// Edición de Causas egreso //GET public async Task<ActionResult> EditarCausaEgreso(int? ID) { // bad request if (ID == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } // get entity var _entity = await _context.CAUSASEGRESO.FindAsync(ID); // set model var _model = new CAUSASEGRESOMODEL { ID = _entity.ID, NOMBRE = _entity.NOMBRE, DESCRIPCION = _entity.DESCRIPCION }; // to view return View(_model); }
public async Task<ActionResult> EditarCausaEgreso(CAUSASEGRESOMODEL _model) { if (ModelState.IsValid) { // comprobar el nombre if (_context.CAUSASEGRESO.FirstOrDefault(c => c.NOMBRE == _model.NOMBRE && c.ID != _model.ID) != null) { ModelState.AddModelError("", "Este nombre de Causa ya está asignado a otro registro, por favir elija otro"); return View(_model); } else { try { // get entity var _entity = new CAUSASEGRESO(); _entity = await _context.CAUSASEGRESO.FindAsync(_model.ID); _entity.NOMBRE = _model.NOMBRE; _entity.DESCRIPCION = _model.DESCRIPCION; // actualizar el registro _context.Entry(_entity).State = EntityState.Modified; await _context.SaveChangesAsync(); //redireccionar return RedirectToAction("CausasEgreso", "Configuraciones"); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } } return View(_model); }
// Nueva causa egreso // GET public ActionResult NuevaCausaEgreso() { // get model var _model = new CAUSASEGRESOMODEL(); // toV view return View(_model); }