public ActionResult Imprimir2()
        {
            var sql   = "select max(IDPRESTAMO) from dbo.PRESTAMO";
            var total = db.Database.SqlQuery <int>(sql).First();

            ViewBag.total = total;


            PrestamoViewModel PrestamoVm = new PrestamoViewModel();

            PrestamoVm.prestamo1 = db.PRESTAMOes.Find(total);
            var IDMATBIBLIO = PrestamoVm.prestamo1.IDMATBIBLIO;

            PrestamoVm.Material1 = db.MATERIALBIBLIOGRAFICOes.Find(IDMATBIBLIO);
            var IDUSUARIO = User.Identity.GetUserId();

            PrestamoVm.User = db.AspNetUsers.Find(IDUSUARIO);

            //var IDPERSONA = PrestamoVm.User.IdPersona;
            //PrestamoVm.Persona1 = db.PERSONAs.Find(IDPERSONA);



            return(View(PrestamoVm));
        }
Ejemplo n.º 2
0
        // GET: Prestamos/Edit/5
        public ActionResult Edit(int?id)
        {
            //PrestamoViewModel prestamoViewModel = new PrestamoViewModel();
            PrestamosService prestamosServ = new PrestamosService();

            Prestamo pModel  = _db.Prestamos.Find(id);
            Cliente  cliente = _db.Clientes.Find(pModel.ClienteId);
            var      status  = (pModel.Estatus == true) ? PrestamoViewModel.estatus.Activo : PrestamoViewModel.estatus.Inactivo;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            PrestamoViewModel prestamoViewModel = new PrestamoViewModel
            {
                Id       = pModel.Id,
                Cliente  = cliente.Nombre,
                Clientes = prestamosServ.ObtenerListaClientes(),
                Monto    = pModel.Monto,
                Fecha    = pModel.Fecha,
                Status   = status
            };

            //prestamoViewModel = prestamosServ.ObtenerPrestamo(id);

            if (prestamoViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(prestamoViewModel));
        }
Ejemplo n.º 3
0
        // GET: Prestamo
        public ActionResult Listar()
        {
            PrestamoViewModel pvm = new PrestamoViewModel();

            pvm.lista = PrestamoService.findAll();
            return(View(pvm));
        }
        public ActionResult Index(PrestamoViewModel PrestamoVm)
        {
            PRESTAMO prestamo = new PRESTAMO();

            prestamo.ID              = PrestamoVm.Usuarioid;
            prestamo.IDMATBIBLIO     = PrestamoVm.Material1.IDMATBIBLIO;
            prestamo.FECHADEPRESTAMO = PrestamoVm.prestamo1.FECHADEPRESTAMO;
            prestamo.FECHADEENTREGA  = PrestamoVm.prestamo1.FECHADEENTREGA;
            db.PRESTAMOes.Add(prestamo);
            db.SaveChanges();


            MATERIALBIBLIOGRAFICO material = new MATERIALBIBLIOGRAFICO();

            int nuevas = int.Parse(PrestamoVm.Material1.UNIDADES);

            nuevas = nuevas - 1;

            material.UNIDADES = nuevas.ToString();


            int noOfRowUpdated = db.Database.ExecuteSqlCommand("Update MATERIALBIBLIOGRAFICO set UNIDADES = {0} where IDMATBIBLIO = {1}", material.UNIDADES, PrestamoVm.Material1.IDMATBIBLIO);

            //intento de registrar
            REGISTRO registro = new REGISTRO();

            registro.IDMATBIBLIO = prestamo.IDMATBIBLIO;
            registro.IDPRESTAMO  = prestamo.IDPRESTAMO; //posible error
            registro.Id          = PrestamoVm.Usuarioid;
            db.REGISTROes.Add(registro);
            db.SaveChanges();

            return(RedirectToAction("PrintViewToPdf2", new RouteValueDictionary(new { Controller = "Prestamo", Action = "PrintViewToPdf2" })));
        }
