internal int GuardarDetalle(GrupoVentaGanadoInfo venta)
 {
     try
     {
         Logger.Info();
         Dictionary <string, object> parameters;
         if (venta.TipoVenta == Info.Enums.TipoVentaEnum.Propio)
         {
             parameters = AuxVentaGanadoDetalle.ObtenerParametrosGrabarDetallePropio(venta);
         }
         else
         {
             parameters = AuxVentaGanadoDetalle.ObtenerParametrosGrabarDetalleExterno(venta);
         }
         int result = Create("SalidaIndividualVenta_GuardarDetalleGanado", parameters);
         return(result);
     }
     catch (SqlException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (DataException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
        public static int GuardarVentaDetalle(string codigoCorral, int causaPrecioId, VentaGanadoInfo ventaGanado, List <VentaGanadoDetalleInfo> ventaGanadoDetalle, int tipoVenta, int totalCabezas)
        {
            int valorRetorno = 0;
            var datosVenta   = new GrupoVentaGanadoInfo();

            try
            {
                var seguridad = (SeguridadInfo)HttpContext.Current.Session["Seguridad"];
                datosVenta.OrganizacionId = seguridad.Usuario.Organizacion.OrganizacionID;
                datosVenta.UsuarioID      = seguridad.Usuario.UsuarioID;
                datosVenta.TotalCabezas   = totalCabezas;
                datosVenta.TipoVenta      = (TipoVentaEnum)tipoVenta;
                datosVenta.CausaPrecioID  = causaPrecioId;
                //informacion del la organzacion y usuario
                if (seguridad != null)
                {
                    var ventaGanadoDetallePl = new VentaGanadoDetallePL();
                    ventaGanado.UsuarioModificacionID = datosVenta.UsuarioID;
                    for (var i = 0; i < ventaGanadoDetalle.Count; i++)
                    {
                        ventaGanadoDetalle[i].FotoVenta = TipoFoto.Venta.ToString() + '/' + ventaGanadoDetalle[i].FotoVenta;
                    }
                    datosVenta.CodigoCorral        = codigoCorral;
                    datosVenta.VentaGanado         = ventaGanado;
                    datosVenta.VentaGandadoDetalle = ventaGanadoDetalle;
                    valorRetorno = ventaGanadoDetallePl.GuardarDetalle(datosVenta);
                }
            }
            catch (Exception ex)
            {
                valorRetorno = -1;
            }

            return(valorRetorno);
        }
        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);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="venta"></param>
 /// <returns></returns>
 public int GuardarDetalle(GrupoVentaGanadoInfo venta)
 {
     try
     {
         Logger.Info();
         var ventaGanadoDetalleBL = new VentaGanadoDetalleBL();
         int result = ventaGanadoDetalleBL.GuardarDetalle(venta);
         return(result);
     }
     catch (ExcepcionGenerica)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #5
0
        internal static Dictionary <string, object> ObtenerParametrosGrabarDetalleExterno(GrupoVentaGanadoInfo venta)
        {
            try
            {
                Logger.Info();
                var xml = new XElement("ROOT",
                                       new XElement("GrabarVenta",
                                                    new XElement("OrganizacionID", venta.OrganizacionId),
                                                    new XElement("FolioTicket", venta.VentaGanado.FolioTicket),
                                                    new XElement("CodigoCorral", venta.CodigoCorral),
                                                    new XElement("UsuarioID", venta.UsuarioID),
                                                    new XElement("CausaPrecioID", venta.CausaPrecioID),
                                                    new XElement("Arete", ""),
                                                    new XElement("FotoVenta", ""),
                                                    new XElement("TipoVenta", venta.TipoVenta.GetHashCode()),
                                                    new XElement("TotalCabezas", venta.TotalCabezas)
                                                    ));

                var parametros =
                    new Dictionary <string, object>
                {
                    { "@XmlVenta", xml.ToString() }
                };
                return(parametros);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
        }