I'm having a question on how popular and then get the selected item from a DropDownListFor
, I'm using DDD and Entity Framework architecture.
In the case here my class ServiceProviderViewModel
has to have relationship with other classes. I would like to know how to make this Helper in View of Create
popular.
Following codes:
public class ServiceProviderViewModel
{
[Key]
public int ServiceProviderId { get; set; }
[Required(ErrorMessage = "Por favor, informe o nome do colaborador.")]
[Display(Name = "Nome:")]
public string Name { get; set; }
[Display(Name = "Nome da Mãe:")]
public string MotherName { get; set; }
[Display(Name = "Nome do Pai:")]
public string FatherName { get; set; }
[Display(Name = "E-mail:")]
[EmailAddress(ErrorMessage = "Por favor, informe um formato de e-mail válido.")]
public string Email { get; set; }
[Display(Name = "Nascimento:")]
public DateTime Birth { get; set; }
[ScaffoldColumn(false)]
public DateTime DateRegister { get; set; }
[ScaffoldColumn(false)]
public DateTime DateModified { get; set; }
[Required(ErrorMessage = "Por favor, informe o departamento para o colocaborador.")]
[Display(Name = "Departamento:")]
public int DepartamentId { get; set; }
[Required(ErrorMessage = "Por favor, informe o departamento para o colocaborador.")]
[Display(Name = "Cargo/Função:")]
public int PositionId { get; set; }
public virtual DepartamentViewModel Departaments { get; set; }
public virtual PositionViewModel Positions { get; set; }
public virtual IEnumerable<ServiceProviderAddressViewModel> ServiceProviderAddress { get; set; }
public virtual IEnumerable<ServiceProviderPhoneViewModel> ServiceProviderPhone { get; set; }
public virtual IEnumerable<ServiceProviderInfoViewModel> ServiceProviderInfo { get; set; }
public virtual IEnumerable<InfoBankViewModel> InfoBank { get; set; }
}
Controller :
public class ServiceProviderController : Controller
{
private readonly IServiceProviderAppService _serviceProviderApp;
public ServiceProviderController(IServiceProviderAppService serviceProviderApp)
{
_serviceProviderApp = serviceProviderApp;
}
// GET: ServiceProvider
public ActionResult Index()
{
var serviceProviderViewModel = Mapper.Map<IEnumerable<ServiceProvider>, IEnumerable<ServiceProviderViewModel>>(_serviceProviderApp.GetAll());
return View(serviceProviderViewModel);
}
// GET: ServiceProvider/Create
public ActionResult Create()
{
return View();
}
// POST: ServiceProvider/Create
[HttpPost]
public ActionResult Create(ServiceProviderViewModel serviceProvider)
{
if (ModelState.IsValid)
{
var serviceProviderDomain = Mapper.Map<ServiceProviderViewModel, ServiceProvider>(serviceProvider);
_serviceProviderApp.Add(serviceProviderDomain);
_serviceProviderApp.Save();
return RedirectToAction("Index");
}
return View(serviceProvider);
}
...
For each class that ServiceProvider
relates I have the specific models for CRUD realization. I just do not know how I should work to run this mix of models and controllers .