Ejemplo n.º 5
0
        public ActionResult PrestamoPorLibro(String titulo)
        {
            PrestamoViewModel pvm = new PrestamoViewModel();

            pvm.lista = PrestamoService.findByTitulo(titulo);
            return(View(pvm));
        }
        // GET: Prestamo
        public ActionResult Index(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PrestamoViewModel PrestamoVm = new PrestamoViewModel();

            PrestamoVm.Material1 = db.MATERIALBIBLIOGRAFICOes.Find(id);

            if (PrestamoVm.Material1 == null)
            {
                return(HttpNotFound());
            }

            /* var estaautenticado = User.Identity.IsAuthenticated;
             *
             * if(estaautenticado)
             * {
             *   var NombreUsuario = User.Identity.Name;
             *   PrestamoVm.Nombre = NombreUsuario;
             *   var Usuarioid = User.Identity.GetUserId();
             *   PrestamoVm.Usuarioid = Usuarioid;
             * }*/

            PrestamoVm.MatId     = id;
            PrestamoVm.Usuarioid = User.Identity.GetUserId();


            return(View(PrestamoVm));
        }
        public ActionResult Devolver(decimal id)

        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PrestamoViewModel PrestamoVm = new PrestamoViewModel();

            PrestamoVm.Material1 = db.MATERIALBIBLIOGRAFICOes.Find(id);



            var sql   = "select max(IDPRESTAMO) from dbo.PRESTAMO where IDMATBIBLIO =" + id.ToString();
            var total = db.Database.SqlQuery <int>(sql).First();

            ViewBag.total = total;



            PrestamoVm.prestamo1 = db.PRESTAMOes.Find(total);


            var IDUSUARIO = PrestamoVm.prestamo1.ID;

            PrestamoVm.User = db.AspNetUsers.Find(IDUSUARIO);

            var IDPERSONA = PrestamoVm.User.IdPersona;

            PrestamoVm.Persona1 = db.PERSONAs.Find(IDPERSONA);

            return(View(PrestamoVm));
        }
Ejemplo n.º 8
0
        public PrestamoViewModel ObtenerPrestamo(int?id)
        {
            var pModel = _db.Prestamos.Find(id);
            //La expresion luego de la variable estatus es un if de forma conta.
            // si la condicion dada se cumple, la variable tendra el valor de lo que aparece luego del signo
            //de interrogacion, si la condicion no se cumple, el valor sera el que aparece luego de los dos puntos.
            var estatus = (pModel.Estatus == true) ? PrestamoViewModel.estatus.Activo : PrestamoViewModel.estatus.Inactivo;

            //Se buscan todos los recibos pertenecientes a un prestamo
            // para mostrarlos en los detalles del prestamo.
            var recibos = _db.Recibos
                          .Where(r => r.PrestamoId == id)
                          .ToList();

            PrestamoViewModel prestamoViewModel = new PrestamoViewModel()
            {
                Id      = pModel.Id,
                Cliente = (_db.Clientes.Find(pModel.ClienteId)).Nombre,
                Monto   = pModel.Monto,
                Fecha   = pModel.Fecha,
                Status  = estatus,
                Recibos = recibos
            };

            return(prestamoViewModel);
        }
Ejemplo n.º 9
0
        public ActionResult PrestamoPorDNI(int numeroDocumento)
        {
            PrestamoViewModel pvm = new PrestamoViewModel();

            pvm.lista = PrestamoService.findByNumeroDocumento(numeroDocumento);
            return(View(pvm));
        }
Ejemplo n.º 10
0
        // GET: Prestamos/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Prestamo pModel = _db.Prestamos.Find(id);

            if (pModel == null)
            {
                return(HttpNotFound());
            }
            else
            {
                var estatus = (pModel.Estatus == true) ? PrestamoViewModel.estatus.Activo : PrestamoViewModel.estatus.Inactivo;

                PrestamoViewModel prestamoViewModel = new PrestamoViewModel
                {
                    Id      = pModel.Id,
                    Cliente = (_db.Clientes.Find(pModel.ClienteId)).Nombre,
                    Monto   = pModel.Monto,
                    Fecha   = pModel.Fecha,
                    Status  = estatus
                };

                return(View(prestamoViewModel));
            }
        }
Ejemplo n.º 11
0
        public IActionResult Create(PrestamoViewModel model)
        {
            if (ModelState.IsValid)
            {
            }

            return(View(model));
        }
Ejemplo n.º 12
0
 public ActionResult NuevoPrestamo(PrestamoViewModel pvm)
 {
     if (ModelState.IsValid)
     {
         PrestamoService.add(pvm);
         return(RedirectToAction("Listar"));
     }
     return(View(PrestamoService.getFormData()));
 }
Ejemplo n.º 13
0
        public IActionResult Create(PrestamoViewModel model)
        {
            if(ModelState.IsValid)
            {

            }

            return View(model);
        }
Ejemplo n.º 14
0
        public static Prestamo mapper(PrestamoViewModel pvm)
        {
            Prestamo p = null;

            if (pvm != null)
            {
                p = new Prestamo(pvm.PrestamoId, pvm.devuelto, pvm.fechaPrestamo, pvm.fechaDevolucionTope, pvm.fechaDevolucionReal, pvm.UsuarioId, pvm.LibroId);
            }
            return(p);
        }
