// // GET: /IngresoFinanza/Delete/5 public ActionResult Delete(int id = 0) { IngresoFinanzas ingresofinanzas = db.IngresoFinanzas.Find(id); if (ingresofinanzas == null) { return(HttpNotFound()); } return(View(ingresofinanzas)); }
// // GET: /IngresoFinanza/Edit/5 public ActionResult Edit(int id = 0) { IngresoFinanzas ingresofinanzas = db.IngresoFinanzas.Find(id); if (ingresofinanzas == null) { return(HttpNotFound()); } ingresoAnterior = ingresofinanzas; ViewBag.ConceptoIngresoid = new SelectList(db.ConceptoIngreso, "id", "concepto", ingresofinanzas.ConceptoIngresoid); ViewBag.Cuentasid = new SelectList(db.Cuentas.Where(c => c.activo), "id", "nombre", ingresofinanzas.Cuentasid); var personas = from p in db.Persona where p.activo select new { p.id, nombre = p.nombre + " " + p.apellido1 + " " + (p.apellido2 ?? "") }; ViewBag.Personaid = new SelectList(personas, "id", "nombre", ingresofinanzas.Personaid); return(View(ingresofinanzas)); }
public ActionResult DeleteConfirmed(int id) { IngresoFinanzas ingresofinanzas = db.IngresoFinanzas.Find(id); var cuenta = ingresofinanzas.Cuentas; if (cuenta.importe - ingresofinanzas.importe >= 0) { cuenta.importe -= ingresofinanzas.importe; } else { throw new Exception("La cuanta de la que desea extraer no tiene ese importe, no puede borrar este ingreso mientras la cuenta no tenga el importe suficiente"); } db.Entry(cuenta).State = EntityState.Modified; db.IngresoFinanzas.Remove(ingresofinanzas); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(IngresoFinanzas ingresofinanzas) { if (ModelState.IsValid) { var user = Session["usuarioActual"] as Usuario; ingresofinanzas.Usuarioid = user.id; var cuenta = db.Cuentas.Find(ingresofinanzas.Cuentasid); cuenta.importe += ingresofinanzas.importe; db.Entry(cuenta).State = EntityState.Modified; db.IngresoFinanzas.Add(ingresofinanzas); db.SaveChanges(); return(RedirectToAction("Create")); } ViewBag.ConceptoIngresoid = new SelectList(db.ConceptoIngreso, "id", "concepto", ingresofinanzas.ConceptoIngresoid); ViewBag.Cuentasid = new SelectList(db.Cuentas.Where(c => c.activo), "id", "nombre", ingresofinanzas.Cuentasid); var personas = from p in db.Persona where p.activo select new { p.id, nombre = p.nombre + " " + p.apellido1 + " " + (p.apellido2 ?? "") }; ViewBag.Personaid = new SelectList(personas, "id", "nombre", ingresofinanzas.Personaid); return(View(ingresofinanzas)); }
public ActionResult Edit(IngresoFinanzas ingresofinanzas) { if (ModelState.IsValid) { var user = Session["usuarioActual"] as Usuario; ingresofinanzas.Usuarioid = user.id; var cuentaAnterior = db.Cuentas.Find(ingresoAnterior.Cuentasid); if (cuentaAnterior.importe - ingresofinanzas.importe >= 0) { cuentaAnterior.importe -= ingresofinanzas.importe; } else { throw new Exception("La cuanta de la que desea extraer no tiene ese importe, no puede borrar este ingreso mientras la cuenta no tenga el importe suficiente"); } var cuenta = db.Cuentas.Find(ingresofinanzas.Cuentasid); cuenta.importe += ingresofinanzas.importe; db.Entry(cuenta).State = EntityState.Modified; db.Entry(cuentaAnterior).State = EntityState.Modified; db.Entry(ingresofinanzas).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ConceptoIngresoid = new SelectList(db.ConceptoIngreso, "id", "concepto", ingresofinanzas.ConceptoIngresoid); ViewBag.Cuentasid = new SelectList(db.Cuentas, "id", "nombre", ingresofinanzas.Cuentasid); var personas = from p in db.Persona where p.activo select new { p.id, nombre = p.nombre + " " + p.apellido1 + " " + (p.apellido2 ?? "") }; ViewBag.Personaid = new SelectList(personas, "id", "nombre", ingresofinanzas.Personaid); return(View(ingresofinanzas)); }