Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

mvc, class library

I have the codes below
1. RetrieveData is working fine., but now I want to assign class library value in a loop.
Basically, I have wcf call to get the list of name which is exactly same as class library property name - see newretrievedata
Is it possible to do that?

On another side of class library in c#, i already have all of the property/object in class library.


     
  public JsonResult RetrieveData(string ID)
        {
            Domain.Lead l = new Domain.Lead();
            l.firstname = "John";
            l.lastname = "Smith";
            return Json(l, JsonRequestBehavior.AllowGet);
        }

 
        public JsonResult newRetrieveData(string ID)
        {
            Domain.Lead l = new Domain.Lead();


            foreach (KeyValuePair<string, string> i in Helper.DynamicsCRM.GetAllLeadInfoByMetaData3("a51ec467-7255-e811-81153863bb3c4538"))
            {               
                //Response.Write(i.Key + " >> " + i.Value + "<br>"); Key has firstname, and lastname, etc.
            	l.i.Key = i.Value;
            }
            return Json(l, JsonRequestBehavior.AllowGet);
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITsolutionWizard

ASKER

So u can help or not?
Assign value meaning like below

Person.firstname = "john"

Normally, I assign above and now I hope to get the property name and value by reading wcf that I created
Sorry for nitpicking, but WCF must use XML, not JSON. And by rephrase I mean to describe what you are doing, where it is failing. It also means to explain you context. You haven't posted enough information nor consistent information so far.

E.g. what is your solution/project architecture? What stack(s) do you use?
If I look at your sample fragments: Do you develop a REST web service? Do you use ASP.NET Web API?

Your sample seem to define two endpoints: RetrieveData() and newRetrieveData(). The first returns a static object, while the second returns some arbitrary data.

Problem 1: Big problem, so sad. The naming is bad. RetrieveData and newRetrieveData is only a generic description. API names should be specific, concise and exact. RetrieveData should be named at least RetrieveLead. newRetrieveData (here I need to guess a little bit) should be named RetrieveLeadInformation.

Problem 2: Both methods pretend to be dynamic. But they return either a static value or some arbitrary data. Thus this API is currently lying.

Problem 3: Is a little bit more sophisticated, cause it's about architecture. Layers and abstraction. The web service is normally a service façade of the business logic. Which sits on top of the data access layer. In the data access layer we normally find methods like  Helper.DynamicsCRM.GetAllLeadInfoByMetaData3. But this is never a "Helper". Nor should it return untyped data. KeyValuePair<string, string> is a generic and does not transmit sematic information. The method Helper.DynamicsCRM.GetAllLeadInfoByMetaData3 is normally part of the repository pattern. Furthermore how is your data transfer object (DTO, POCO) Domain.Lead defined?
Based on the given facts the LeadRepository should have the methods RetrieveLead(predicates) and RetrieveLeads(predicates). And depending on the use-case the symmetric Create, Update and Delete methods also to complete the CRUD paradigm here. The Lead class should have a property Metadata.

p.s. Consider using unit tests with a test driven approach to avoid that ("hope").
Please don't worry my wcf. If you can help, focus on my code only. Thank you for your helps and time
Okay, the hard way:

If you can help, focus on my code only
You've posted only fragments.. these fragments don't contain any error. But bad coding style and bad architectural approaches.

And the only sentence I understood in your OP:
Is it possible to do that?
Yes, cause it is a rhetorical question. Is it advisable? No. So my post above..

And for the rest of your post(s): They are hard to understand, you don't use common terms. Instead you created your own. You posted only code fragments instead of a concise and complete example. In short: you don't provided the needed information nor context. I've asked twice to do so. HHCIB?