示例#1
0
        public override bool Modificar(Rentas renta)
        {
            bool paso = false;

            _contexto = new DAL.Contexto();

            try
            {
                var rentaAnt   = _contexto.Renta.Find(renta.RentaId);
                var detalleAnt = _contexto.Rentadetalle.Where(r => r.RentaId == rentaAnt.RentaId).AsNoTracking().ToList();
                var cantidad   = rentaAnt.Detalle.Count;

                _contexto.Entry(rentaAnt).State = EntityState.Deleted;
                _contexto.Entry(renta).State    = EntityState.Modified;
                _contexto.Clientes.Find(rentaAnt.ClienteId).VehiculosRentados += cantidad;
                if (_contexto.SaveChanges() > 0)
                {
                    paso = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                _contexto.Dispose();
            }

            return(paso);
        }
示例#2
0
        public override bool Modificar(Prestamo entity)
        {
            _contexto = new DAL.Contexto();
            decimal montoBaseDatos = 0;
            decimal montoEntidad   = 0;
            bool    paso           = false;

            try
            {
                //Busca el detalle anterior en base de datos
                var detalleAnterior = _contexto.Cuotas.Where(x => x.IdPrestamo == entity.IdPrestamo).AsNoTracking().ToList();

                //Agrega a la variable montoBaseDatos el monto del capital mas el interes
                foreach (var item in detalleAnterior)
                {
                    montoBaseDatos += item.Capital + item.Interes;
                }

                //Agrega a la variable montoEntidad el monto del capital mas el interes
                foreach (var item in entity.Detalle)
                {
                    montoEntidad += item.Capital + item.Interes;
                }

                _contexto.Cuenta.Find(entity.IdCuenta).Balance -= montoBaseDatos;
                _contexto.Cuenta.Find(entity.IdCuenta).Balance += montoEntidad;

                //Marca como borrado alguna cuota que este en base de datos y no en la lista detalle

                if (entity.Detalle.Count < detalleAnterior.Count)
                {
                    foreach (var item in detalleAnterior)
                    {
                        if (!entity.Detalle.Exists(x => x.IdCuota.Equals(item.IdCuota)))
                        {
                            _contexto.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                        }
                    }
                }

                //Modifica o agrega una nueva cuota
                foreach (var item in entity.Detalle)
                {
                    _contexto.Entry(item).State = item.IdCuota == 0 ? EntityState.Added : EntityState.Modified;
                }

                //modifica la entidad
                _contexto.Entry(entity).State = EntityState.Modified;

                //Guarda
                paso = _contexto.SaveChanges() > 0 ? true : false;
            }
            catch (Exception)
            {
                throw;
            }
            return(paso);
        }
示例#3
0
        private void Modificarbutton_Click(object sender, EventArgs e)
        {
            DAL.Contexto contexto = new DAL.Contexto();

            Cotizaciones cotizacion = new Cotizaciones();

            cotizacion = contexto.Cotizaciones.Find(1);
            contexto.Dispose();//me desconecto aqui

            contexto = new DAL.Contexto();

            cotizacion.AgregarDetalle(1, "Croissant", 2);
            cotizacion.AgregarDetalle(1, "Croissant", 2);
            cotizacion.AgregarDetalle(1, "Croissant", 2);
            cotizacion.AgregarDetalle(1, "Croissant", 2);
            cotizacion.AgregarDetalle(1, "Croissant", 2);

            //recorrer el detalle
            foreach (var item in cotizacion.Detalle)
            {
                item.CotizacionId          = cotizacion.CotizacionId;
                contexto.Entry(item).State = EntityState.Added;
            }

            contexto.SaveChanges();
        }
示例#4
0
        public override bool Modificar(Deposito entity)
        {
            var  BaseDatos = base.Buscar(entity.DepositoId);
            bool paso      = false;

            _contexto = new DAL.Contexto();
            try
            {
                _contexto.Cuenta.Find(entity.CuentaId).Balance -= BaseDatos.Monto;
                _contexto.Cuenta.Find(entity.CuentaId).Balance += entity.Monto;

                _contexto.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                if (_contexto.SaveChanges() > 0)
                {
                    paso = true;
                }
            }
            catch (Exception)
            {
                throw;
            }



            return(paso);
        }
示例#5
0
        public override bool Eliminar(int id)
        {
            bool paso = false;

            _contexto = new DAL.Contexto();
            try
            {
                var Ant      = _contexto.Renta.Find(id);
                var cantidad = Ant.Detalle.Count;
                if (Ant != null)
                {
                    _contexto.Rentadetalle.RemoveRange(_contexto.Rentadetalle.Where(x => x.RentaId == Ant.RentaId));
                    _contexto.Entry(Ant).State = System.Data.Entity.EntityState.Deleted;
                    _contexto.Clientes.Find(Ant.ClienteId).VehiculosRentados -= cantidad;
                    if (_contexto.SaveChanges() > 0)
                    {
                        paso = true;
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                _contexto.Dispose();
            }



            return(paso);
        }
示例#6
0
        public override bool Eliminar(int id)
        {
            bool paso = false;

            _contexto = new DAL.Contexto();

            try
            {
                var Deposito = _contexto.Depositos.Find(id);
                _contexto.Cuenta.Find(Deposito.CuentaId).Balance -= Deposito.Monto;
                _contexto.Entry(Deposito).State = System.Data.Entity.EntityState.Deleted;
                if (_contexto.SaveChanges() > 0)
                {
                    paso = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(paso);
        }