예제 #1
0
        public override void Delete(int id)
        {
            var dto    = GetById(id);
            var entity = CdpContext.LotesCartaPorte.Single(l => l.Id == id);

            dto.Disponibles = CdpContext.CartaDePortes.Count(c => c.Estado == 0 && c.Lote.Id == id);

            if (dto.Cantidad == dto.Disponibles)
            {
                var cdpIds = entity.CartasDePorte.Select(c => c.Id).ToList();

                cdpIds.ForEach(c =>
                {
                    var cdp = entity.CartasDePorte.Single(cc => cc.Id == c);
                    CdpContext.CartaDePortes.Remove(cdp);
                });

                CdpContext.LotesCartaPorte.Remove(entity);
            }
            else
            {
                var maxNroCartaPorte = entity.CartasDePorte.Where(c => c.Estado == 1).Select(c => int.Parse(c.NumeroCartaDePorte)).Max();
                var cdpIds           = entity.CartasDePorte.Where(c => c.Estado == 0).Select(c => c.Id).ToList();

                cdpIds.ForEach(c =>
                {
                    var cdp = entity.CartasDePorte.Single(cc => cc.Id == c);
                    CdpContext.CartaDePortes.Remove(cdp);
                });

                entity.Hasta = maxNroCartaPorte;

                var log1 = new LogOperacion
                {
                    Tabla        = "CartasDePorte",
                    Accion       = "DELETE DISP",
                    ReferenciaId = id,
                    CreateDate   = DateTime.Now,
                    CreatedBy    = UsuarioLogged
                };

                var log2 = new LogOperacion
                {
                    Tabla        = "LoteCartasDePorte",
                    Accion       = "DELETE DISP",
                    ReferenciaId = id,
                    CreateDate   = DateTime.Now,
                    CreatedBy    = UsuarioLogged
                };

                CdpContext.LogOperaciones.Add(log1);
                CdpContext.LogOperaciones.Add(log2);
            }

            CdpContext.SaveChanges();
        }
        public void setLLenarEntidad(int IdeContrato, string TipoOper, string CodiEven, string CodiOper, string CodiUsu, string Entidad)
        {
            var entity = new LogOperacion()
            {
                IDE_CONTRATO = IdeContrato,
                TipoOper     = TipoOper,
                CodiEven     = CodiEven,
                CodiOper     = CodiOper,
                CodiUsu      = CodiUsu,
                Entidad      = Entidad
            };

            this.setGuardarLogOperacion(entity);
        }
 public long setGuardarLogOperacion(LogOperacion log)
 {
     try
     {
         using (var db = new DISEntities())
         {
             db.LogOperacions.Add(log);
             db.SaveChanges();
             return(log.CodiLogOper);
         }
     }
     catch (Exception ex)
     {
         throw (new Exception(ex.Message));
     }
 }
 //este el el metodo generico para llamar desde cualquier parte de la aplicacion
 //ejemplo
 //llena la entidad
 //var operacion = LogOperacion(){agregar sus propiedades menos (FechEven,CodiCnx)}
 //luego instacia la clase nLogOperacion
 //var negocio = nLogOperacion().setGuardarLogOperacion(operacion);
 public long setGuardarLogOperacion(LogOperacion log)
 {
     log.FechEven = FechEven;
     log.CodiCnx  = CodiCnx;
     return(new dLogOperacion().setGuardarLogOperacion(log));
 }