Ejemplo n.º 15
0
 public static void add(PrestamoViewModel pvm)
 {
     using (var ctx = new BibliotecaContext())
     {
         Prestamo p = mapper(pvm);
         p.fechaDevolucionTope = p.fechaPrestamo.AddDays(Prestamo.DIAS_PRESTAMO);
         p.fechaDevolucionReal = DateTime.MaxValue;
         ctx.Entry(p).State    = EntityState.Added;
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 16
0
        public ActionResult Create([Bind(Include = "Id,Cliente,Monto,Fecha,Status")] PrestamoViewModel prestamoViewModel)
        {
            var Cliente = _db.Clientes.Where(c => c.Nombre == prestamoViewModel.Cliente).First();

            var status = (prestamoViewModel.Status == PrestamoViewModel.estatus.Activo) ? true : false;

            PrestamosService prestamosServ = new PrestamosService();

            var pModel = new Prestamo
            {
                ClienteId = Cliente.Id,
                Monto     = prestamoViewModel.Monto,
                Fecha     = prestamoViewModel.Fecha,
                Estatus   = status
            };

            if (ModelState.IsValid)
            {
                //Se guarda el prestamo para que genere un id de prestamo
                _db.Prestamos.Add(pModel);
                _db.SaveChanges();

                if (!prestamosServ.EstaPendiente(pModel))
                {
                    //Se busca el prestamo recien hecho para utilizar su id para crear los recibos de ese prestamo
                    prestamoViewModel.Id =
                        (_db.Prestamos
                         .Where(p => p.ClienteId == Cliente.Id && p.Monto == prestamoViewModel.Monto && p.Fecha == prestamoViewModel.Fecha).Single()
                        ).Id;

                    List <Recibo> recibos = prestamosServ.GenerarRecibos(prestamoViewModel);

                    // Si no se pueden generar los recibos (devuleve null),
                    //se elimina el prestamo de la db para poder intentarlo de nuevo
                    if (recibos == null)
                    {
                        _db.Prestamos.Remove(pModel);
                        _db.SaveChanges();
                        return(HttpNotFound());
                    }
                    //Si el resulgado de GenerarRecibos no es null, se guardan los recibos en la db
                    foreach (var recibo in recibos)
                    {
                        _db.Recibos.Add(recibo);
                        _db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View(prestamoViewModel));
        }
Ejemplo n.º 17
0
        public ActionResult Modificar(int prestamoId)
        {
            PrestamoViewModel pvm    = PrestamoService.getFormData();
            PrestamoViewModel pvmMod = PrestamoService.findById(prestamoId);

            pvm.LibroId             = pvmMod.LibroId;
            pvm.UsuarioId           = pvmMod.UsuarioId;
            pvm.fechaPrestamoString = pvmMod.fechaPrestamoString;
            pvm.fechaDevolucionReal = pvmMod.fechaDevolucionReal;
            pvm.fechaDevolucionTope = pvmMod.fechaDevolucionTope;
            return(View(pvm));
        }
Ejemplo n.º 18
0
        // GET: Prestamos/Create
        public ActionResult Create()
        {
            PrestamoViewModel model         = new PrestamoViewModel();
            PrestamosService  prestamosServ = new PrestamosService();

            #region Porpular DropDownList con nombres de clientes

            model.Clientes = prestamosServ.ObtenerListaClientes();

            #endregion

            return(View(model));
        }
Ejemplo n.º 19
0
        public static PrestamoViewModel mapper(Prestamo p)
        {
            PrestamoViewModel pvm = null;

            if (p != null)
            {
                pvm = new PrestamoViewModel(p.PrestamoId, p.devuelto, p.fechaPrestamo, p.fechaDevolucionTope, p.fechaDevolucionReal, p.usuario_UsuarioId, p.libro_LibroID);
                pvm.fechaPrestamoString       = p.fechaPrestamo.ToString("dd/MM/yyyy");
                pvm.fechaDevolucionTopeString = p.fechaDevolucionTope.ToString("dd/MM/yyyy");
                pvm.fechaDevolucionRealString = p.fechaDevolucionReal.ToString("dd/MM/yyyy");
            }
            return(pvm);
        }
        public ActionResult Devolver(PrestamoViewModel PrestamoVm)
        {
            var idmaterial = PrestamoVm.Material1.IDMATBIBLIO;

            int nuevas = int.Parse(PrestamoVm.Material1.UNIDADES);

            nuevas = nuevas + 1;
            var nuevasString = nuevas.ToString();


            int noOfRowUpdated = db.Database.ExecuteSqlCommand("Update MATERIALBIBLIOGRAFICO set UNIDADES = {0} where IDMATBIBLIO = {1}", nuevasString, idmaterial);

            return(RedirectToAction("Index2", new RouteValueDictionary(new { Controller = "MATERIALBIBLIOGRAFICOes", Action = "Index2" })));
        }
Ejemplo n.º 21
0
 public static void update(PrestamoViewModel pvm)
 {
     using (var ctx = new BibliotecaContext())
     {
         Prestamo p = ctx.Prestamos.SingleOrDefault(b => b.PrestamoId == pvm.PrestamoId);
         if (p != null)
         {
             p.fechaDevolucionTope = pvm.fechaDevolucionTope;
             p.fechaPrestamo       = pvm.fechaPrestamo;
             p.usuario_UsuarioId   = pvm.UsuarioId;
             p.libro_LibroID       = pvm.LibroId;
             ctx.SaveChanges();
         }
     }
 }
Ejemplo n.º 22
0
        public static PrestamoViewModel getFormData()
        {
            List <LibroViewModel> lvms = new List <LibroViewModel>();
            PrestamoViewModel     pvm  = new PrestamoViewModel();

            pvm.fechaPrestamo = DateTime.Now;
            pvm.usuarios      = UsuarioService.findAll();
            foreach (var lvm in LibroService.findAll())
            {
                if (validarEjemplaresDisponibles(lvm))
                {
                    lvms.Add(lvm);
                }
            }
            pvm.libros = lvms;
            return(pvm);
        }
Ejemplo n.º 23
0
        public static List <PrestamoViewModel> mapper(List <Prestamo> ps)
        {
            List <PrestamoViewModel> pvms = new List <PrestamoViewModel>();
            PrestamoViewModel        pvm;

            foreach (var p in ps)
            {
                if (p != null)
                {
                    pvm = new PrestamoViewModel(p.PrestamoId, p.devuelto, p.fechaPrestamo, p.fechaDevolucionTope, p.fechaDevolucionReal, p.usuario_UsuarioId, p.libro_LibroID);
                    pvm.fechaPrestamoString       = p.fechaPrestamo.ToString("dd/MM/yyyy");
                    pvm.fechaDevolucionTopeString = p.fechaDevolucionTope.ToString("dd/MM/yyyy");
                    pvm.fechaDevolucionRealString = p.fechaDevolucionReal.ToString("dd/MM/yyyy");
                    pvms.Add(pvm);
                }
            }
            return(pvms);
        }
Ejemplo n.º 24
0
        // GET: Prestamos/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            PrestamoViewModel prestamoViewModel = new PrestamoViewModel();
            PrestamosService  prestamosServ     = new PrestamosService();

            prestamoViewModel = prestamosServ.ObtenerPrestamo(id);

            if (prestamoViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(prestamoViewModel));
        }
Ejemplo n.º 25
0
        public ActionResult Edit([Bind(Include = "Id,Cliente,Monto,Fecha,Status")] PrestamoViewModel prestamoViewModel)
        {
            Prestamo pModel = new Prestamo();

            if (ModelState.IsValid)
            {
                var cliente = _db.Clientes.Where(c => c.Nombre == prestamoViewModel.Cliente).First();
                var status  = (prestamoViewModel.Status == PrestamoViewModel.estatus.Activo) ? true : false;

                pModel = new Prestamo
                {
                    Id        = prestamoViewModel.Id,
                    ClienteId = cliente.Id,
                    Monto     = prestamoViewModel.Monto,
                    Fecha     = prestamoViewModel.Fecha,
                    Estatus   = status
                };

                _db.Entry(pModel).State = EntityState.Modified;
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(prestamoViewModel));
        }
Ejemplo n.º 26
0
        //Este metodo será invocado por el controlador de prestamos,
        // al hacerlo, generará los recibos correspondientes a dicho prestamo.
        public List <Recibo> GenerarRecibos(PrestamoViewModel pModel)
        {
            if (pModel == null)
            {
                return(null);
            }

            else
            {
                List <Recibo> receipts = new List <Recibo>();

                int monto = (pModel.Monto / 10);

                DateTime fecha = pModel.Fecha;

                int idPrestamo = pModel.Id;

                bool status = (pModel.Status == PrestamoViewModel.estatus.Activo) ? true : false;

                for (int i = 1; i <= 13; i++)
                {
                    fecha = fecha.AddDays(7);

                    receipts.Add(new Recibo
                    {
                        Cuota      = i,
                        MontoPago  = monto,
                        FechaPago  = fecha,
                        Estatus    = status,
                        PrestamoId = idPrestamo
                    });
                }

                return(receipts);
            }
        }
Ejemplo n.º 27
0
 public ActionResult Modificar(PrestamoViewModel pvm)
 {
     pvm.fechaDevolucionTope = pvm.fechaPrestamo.AddDays(Prestamo.DIAS_PRESTAMO);
     PrestamoService.update(pvm);
     return(volverAlListado());
 }
Ejemplo n.º 28
0
        public ActionResult NuevoPrestamo()
        {
            PrestamoViewModel pvm = PrestamoService.getFormData();

            return(View(pvm));
        }