I am starting a new Web API project and trying to still grasp the concepts of DTO / View Model.I know for a fact that your DTOs should only hold data and any required business rules should be performed on the DTO before finally it gets to the controller to be converted (mapped) to an appropriate view model.
However, in my case the PutUser action expects an entire "UpdateUserViewModel" in the form of Json from the client :
public HttpResponseMessage PutUser(UpdateUserViewModel user)
{
var userDTO = UserManager.Update(user); // Passing the viewmodel as it is to the business manager
// Perform DTO to view model mapping here and return response.
return Request.CreateResponse(HttpStatusCode.OK,UpdateUserViewModel);
}
In my business layer I will now map this view model user to the userDTO and perform any business logic and return a userDTO object to the Action which will then be mapped to the view model and returned as the response , is this the right approach or should my manager only expect a DTO object, basically where should the mapping of ViewModel -> DTO happen -> ViewModel ?
If this is the right approach, what is the best way to map ViewModel entities to DTO and the reverse without using auto mapper?