Design patterns advice - separating ViewModels from domain models
Tag : chash , By : Christopher
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I also don't see much of a reason to keep the DAL separate from the MVC layer. In case you're interested, here is the layout that I've used for multiple project and I find it is very usable and flexible. DataObjects Basic objects with only properties. Also includes enumerations which the DataObjects use.
|
Easily create MVC ViewModels from Entity models?
Tag : chash , By : Joe Sweeney
Date : March 29 2020, 07:55 AM
This might help you You could consider using T4 templating, see this MSDN magazine article to get started. You could create a template that uses reflection to get the properties of your Model, and generate ViewModel from this.
|
AutoMapper: two-way, deep mapping, between domain models and viewmodels
Date : March 29 2020, 07:55 AM
it should still fix some issue In the end I found AutoMapper was unsuited to my scenario. Instead I built a custom utility to provide bidirectional mapping & deep property mapping allowing configuration as follows. Given the scope of our project I believe this is justified. BiMapper.CreateProfile<Client, ClientNotificationsViewModel>()
.Map(x => x.NotificationSettings.ReceiveActivityEmail, x => x.ReceiveActivityEmail)
.Map(x => x.NotificationSettings.ReceiveActivitySms, x => x.ReceiveActivitySms)
.Map(x => x.ContactDetails.Email, x => x.Email)
.Map(x => x.ContactDetails.MobileNumber, x => x.MobileNumber);
BiMapper.PerformMap(client, viewModel);
BiMapper.PerformMap(viewModel, client);
|
MVC map Viewmodels to domain models
Tag : chash , By : Thomas Gueze
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I am struggling to figure out how to map my viewModels to domain models for to the Index, Edit, Details and Delete Action Result in the controller. , To map your domain model to the view model in the edit method Parent p = db.Parents.Find(id);
ParentsEditVM model = new ParentsEditVM()
{
ParentID = p.ParentID,
FirstName =p.FirstName,
LastName = p.LastName,
Children = p.Childs.Select(c => new ChildVM()
{
ChildID = c.ChildID,
Name = c.Name,
... etc
}).ToList(),
};
....
return View(model);
|
In Asp.net MVC, is it advisable for viewmodels to derive from domain models?
Tag : chash , By : taviso
Date : March 29 2020, 07:55 AM
|