public ActionResult Agregar(AC_Gastos g) { try { if (g != null) { AC_Usuario userLog = db.AC_Usuario.SingleOrDefault(x => x.Correo == User.Identity.Name); gasto.ID_Articulo = g.ID_Articulo; gasto.Costo = g.Costo; gasto.ID_Usuario = userLog.U_ID; gasto.Fecha = DateTime.Now; db.AC_Gastos.Add(gasto); db.SaveChanges(); return(RedirectToAction("Index", "Gastos")); } else { ViewBag.mensage = "Ingrese los datos requeridos"; } } catch (Exception ex) { } return(View()); }
public ActionResult Modificar(int id, AC_Gastos g) { gasto = db.AC_Gastos.Find(id); if (gasto != null) { try { gasto.Costo = g.Costo; db.SaveChanges(); return(RedirectToAction("Index", "Gastos")); } catch (Exception ex) { ViewBag.mensage = "Este Gasto no existe"; return(View("Error")); } } return(View()); }
public ActionResult Eliminar(int id, QueryGastos gastos) { try { gasto = db.AC_Gastos.Find(id); if (gasto != null) { db.AC_Gastos.Remove(gasto); db.SaveChanges(); return(RedirectToAction("Index", "Gastos")); } else { ViewBag.mensage = "No existe ese gasto, Ingrese un valor valido"; return(View("Error")); } } catch (Exception ex) { ViewBag.mensage = "No se pudo eliminar"; return(View("Error")); } return(View()); }