Exemplo n.º 1
0
        public static bool Eliminar(int id)
        {
            bool     paso     = false;
            Contexto contexto = new Contexto();

            try
            {
                var                 mora = MorasBLL.Buscar(id);
                Prestamos           prestamo;
                List <MorasDetalle> viejosDetalles = Buscar(mora.MoraId).Detalle;
                foreach (MorasDetalle d in viejosDetalles)
                {
                    prestamo       = PrestamoBLL.Buscar(d.PrestamoId);
                    prestamo.Mora -= d.Total;
                    PrestamoBLL.Guardar(prestamo);
                }
                if (mora != null)
                {
                    contexto.Entry(mora).State = EntityState.Deleted;
                    paso = contexto.SaveChanges() > 0;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }
            return(paso);
        }
Exemplo n.º 2
0
        private static bool Insertar(Moras mora)
        {
            bool     paso     = false;
            Contexto contexto = new Contexto();

            try
            {
                contexto.Moras.Add(mora);
                paso = contexto.SaveChanges() > 0;
                Prestamos           prestamo;
                List <MorasDetalle> detalle = mora.Detalle;
                foreach (MorasDetalle m in detalle)
                {
                    prestamo       = PrestamoBLL.Buscar(m.PrestamoId);
                    prestamo.Mora += m.Total;
                    PrestamoBLL.Guardar(prestamo);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }
            return(paso);
        }
Exemplo n.º 3
0
        private static bool Modificar(Moras mora)
        {
            bool     paso     = false;
            Contexto contexto = new Contexto();

            try
            {
                Prestamos           prestamo;
                List <MorasDetalle> detalle = Buscar(mora.MoraId).Detalle;
                foreach (MorasDetalle m in detalle)
                {
                    prestamo       = PrestamoBLL.Buscar(m.PrestamoId);
                    prestamo.Mora -= m.Total;
                    PrestamoBLL.Guardar(prestamo);
                }
                contexto.Database.ExecuteSqlRaw($"Delete FROM MorasDetalle Where MoraId={mora.MoraId}");
                foreach (var item in mora.Detalle)
                {
                    contexto.Entry(item).State = EntityState.Added;
                }

                List <MorasDetalle> nuevo = mora.Detalle;
                foreach (MorasDetalle m in nuevo)
                {
                    prestamo       = PrestamoBLL.Buscar(m.PrestamoId);
                    prestamo.Mora += m.Total;
                    PrestamoBLL.Guardar(prestamo);
                }

                contexto.Entry(mora).State = EntityState.Modified;
                paso = contexto.SaveChanges() > 0;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }
            return(paso);
        }