private void GuardarProyeccion(CheckListCorralInfo checkListCorral, CheckListCorralDAL checkListCorralDAL) { var loteProyeccion = checkListCorralDAL.GenerarProyeccion(checkListCorral); var loteProyeccionBL = new LoteProyeccionPL(); var listaReimplantesGuardar = new List <LoteReimplanteInfo>(); if (loteProyeccion == null) { return; } loteProyeccion.UsuarioCreacionID = checkListCorral.UsuarioCreacionID; loteProyeccion.RequiereRevision = checkListCorral.RequiereRevision; var loteProyeccionID = loteProyeccionBL.Guardar(loteProyeccion); var primerReimplante = new LoteReimplanteInfo { LoteProyeccionID = loteProyeccionID, NumeroReimplante = loteProyeccion.Proyeccion.PrimerReimplante, FechaProyectada = loteProyeccion.Proyeccion.FechaProyectada1, PesoProyectado = loteProyeccion.Proyeccion.PesoProyectado1, UsuarioCreacionID = checkListCorral.UsuarioCreacionID }; if (primerReimplante.NumeroReimplante != 0 && primerReimplante.FechaProyectada != DateTime.MinValue && primerReimplante.PesoProyectado != 0) { listaReimplantesGuardar.Add(primerReimplante); } var segundoReimplante = new LoteReimplanteInfo { LoteProyeccionID = loteProyeccionID, NumeroReimplante = loteProyeccion.Proyeccion.SegundoReimplante, FechaProyectada = loteProyeccion.Proyeccion.FechaProyectada2, PesoProyectado = loteProyeccion.Proyeccion.PesoProyectado2, UsuarioCreacionID = checkListCorral.UsuarioCreacionID }; if (segundoReimplante.NumeroReimplante != 0 && segundoReimplante.FechaProyectada != DateTime.MinValue && segundoReimplante.PesoProyectado != 0) { listaReimplantesGuardar.Add(segundoReimplante); } var loteReimplanteBL = new LoteReimplanteBL(); if (listaReimplantesGuardar.Count > 0) { loteReimplanteBL.GuardarListaReimplantes(listaReimplantesGuardar); } checkListCorral.FechaSacrificio = loteProyeccion.FechaSacrificio; checkListCorral.Fecha1Reimplante = loteProyeccion.Proyeccion.FechaProyectada1; checkListCorral.Fecha2Reimplante = loteProyeccion.Proyeccion.FechaProyectada2; checkListCorral.DiasEngorda = loteProyeccion.DiasEngorda; }
/// <summary> /// Metodo para guardar la configuracion de reimplantes /// </summary> /// <param name="configuracionReimplante">Representa el Contexto de lo que se va a guardar</param> public int GuardarConfiguracionReimplante(ConfiguracionReimplanteModel configuracionReimplante) { try { Logger.Info(); var loteReimplanteBL = new LoteReimplanteBL(); var loteProyeccionDAL = new LoteProyeccionDAL(); var loteDAL = new LoteDAL(); int result = configuracionReimplante.LoteProyeccion.LoteProyeccionID; var opciones = new TransactionOptions(); var filtroDisponilidadInfo = new FiltroDisponilidadInfo { UsuarioId = configuracionReimplante.LoteProyeccion.UsuarioCreacionID, ListaLoteDisponibilidad = new List <DisponibilidadLoteInfo> { new DisponibilidadLoteInfo { LoteId = configuracionReimplante.Lote.LoteID, FechaDisponibilidad = configuracionReimplante.FechaDisponible, DisponibilidadManual = false } } }; opciones.IsolationLevel = IsolationLevel.ReadUncommitted; opciones.Timeout = new TimeSpan(2, 0, 0); using (var scope = new TransactionScope(TransactionScopeOption.Required, opciones)) { if (configuracionReimplante.LoteProyeccion.LoteProyeccionID == 0) { configuracionReimplante.LoteProyeccion.OrganizacionID = configuracionReimplante.Corral.Organizacion.OrganizacionID; configuracionReimplante.LoteProyeccion.LoteID = configuracionReimplante.Lote.LoteID; result = loteProyeccionDAL.Crear(configuracionReimplante.LoteProyeccion); configuracionReimplante.LoteProyeccion.LoteProyeccionID = result; loteProyeccionDAL.CrearBitacora(configuracionReimplante.LoteProyeccion); } else { if (configuracionReimplante.LoteProyeccion.AplicaBitacora) { loteProyeccionDAL.Actualizar(configuracionReimplante.LoteProyeccion); loteProyeccionDAL.CrearBitacora(configuracionReimplante.LoteProyeccion); } } if (configuracionReimplante.LoteProyeccion.ListaReimplantes != null && configuracionReimplante.LoteProyeccion.ListaReimplantes.Any()) { configuracionReimplante.LoteProyeccion.ListaReimplantes.ToList().ForEach( reimp => reimp.LoteProyeccionID = result); loteReimplanteBL.GuardarListaReimplantes( configuracionReimplante.LoteProyeccion.ListaReimplantes.ToList()); } loteDAL.ActualizarLoteDisponibilidad(filtroDisponilidadInfo); if (configuracionReimplante.Lote.AplicaCierreLote) { loteDAL.ActualizaFechaCierre(configuracionReimplante.Lote.LoteID, configuracionReimplante.UsuarioCreacionID); } scope.Complete(); } return(result); } catch (ExcepcionGenerica) { throw; } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }