Пример #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);
        }
Пример #2
0
        public static bool Eliminar(int id)
        {
            Context context = new Context();
            bool    found   = false;

            try{
                var prestamo = context.Prestamos.Find(id);

                if (prestamo != null)
                {
                    Personas persona = PersonaBLL.Buscar(prestamo.PersonaId);
                    persona.Balance -= prestamo.Monto;
                    PersonaBLL.Modificar(persona);

                    context.Prestamos.Remove(prestamo);
                    found = context.SaveChanges() > 0;
                }
            } catch {
                throw;
            } finally{
                context.Dispose();
            }

            return(found);
        }
Пример #3
0
        private static bool Insertar(Prestamos prestamo)
        {
            Context context = new Context();
            bool    found   = false;

            try{
                prestamo.Balance = prestamo.Monto;
                context.Prestamos.Add(prestamo);
                found = context.SaveChanges() > 0;

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

            return(found);
        }