public ActionResult AddEditSubFamily(Int32?SubFamilyId) { var model = new AddEditSubFamilyViewModel(); model.Fill(CargarDatosContext(), SubFamilyId); return(View(model)); }
public ActionResult AddEditSubFamily(AddEditSubFamilyViewModel model) { try { if (!ModelState.IsValid) { model.Fill(CargarDatosContext(), model.SubFamilyId); TryUpdateModel(model); PostMessage(MessageType.Error); return(View(model)); } SubFamily subFamily = null; if (model.SubFamilyId.HasValue) { subFamily = context.SubFamily.FirstOrDefault(x => x.SubFamilyId == model.SubFamilyId); } else { subFamily = new SubFamily(); subFamily.State = ConstantHelpers.ESTADO.ACTIVO; context.SubFamily.Add(subFamily); } subFamily.Description = model.Description; subFamily.FamilyId = model.FamilyId; context.SaveChanges(); PostMessage(MessageType.Success); return(RedirectToAction("ListSubFamily")); } catch (Exception ex) { PostMessage(MessageType.Error); model.Fill(CargarDatosContext(), model.SubFamilyId); return(View(model)); } }