private void ValidateModel(InstrumentTypesEditModel model) { if (model.InstrumentType.Id < 0) { ModelState.AddModelError("Id", "Tipo inexistente. :("); } else if (model.InstrumentType.Name == null || model.InstrumentType.Name == string.Empty) { ModelState.AddModelError("Name", "Parece que o campo Nome não foi preenchido. :( Preencha-o e tente novamente."); } }
public ActionResult Edit(int id) { if (id > 0) { InstrumentTypesEditModel model = new InstrumentTypesEditModel(); model.InstrumentType = InstrumentTypesRepository.Get(id); return(View(model)); } else { return(View("Error")); } }
public ActionResult Edit(int id, InstrumentTypesEditModel model) { ValidateModel(model); if (ModelState.IsValid) { try { model.InstrumentType.Id = id; int result = InstrumentTypesRepository.Update(model.InstrumentType); Success("Tipo atualizado."); return(RedirectToAction("Index")); } catch { return(View("Error")); } } else { Warning(BuildErrorMessage(GetErrors())); return(RedirectToAction("Edit")); } }