public ActionResult Edit(Int32 id)
        {
            AlquileresMVC.Models.Cliente         cliente = db.ClienteSet.First(c => c.ID == id); Int32 _iIDCliente = cliente.ID;
            List <AlquileresMVC.Models.Alquiler> listAlquiler = db.AlquilerSet.Where(a => a.IDCliente == _iIDCliente && a.Estatus == 1).ToList();
            Double _dMontoEstimado = 0; _dMontoEstimado = (from e in listAlquiler select e.PrecioEstimado).Sum().Value;

            AlquileresMVC.Models.Cantidad_Alquileres_Por_Pagar_VW clienteAlq = dbVW.Cantidad_Alquileres_Por_Pagar_VW_Set.First(c => c.IDCliente == _iIDCliente);
            AlquileresMVC.Models.Descuento descuento = db.DescuentoSet.First(d => d.Codigo == "DEC1");
            Double       _dPorcentajeDescuento       = 0; _dPorcentajeDescuento = descuento.PorcentajeDescuento ?? 0;
            Double       _dDescuento          = _dPorcentajeDescuento * _dMontoEstimado;
            Double       _dMontoTotal         = _dMontoEstimado - _dDescuento;
            PagoCabecera pagoCabeceraToUpdate = db.PagoCabeceraSet.ToList().LastOrDefault();
            Int32        _iID    = pagoCabeceraToUpdate.ID; _iID = _iID + 1;
            DateTime     _dFecha = DateTime.Now;

            if (clienteAlq.NumAlquiler >= 3 && clienteAlq.NumAlquiler <= 5)
            {
                pagoCabeceraToUpdate.MontoExento = _dMontoEstimado;
                pagoCabeceraToUpdate.Descuento   = _dDescuento;
                pagoCabeceraToUpdate.MontoTotal  = _dMontoTotal;
            }
            else
            {
                pagoCabeceraToUpdate.MontoExento = _dMontoEstimado;
                pagoCabeceraToUpdate.Descuento   = 0;
                pagoCabeceraToUpdate.MontoTotal  = _dMontoEstimado;
            }
            pagoCabeceraToUpdate.IDCliente = _iIDCliente;
            pagoCabeceraToUpdate.Fecha     = _dFecha;
            pagoCabeceraToUpdate.ClienteLoad();
            return(View(pagoCabeceraToUpdate));
        }
Esempio n. 2
0
        public ActionResult Delete(Int32 id, FormCollection form)
        {
            AlquileresMVC.Models.Cliente clienteToDelete = db.ClienteSet.First(c => c.ID == id);

            //valido cliente tiene alquiler
            if (db.AlquilerSet.FirstOrDefault(a => a.IDCliente == id) != null)
            {
                ModelState.AddModelError("ID", String.Format("Esta intentando Borrar un cliente que tiene alquiler"));
            }
            else
            {
                try
                {
                    // Delete
                    db.DeleteObject(clienteToDelete);
                    db.SaveChanges();
                    // Retorno a la vista del listar
                    return(RedirectToAction("List"));
                }
                catch (Exception ex)
                {
                    HandleException excepcion = new HandleException();
                    String          msjLog    = "Error en " + ObtenerMetodoEnEjecucion(false).ToString() + ".\n" + excepcion.RegistrarExcepcion(ex, ObtenerMetodoEnEjecucion(false).ToString());
                    excepcion.EscribirLogExcepcion(msjLog); String clientMessage = excepcion.HandleExceptionEx(ex); excepcion = null;
                    ModelState.AddModelError("ID", clientMessage);
                }
            }

            return(View(clienteToDelete));
        }
Esempio n. 3
0
        public ActionResult Create()
        {
            AlquileresMVC.Models.Cliente cliente        = new Cliente();
            AlquileresMVC.Models.Cliente clienteToIDAdd = db.ClienteSet.ToList().LastOrDefault();
            Int32 _id = clienteToIDAdd.ID + 1;

            cliente.ID = _id;
            return(View(cliente));
        }
