public ActionResult Crear() { var mpagos = db.MPagoes.OrderBy(x => x.MPagoId).ToList(); MPagoViewModel vm = new MPagoViewModel(); vm.MPagos = mpagos; return(View(vm)); }
public ActionResult Update(MPagoViewModel vm) { var mpagos = db.MPagoes.OrderBy(x => x.MPagoId).ToList(); var mpago = mpagos.FirstOrDefault(x => x.MPagoId == vm.MPagoId); if (mpago == null) { TempData["ErrorMessage"] = "El identificador no fue encontrado"; return(RedirectToAction("Index")); } mpago.MPagoName = vm.MPagoName; db.Entry(mpago).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Update(int id) { var mpagos = db.MPagoes.OrderBy(x => x.MPagoId).ToList(); var mpago = mpagos.FirstOrDefault(x => x.MPagoId == id); if (id == 0 || mpago == null) { TempData["ErrorMessage"] = "El identificador no fue encontrado"; return(RedirectToAction("Index")); } MPagoViewModel vm = new MPagoViewModel(); vm.MPagoId = mpago.MPagoId; vm.MPagoName = mpago.MPagoName; return(View(vm)); }
public ActionResult Crear(MPagoViewModel model) { if (ModelState.IsValid) { if (db.MPagoes.Any(x => x.MPagoName == model.MPagoName)) { TempData["ErrorMessage"] = "El medio de pago ya se encuatra registrado"; return(View(model)); } var mpago = new MPago(); mpago.MPagoName = model.MPagoName; db.MPagoes.Add(mpago); db.SaveChanges(); TempData["SuccessMessage"] = "Medio de pago creado Correctamente"; return(RedirectToAction("Index", "MPago")); } var mpagos = db.MPagoes.OrderBy(x => x.MPagoId).ToList(); model.MPagos = mpagos; return(View("Index", model)); }