public ActionResult Create(TbGastos a) { try { var context = HttpContext.RequestServices.GetService(typeof(riviera_businessContext)) as riviera_businessContext; if (a.IdTipoGasto == 1 || a.IdTipoGasto == 2) { a.IdCarro = 1; } context.TbGastos.Add(a); context.SaveChanges(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Edit(int id, TbGastos a) { try { var context = HttpContext.RequestServices.GetService(typeof(riviera_businessContext)) as riviera_businessContext; var objectEdit = context.TbGastos.FirstOrDefault(gas => gas.IdGastos == a.IdGastos); if (objectEdit != null) { objectEdit.Descripcion = a.Descripcion; objectEdit.Fecha = a.Fecha; objectEdit.IdCarro = a.IdCarro; objectEdit.IdEstado = a.IdEstado; objectEdit.IdTipoGasto = a.IdTipoGasto; objectEdit.Monto = a.Monto; context.TbGastos.Update(objectEdit); context.SaveChanges(); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }