예제 #1
0
        public ActionResult MantenerPrograma()
        {
            var model = new ProgramaModel();

            try
            {
                using (var service = new ProduccionServiceClient())
                {
                    model.PlanVigente = service.ObtenerPlanVigente();
                }

                if (model.PlanVigente != null && model.PlanVigente.Estado == Constantes.EstadoPlan.Pendiente)
                {
                    using (var service = new ProduccionServiceClient())
                    {
                        model.ProgramasAnteriores = service.ListrarProgramasPorPlan(model.PlanVigente.Id);
                    }

                    if (model.ProgramasAnteriores.Any(p => p.Estado == Constantes.EstadoPrograma.Programado))
                    {
                        var programaVigente =
                            model.ProgramasAnteriores.LastOrDefault(
                                p => p.Estado == Constantes.EstadoOrdenPoduccion.Programado);

                        if (programaVigente != null)
                        {
                            model.Id          = programaVigente.Id;
                            model.Numero      = programaVigente.Numero;
                            model.FechaInicio = programaVigente.FechaInicio;
                            model.FechaFin    = programaVigente.FechaFin;
                            model.CantidadOV  = programaVigente.CantidadOV;
                            model.Estado      = programaVigente.Estado;

                            model.ProgramasAnteriores.Remove(programaVigente);

                            IList <OrdenVenta> ordenesVentaPorPrograma;
                            using (var service = new ProduccionServiceClient())
                            {
                                ordenesVentaPorPrograma = service.ListarOrdenesVentaPorPrograma(model.Id);
                            }
                            if (ordenesVentaPorPrograma.Count > 0)
                            {
                                foreach (var ordenVenta in ordenesVentaPorPrograma)
                                {
                                    model.OrdenesVenta.Add(ordenVenta);
                                }
                            }
                        }
                    }
                    else
                    {
                        using (var service = new ProduccionServiceClient())
                        {
                            model.OrdenesVenta = service.ListarOrdenesVentaPendiente();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(ex);
            }
            return(View(model));
        }
        public ActionResult MantenerPrograma()
        {
            var model = new ProgramaModel();
            try
            {
                using (var service = new ProduccionServiceClient())
                {
                    model.PlanVigente = service.ObtenerPlanVigente();
                }

                if (model.PlanVigente != null && model.PlanVigente.Estado == Constantes.EstadoPlan.Pendiente)
                {
                    using (var service = new ProduccionServiceClient())
                    {
                        model.ProgramasAnteriores = service.ListrarProgramasPorPlan(model.PlanVigente.Id);
                    }

                    if (model.ProgramasAnteriores.Any(p => p.Estado == Constantes.EstadoPrograma.Programado))
                    {
                        var programaVigente =
                            model.ProgramasAnteriores.LastOrDefault(
                                p => p.Estado == Constantes.EstadoOrdenPoduccion.Programado);

                        if (programaVigente != null)
                        {
                            model.Id = programaVigente.Id;
                            model.Numero = programaVigente.Numero;
                            model.FechaInicio = programaVigente.FechaInicio;
                            model.FechaFin = programaVigente.FechaFin;
                            model.CantidadOV = programaVigente.CantidadOV;
                            model.Estado = programaVigente.Estado;

                            model.ProgramasAnteriores.Remove(programaVigente);

                            IList<OrdenVenta> ordenesVentaPorPrograma;
                            using (var service = new ProduccionServiceClient())
                            {
                                ordenesVentaPorPrograma = service.ListarOrdenesVentaPorPrograma(model.Id);
                            }
                            if (ordenesVentaPorPrograma.Count > 0)
                            {
                                foreach (var ordenVenta in ordenesVentaPorPrograma)
                                {
                                    model.OrdenesVenta.Add(ordenVenta);
                                }
                            }
                        }
                    }
                    else
                    {
                        using (var service = new ProduccionServiceClient())
                        {
                            model.OrdenesVenta = service.ListarOrdenesVentaPendiente();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(ex);
            }
            return View(model);
        }