Esempio n. 4
0
        public ActionResult Edit(Int32 id, FormCollection form)
        {
            AlquileresMVC.Models.Cliente clienteToUpdate = db.ClienteSet.First(c => c.ID == id);

            string[] arreglo = new string[form.AllKeys.ToList().Count];
            Int32    i       = 0;

            foreach (var key in form.AllKeys)
            {
                var value = form[key];
                arreglo[i] = value;
                i++;
            }

            clienteToUpdate.Nombre    = arreglo[0];
            clienteToUpdate.Telefono  = arreglo[1];
            clienteToUpdate.Correo    = arreglo[2];
            clienteToUpdate.Direccion = arreglo[3];
            String sEstatus = arreglo[4];
            Int32  iEstatus = Int32.Parse(sEstatus);

            clienteToUpdate.Estatus = iEstatus;

            TryUpdateModel(clienteToUpdate, "Cliente");
            TryUpdateModel(clienteToUpdate, "Cliente", form.ToValueProvider());

            // Si el modelo es valido, guardo en la BD
            if (ModelState.IsValid)
            {
                db.Connection.Open();
                DbTransaction dbTransaction = db.Connection.BeginTransaction();
                try
                {
                    // Guardar y confirmar el cliente.
                    db.SaveChanges();
                    dbTransaction.Commit();
                    /// Si la transaccion es exitosa nos redirigimos a la pagina de detalles como
                    /// cofirmación de que la operacion resulto exitosa
                    return(RedirectToAction("Details/" + clienteToUpdate.ID));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    HandleException excepcion = new HandleException();
                    String          msjLog    = "Error en " + ObtenerMetodoEnEjecucion(false).ToString() + ".\n" + excepcion.RegistrarExcepcion(ex, ObtenerMetodoEnEjecucion(false).ToString());
                    excepcion.EscribirLogExcepcion(msjLog); String clientMessage = excepcion.HandleExceptionEx(ex); excepcion = null;
                    ModelState.AddModelError("ID", clientMessage);
                }
            }

            return(View(clienteToUpdate));
        }
        public ActionResult Edit(Int32 id, FormCollection form)
        {
            AlquileresMVC.Models.Cliente         cliente = db.ClienteSet.First(c => c.ID == id); Int32 _iIDCliente = cliente.ID;
            List <AlquileresMVC.Models.Alquiler> listAlquiler = db.AlquilerSet.Where(a => a.IDCliente == _iIDCliente && a.Estatus == 1).ToList();
            Double _dMontoEstimado = 0; _dMontoEstimado = (from e in listAlquiler select e.PrecioEstimado).Sum().Value;

            AlquileresMVC.Models.Cantidad_Alquileres_Por_Pagar_VW clienteAlq = dbVW.Cantidad_Alquileres_Por_Pagar_VW_Set.First(c => c.IDCliente == _iIDCliente);
            AlquileresMVC.Models.Descuento descuento = db.DescuentoSet.First(d => d.Codigo == "DEC1");
            Double       _dPorcentajeDescuento       = 0; _dPorcentajeDescuento = descuento.PorcentajeDescuento ?? 0;
            Double       _dDescuento          = _dPorcentajeDescuento * _dMontoEstimado;
            Double       _dMontoTotal         = _dMontoEstimado - _dDescuento;
            PagoCabecera pagoCabeceraToUpdate = db.PagoCabeceraSet.ToList().LastOrDefault();
            Int32        _iID    = pagoCabeceraToUpdate.ID; _iID = _iID + 1;
            DateTime     _dFecha = DateTime.Now;

            if (clienteAlq.NumAlquiler >= 3 && clienteAlq.NumAlquiler <= 5)
            {
                pagoCabeceraToUpdate.MontoExento = _dMontoEstimado;
                pagoCabeceraToUpdate.Descuento   = _dDescuento;
                pagoCabeceraToUpdate.MontoTotal  = _dMontoTotal;
            }
            else
            {
                pagoCabeceraToUpdate.MontoExento = _dMontoEstimado;
                pagoCabeceraToUpdate.Descuento   = 0;
                pagoCabeceraToUpdate.MontoTotal  = _dMontoEstimado;
            }
            pagoCabeceraToUpdate.IDCliente = _iIDCliente;
            pagoCabeceraToUpdate.Fecha     = _dFecha;
            pagoCabeceraToUpdate.ClienteLoad();
            Int32 iEstatus = 1;

            pagoCabeceraToUpdate.Estatus = iEstatus;

            TryUpdateModel(pagoCabeceraToUpdate, "PagoCabecera");

            // Si el modelo es valido, guardo en la BD
            if (ModelState.IsValid)
            {
                db.Connection.Open();
                DbTransaction dbTransaction = db.Connection.BeginTransaction();
                try
                {
                    // Guardar y confirmar.
                    db.AddToPagoCabeceraSet(pagoCabeceraToUpdate);
                    db.SaveChanges();
                    dbTransaction.Commit();
                    /// Si la transaccion es exitosa nos redirigimos a la pagina de detalles como
                    /// cofirmación de que la operacion resulto exitosa
                    return(RedirectToAction("List"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    HandleException excepcion = new HandleException();
                    String          msjLog    = "Error en " + ObtenerMetodoEnEjecucion(false).ToString() + ".\n" + excepcion.RegistrarExcepcion(ex, ObtenerMetodoEnEjecucion(false).ToString());
                    excepcion.EscribirLogExcepcion(msjLog); String clientMessage = excepcion.HandleExceptionEx(ex); excepcion = null;
                    ModelState.AddModelError("ID", clientMessage);
                }
            }

            // Refresca el formulario con los datos guardados
            return(View(pagoCabeceraToUpdate));
        }
Esempio n. 6
0
        public ActionResult Create(FormCollection collection)
        {
            AlquileresMVC.Models.Cliente clienteToAdd = new AlquileresMVC.Models.Cliente();

            string[] arreglo = new string[collection.AllKeys.ToList().Count];
            Int32    i       = 0;

            foreach (var key in collection.AllKeys)
            {
                var value = collection[key];
                arreglo[i] = value;
                i++;
            }

            clienteToAdd.Nombre    = arreglo[0];
            clienteToAdd.Telefono  = arreglo[1];
            clienteToAdd.Correo    = arreglo[2];
            clienteToAdd.Direccion = arreglo[3];
            String sEstatus = arreglo[4];
            Int32  iEstatus = Int32.Parse(sEstatus);

            clienteToAdd.Estatus = iEstatus;

            TryUpdateModel(clienteToAdd, "Cliente");
            TryUpdateModel(clienteToAdd, "Cliente", collection.ToValueProvider());

            //valido claves primaria
            if (db.ClienteSet.FirstOrDefault(c => c.ID == clienteToAdd.ID) != null)
            {
                ModelState.AddModelError("ID", String.Format("Violacion Clave primaria", "ID"));
            }
            else
            {
                // Si el modelo es valido, guardo en la BD
                if (ModelState.IsValid)
                {
                    db.Connection.Open();
                    DbTransaction dbTransaction = db.Connection.BeginTransaction();

                    try
                    {
                        // Guardar y confirmar el cliente.
                        db.AddToClienteSet(clienteToAdd);
                        db.SaveChanges();
                        dbTransaction.Commit();
                        /// Si la transaccion es exitosa nos redirigimos a la pagina de detalles como
                        /// cofirmación de que la operacion resulto exitosa
                        AlquileresMVC.Models.Cliente _entidadToIDAdd = db.ClienteSet.ToList().LastOrDefault();
                        Int32 _id = _entidadToIDAdd.ID;
                        _entidadToIDAdd.ID = _id;
                        return(RedirectToAction("Details/" + _entidadToIDAdd.ID));
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        HandleException excepcion = new HandleException();
                        String          msjLog    = "Error en " + ObtenerMetodoEnEjecucion(false).ToString() + ".\n" + excepcion.RegistrarExcepcion(ex, ObtenerMetodoEnEjecucion(false).ToString());
                        excepcion.EscribirLogExcepcion(msjLog); String clientMessage = excepcion.HandleExceptionEx(ex); excepcion = null;
                        ModelState.AddModelError("ID", clientMessage);
                    }
                }
            }

            return(View(clienteToAdd));
        }
Esempio n. 7
0
 public ActionResult Details(int id)
 {
     AlquileresMVC.Models.Cliente clienteDetail = db.ClienteSet.First(c => c.ID == id);
     return(View(clienteDetail));
 }
Esempio n. 8
0
 public ActionResult Delete(int id)
 {
     AlquileresMVC.Models.Cliente clienteToDelete = db.ClienteSet.First(c => c.ID == id);
     ViewData.Model = clienteToDelete;
     return(View());
 }
Esempio n. 9
0
 public ActionResult Edit(Int32 id)
 {
     AlquileresMVC.Models.Cliente clienteToUpdate = db.ClienteSet.First(c => c.ID == id);
     ViewData.Model = clienteToUpdate;
     return(View());
 }