public ActionResult AddEditTypeExistence(Int32?TypeExistenceId, Int32?FatherId) { var model = new AddEditTypeExistenceViewModel(); model.Fill(CargarDatosContext(), TypeExistenceId, FatherId); return(View(model)); }
public ActionResult AddEditTypeExistence(AddEditTypeExistenceViewModel model) { try { if (!ModelState.IsValid) { model.Fill(CargarDatosContext(), model.TypeExistenceId, model.FatherId); TryUpdateModel(model); PostMessage(MessageType.Error); return(View(model)); } TypeExistence typeExistence = null; if (model.TypeExistenceId.HasValue) { typeExistence = context.TypeExistence.FirstOrDefault(x => x.TypeExistenceId == model.TypeExistenceId); } else { typeExistence = new TypeExistence(); typeExistence.State = ConstantHelpers.ESTADO.ACTIVO; context.TypeExistence.Add(typeExistence); } typeExistence.Description = model.Description; context.SaveChanges(); PostMessage(MessageType.Success); return(RedirectToAction("ListTypeExistence", new { FatherId = model.FatherId })); } catch (Exception ex) { PostMessage(MessageType.Error); model.Fill(CargarDatosContext(), model.TypeExistenceId, model.FatherId); return(View(model)); } }