Currently I am converting ViewModels into model objects and also the other way round. I do this in the controller and sometimes it can be quite a big object with many properties. I was wondering if this is bad practice. Should I create adapter classes to convert them and then just use the adapter in the controller.
Below is an example of how I convert the ViewModel object to a Model object in the controller:
public async Task<IActionResult> Register(RegisterViewModel registerModel)
{
if (ModelState.IsValid)
{
ApplicationUser user = new ApplicationUser
{
UserName = registerModel.Email,
Email = registerModel.Email,
FirstName = registerModel.FirstName,
LastName = registerModel.LastName,
AddressLine1 = registerModel.AddressLine1,
AddressLine2 = registerModel.AddressLine2,
City = registerModel.City,
PostCode = registerModel.PostCode,
PhoneNumber = registerModel.PhoneNumber,
NotificationPreference = Enum.GetName(typeof(NotificationPreference), NotificationPreference.None)
};
await userManager.CreateAsync(user, registerModel.Password);
}
return View(registerModel);
}
So should I create the ApplicationUser here or should I create it in an adapter class.