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)); } }
public ActionResult _DeleteTypeExistence(_DeleteTypeExistenceViewModel model) { try { TypeExistence TypeExistence = null; if (model.TypeExistenceId.HasValue) { TypeExistence = context.TypeExistence.FirstOrDefault(x => x.TypeExistenceId == model.TypeExistenceId); TypeExistence.State = ConstantHelpers.ESTADO.INACTIVO; } context.SaveChanges(); PostMessage(MessageType.Success); } catch (Exception ex) { PostMessage(MessageType.Error); } return(RedirectToAction("ListTypeExistence", new { FatherId = model.FatherId })); }