Exemplo n.º 1
0
        public virtual ActionResult SummaryEdit(string operationNumber, int year, SupervisionPlanView view, bool createNew = false)
        {
            //ViewBag.UploadFileError = ((Exception)Session["IndexDocumentRelationshipError"]).Message;
            ViewBag.EditMode             = true;
            ViewBag.LocalizedStatusValue = Localization.GetText("Draft");
            ViewBag.EditableView         = view;
            ViewBag.operationNumber      = operationNumber;

            SupervisionPlanModel plan = null;

            if (createNew)
            {
                plan = new SupervisionPlanModel
                {
                    Year            = year,
                    OperationNumber = operationNumber
                }
            }
            ;
            var supervisionPlans = PrepareSummaryView(plan, operationNumber, year);

            if (view == SupervisionPlanView.Budget)
            {
                LocalizeAndCompleteBudgetMatrix(supervisionPlans);
            }

            ViewBag.IsNewPlan       = supervisionPlans.Find(p => p.Year == year).ActualVersionIsNew;
            ViewBag.DraftOrModified = supervisionPlans.Find(p => p.Year == year).ActualVersionIsInDraftOrModified;
            ViewBag.Approved        = supervisionPlans.Find(p => p.Year == year).ActualVersionIsApproved;
            ViewBag.Modified        = supervisionPlans.Find(p => p.Year == year).ActualVersionIsInModified;
            ViewBag.OperationId     = supervisionPlans.Find(p => p.Year == year).OperationId;
            ViewBag.OperationNumber = supervisionPlans.Find(p => p.Year == year).OperationNumber;

            return(View("Summary", supervisionPlans));
        }
Exemplo n.º 2
0
        private List <SupervisionPlanModel> PrepareSummaryView(SupervisionPlanModel plan, string operationNumber, int year)
        {
            var availableYears = new List <int> {
                DateTime.Today.Year, DateTime.Today.Year + 1
            };

            if (plan != null)
            {
                availableYears.Remove(year);
            }

            var supervisionPlans = SupervisionPlanRepository.GetByOperation(operationNumber);

            if (plan != null)
            {
                supervisionPlans.Add(plan);
            }

            //Orden anterior: supervisionPlans.Sort((s1, s2) => s1.Year.CompareTo(s2.Year));
            supervisionPlans = supervisionPlans.OrderByDescending(s => s.Year).ToList();

            foreach (SupervisionPlanModel spversionModel in supervisionPlans)
            {
                if (spversionModel.SupervisionPlanVersions != null)
                {
                    spversionModel.SupervisionPlanVersions = spversionModel.SupervisionPlanVersions.OrderByDescending(x => x.ValidationDate).ToList();
                }
            }

            if (supervisionPlans.All(s => s.Year != year) && supervisionPlans.Count > 0)
            {
                year = supervisionPlans.First().Year;
            }

            foreach (var sp in supervisionPlans)
            {
                if (!sp.ActualVersionIsNew)
                {
                    sp.ActualVersionIsNew = sp.ActualVersion == null;
                }

                sp.ActualVersionIsApproved = sp.ActualVersion != null &&
                                             sp.ActualVersion.ValidationStage.Code.Equals("SP_APPR", StringComparison.InvariantCultureIgnoreCase);
                sp.ActualVersionEditable = !(sp.ActualVersion != null &&
                                             sp.ActualVersion.ValidationStage.Code.Contains("SP_REV"));
                sp.ActualVersionCanModify = sp.ActualVersion != null &&
                                            sp.ActualVersion.ValidationStage.Code.Equals("SP_APPR", StringComparison.InvariantCultureIgnoreCase);
                var stages = new List <string> {
                    "SP_DRAFT", "SP_MOD"
                };
                sp.ActualVersionIsInDraftOrModified = sp.ActualVersion == null || stages.Any(s => s.Equals(sp.ActualVersion.ValidationStage.Code, StringComparison.InvariantCultureIgnoreCase));
                sp.ActualVersionIsInModified        = sp.ActualVersion != null &&
                                                      sp.ActualVersion.ValidationStage.Code.Equals("SP_MOD", StringComparison.InvariantCultureIgnoreCase);
                sp.SupervisionPlanId = sp.ActualVersion == null ? -1 : sp.SupervisionPlanId;
            }

            SetLocalizedValues();

            ViewBag.OperationNumber = operationNumber;
            ViewBag.AvailableYears  = availableYears;
            ViewBag.SelectedYear    = year;
            if (supervisionPlans.Count > 0)
            {
                ViewBag.OperationId = supervisionPlans.Last().OperationId;
                SetLocalizedModel(supervisionPlans);
                Session["SupervisionPlan"] = supervisionPlans;
            }

            return(supervisionPlans);
        }