0

Am writing a service using asp.netwebapi visual studio 13 i am not getting how to integrate or communicate models with business layer. because if i use 3 tier architecture context will act as models no difference in that so please any body suggest me the communication between the models and business layer

1 Answer 1

1

You need to create Models in your WebAPI to separate your BLL from WebAPI. For example, if you have a Person class in your BLL you can have a PersonModel in your WebAPI. It would work like below roughly.

[HttpGet]
Public HttpResponseMessage Get(id)
{
    // Validation for id
    var person = _dbContext.GetPersonById(id);

    // Now populate the Model
    var personModel=new PersonModel();

     // You can use automapper to replace the following part
    personModel.PersonId=person.PersonId;
    personModel.Firstname= person.Firstname; 
    // ....
}


[HttpPost]
Public HttpResponseMessage Post(PersonModel personModel)
{
    // Validation here
    // ...

    var person = new Person();

    // You can use automapper to replace the following part
    person.PersonId= personModel.PersonId;
    person.Firstname=personModel.Firstname;

    _dbContext.Save(person);
}

You can use AutoMapper to automatically populate the models without having to write Model <-> BLL class code.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for suggestion i will get back to u again about this issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.