예제 #1
0
        //
        // GET: /IngresoFinanza/Delete/5

        public ActionResult Delete(int id = 0)
        {
            IngresoFinanzas ingresofinanzas = db.IngresoFinanzas.Find(id);

            if (ingresofinanzas == null)
            {
                return(HttpNotFound());
            }
            return(View(ingresofinanzas));
        }
예제 #2
0
        //
        // 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));
        }
예제 #3
0
        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"));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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));
        }