I have a standard C# MVC project which has a domain layer using EF and repository pattern. Say I have a model like:
public class MainModel
{
public int MainModelID {get; set;}
//Many other properties
public List<Organization> CompetingOrganizations {get;set;}
}
On submission I need to populate the list of CompetingOrganizations based on the current value of other properties in the MainModel and the properties in the of all the Organizations in my database.
Right now my controller just calls the MainModelRepository.Update(...) after the View Model is validated and mapped onto the Domain Model without populating this list. I could populate competing organizations by:
- making a call to the (for example)
List<Organization> CompetingOrgList = OrganizationRepository.GetCompetingOrgs(model)from the controller, add them to theMainModeland persist in the same way, or by; - creating a
MainModelRepository.UpdateWithCompetingOrgs(model)call that directly accesses theOrganizationsDbSetfrom the context in theMainModelRepositoryto figure out which organizations should be added by default.
Both of these options feels wrong, but without a service layer I am not sure how else I should handle it, and which method is cleaner?