Esempio n. 1
0
        public static bool Modificar(Prestamos prestamo)
        {
            Context context = new Context();
            bool    found   = false;

            try{
                prestamo.Balance = prestamo.Monto;
                Prestamos viejoPrestamo = PrestamoBLL.Buscar(prestamo.PrestamoId);
                float     nuevoMonto    = prestamo.Monto - viejoPrestamo.Monto;

                context.Database.ExecuteSqlRaw($"delete from MorasDetalle where PrestamoId = {prestamo.PrestamoId}");
                foreach (var anterior in prestamo.Detalle)
                {
                    context.Entry(anterior).State = EntityState.Added;
                }

                context.Entry(prestamo).State = EntityState.Modified;
                found = context.SaveChanges() > 0;

                Personas persona = PersonaBLL.Buscar(prestamo.PersonaId);
                persona.Balance += nuevoMonto;
                PersonaBLL.Modificar(persona);
            } catch {
                throw;
            } finally{
                context.Dispose();
            }

            return(found);
        }
Esempio n. 2
0
        public static bool Eliminar(int id)
        {
            Context context = new Context();
            bool    found   = false;

            try{
                var mora = context.Moras.Find(id);

                List <MorasDetalle> viejosDetalles = Buscar(mora.MoraId).Detalle;
                foreach (MorasDetalle d in viejosDetalles)
                {
                    Prestamos prestamo = PrestamoBLL.Buscar(d.PrestamoId);
                    prestamo.Mora -= d.Valor;
                    PrestamoBLL.Guardar(prestamo);
                }

                if (mora != null)
                {
                    context.Entry(mora).State = EntityState.Deleted;
                    found = context.SaveChanges() > 0;
                }
            } catch {
                throw;
            } finally{
                context.Dispose();
            }

            return(found);
        }
Esempio n. 3
0
        private static bool Insertar(Moras mora)
        {
            Context context = new Context();
            bool    found   = false;

            try
            {
                context.Moras.Add(mora);
                found = context.SaveChanges() > 0;

                List <MorasDetalle> detalles = mora.Detalle;
                foreach (MorasDetalle d in detalles)
                {
                    Prestamos prestamo = PrestamoBLL.Buscar(d.PrestamoId);
                    prestamo.Mora += d.Valor;
                    PrestamoBLL.Guardar(prestamo);
                }
            } catch {
                throw;
            } finally{
                context.Dispose();
            }

            return(found);
        }
Esempio n. 4
0
        public static bool Modificar(Moras mora)
        {
            Context context = new Context();
            bool    found   = false;

            try
            {
                List <MorasDetalle> viejosDetalles = Buscar(mora.MoraId).Detalle;
                foreach (MorasDetalle d in viejosDetalles)
                {
                    Prestamos prestamo = PrestamoBLL.Buscar(d.PrestamoId);
                    prestamo.Mora -= d.Valor;
                    PrestamoBLL.Guardar(prestamo);
                }

                context.Database.ExecuteSqlRaw($"delete from MorasDetalle where MoraId = {mora.MoraId}");
                foreach (var anterior in mora.Detalle)
                {
                    context.Entry(anterior).State = EntityState.Added;
                }

                List <MorasDetalle> nuevosDetalles = mora.Detalle;
                foreach (MorasDetalle d in nuevosDetalles)
                {
                    Prestamos prestamo = PrestamoBLL.Buscar(d.PrestamoId);
                    prestamo.Mora += d.Valor;
                    PrestamoBLL.Guardar(prestamo);
                }

                context.Entry(mora).State = EntityState.Modified;
                found = context.SaveChanges() > 0;
            }
            catch
            {
                throw;
            }
            finally
            {
                context.Dispose();
            }

            return(found);
        }