public ActionResult Create() { var model = new ServicesCreateViewModel(); PrepareViewModel(model); return(View(model)); }
public ActionResult Create(ServicesCreateViewModel model, string redirectUrl) { if (!ModelState.IsValid) { return(View(model)); } var service = model.Map <Services>(); Services.Create(service); return(RedirectToLocal(redirectUrl)); }
public void PrepareViewModel(ServicesCreateViewModel model) { var units = Units.Get().Select(s => new SelectListItem { Text = s.Name, Value = Convert.ToString(s.UnitsId) }).ToList(); var types = Types.Get().Select(s => new SelectListItem { Text = s.Name, Value = Convert.ToString(s.TypeServicesId) }).ToList(); model.Types = types; model.Units = units; }
public ActionResult Edit(ServicesCreateViewModel model, string redirectUrl) { if (!ModelState.IsValid) { return(View(model: model)); } var serv = Services.GetById(model.ServicesId); if (serv != null) { Mapper.Map(model, serv); Services.Update(serv); } return(RedirectToLocal(redirectUrl)); }