internal int GuardarDetalle(GrupoVentaGanadoInfo venta)
        {
            var animalBL = new AnimalBL();
            var corralBl = new CorralBL();
            var loteBl   = new LoteBL();

            try
            {
                Logger.Info();
                int retorno;
                using (var transaccion = new TransactionScope())
                {
                    var ventaGanadoDetalleDAL = new VentaGanadoDetalleDAL();

                    //Obtener Corral y Lote
                    var corral = corralBl.ObtenerCorralPorCodigo(venta.OrganizacionId, venta.CodigoCorral);
                    var lote   = loteBl.ObtenerPorCorralCerrado(venta.OrganizacionId, corral.CorralID);

                    if (venta.TipoVenta == Info.Enums.TipoVentaEnum.Propio)
                    {
                        //Validar si tenemos animales que pertenezcan a la carga inicial
                        var listaCargaInicial = venta.VentaGandadoDetalle.Where(animal => animal.Animal.CargaInicial).ToList();
                        if (listaCargaInicial != null && listaCargaInicial.Any())
                        {
                            foreach (var animal in listaCargaInicial)
                            {
                                var animalInventario = animalBL.ObtenerAnimalPorArete(animal.Arete, venta.OrganizacionId);
                                var deteccionGrabar  = new DeteccionInfo
                                {
                                    CorralID          = corral.CorralID,
                                    LoteID            = lote.LoteID,
                                    UsuarioCreacionID = venta.VentaGanado.UsuarioModificacionID
                                };

                                // Se intercambian aretes por encontrarse el animal en un corral distinto y ser carga inicial
                                animalBL.ReemplazarAretes(animalInventario, deteccionGrabar);
                            }
                        }
                    }

                    retorno = ventaGanadoDetalleDAL.GuardarDetalle(venta);

                    // Se cierral la transaccion
                    transaccion.Complete();
                }
                return(retorno);
            }
            catch (ExcepcionGenerica)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Guarda la informacion de un arete muerto
        /// </summary>
        /// <param name="muerte"></param>
        /// <param name="esCargaInicial"></param>
        /// <param name="animal"></param>
        /// <returns></returns>
        internal int GuardarMuerte(MuerteInfo muerte, FlagCargaInicial esCargaInicial, AnimalInfo animal)
        {
            try
            {
                Logger.Info();
                int resultado;

                using (var transaccion = new TransactionScope())
                {
                    if (animal != null)
                    {
                        var animalBL = new AnimalBL();
                        // Se valida el flag de EsCargaInicial
                        switch (esCargaInicial)
                        {
                        case FlagCargaInicial.EsCargaInicial:
                            var deteccionGrabar = new DeteccionInfo
                            {
                                CorralID          = muerte.CorralId,
                                LoteID            = muerte.LoteId,
                                UsuarioCreacionID = muerte.UsuarioCreacionID
                            };
                            // Se intercambian aretes por encontrarse el animal en un corral distinto y ser carga inicial
                            animalBL.ReemplazarAretes(animal, deteccionGrabar);
                            break;

                        case FlagCargaInicial.EsAreteNuevo:
                            // Se Reemplaza arete nuevo sobre uno existente del lote
                            animalBL.ReemplazarAreteMismoCorral(animal);
                            break;
                        }
                    }
                    if (muerte.Corral.GrupoCorral != GrupoCorralEnum.Recepcion.GetHashCode() &&
                        string.IsNullOrWhiteSpace(muerte.Arete))
                    {
                        muerte.Arete = GenerarAreteGenerico(muerte);
                    }
                    var muerteDal = new MuerteDAL();
                    resultado = muerteDal.GuardarMuerte(muerte);
                    // Se cierral la transaccion
                    transaccion.Complete();
                }
                return(resultado);
            }
            catch (ExcepcionGenerica)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
        }
Exemple #3
0
 /// <summary>
 /// Obtiene el animal que este muerto
 /// </summary>
 /// <param name="animal"></param>
 /// <param name="deteccionGrabar"></param>
 /// <returns></returns>
 public void ReemplazarAretes(AnimalInfo animal, DeteccionInfo deteccionGrabar)
 {
     try
     {
         Logger.Info();
         var animalBL = new AnimalBL();
         animalBL.ReemplazarAretes(animal, deteccionGrabar);
     }
     catch (ExcepcionGenerica)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Exemple #4
0
        internal int Guardar(DeteccionInfo deteccionGrabar, FlagCargaInicial esCargaInicial, AnimalInfo animal)
        {
            try
            {
                Logger.Info();
                int resultado;
                var transactionOption = new TransactionOptions();
                transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                using (var transaction = new TransactionScope(TransactionScopeOption.Required, transactionOption))
                {
                    if (animal != null)
                    {
                        var animalBL = new AnimalBL();
                        // Se valida el flag de EsCargaInicial
                        switch (esCargaInicial)
                        {
                        case FlagCargaInicial.EsCargaInicial:
                            // Se intercambian aretes por encontrarse el animal en un corral distinto y ser carga inicial
                            animalBL.ReemplazarAretes(animal, deteccionGrabar);
                            break;

                        case FlagCargaInicial.EsAreteNuevo:
                            // Se Reemplaza arete nuevo sobre uno existente del lote
                            animalBL.ReemplazarAreteMismoCorral(animal);
                            break;
                        }
                    }
                    var deteccionDAL = new DeteccionDAL();
                    resultado = deteccionDAL.Guardar(deteccionGrabar);
                    // Se cierral la transaccion
                    transaction.Complete();
                }
                return(resultado);
            }
            catch (ExcepcionGenerica)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
        }
        internal int GuardarAnimalSalida(List <AnimalInfo> listaAnimales, ProgramacionSacrificioGuardadoInfo programacionSacrificioGuardadoInfo)
        {
            int result;

            try
            {
                Logger.Info();
                var loteBL = new LoteBL();
                using (var transaccion = new TransactionScope())
                {
                    var loteInfo        = loteBL.ObtenerPorID(programacionSacrificioGuardadoInfo.LoteID);
                    var deteccionGrabar = new DeteccionInfo
                    {
                        CorralID          = loteInfo.CorralID,
                        LoteID            = loteInfo.LoteID,
                        UsuarioCreacionID = programacionSacrificioGuardadoInfo.UsuarioID
                    };

                    foreach (var animal in listaAnimales)
                    {
                        if (animal != null && animal.CargaInicial)
                        {
                            // Se intercambian aretes por encontrarse el animal en un corral distinto y ser carga inicial
                            var animalBL = new AnimalBL();
                            animalBL.ReemplazarAretes(animal, deteccionGrabar);
                        }
                    }

                    var programacionSacrificio = new ProgramacionSacrificioDAL();
                    result = programacionSacrificio.GuardarAnimalSalida(listaAnimales, programacionSacrificioGuardadoInfo);
                    transaccion.Complete();
                }
            }
            catch (ExcepcionGenerica)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
            return(result);
        }