コード例 #1
0
 public async Task <IHttpActionResult> Get(int UserID)
 {
     return(Ok(await DeliverablesViewModel.MapFromAsync(db.Deliverables.Where(x => x.UserID == UserID).ToList())));
 }
コード例 #2
0
        public static void UpdateProposalOperationViewModel(this ProposalViewModel viewModel, ClientFieldData[] clientFieldData)
        {
            var readyForSubmission    = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("ReadyForSubmission")).Value;
            var subtitleProposal      = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("ProposalSubtitle")).Value;
            var orgUnitJointProposals = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("OrgUnitJointProposal")).ToList();
            var beneficiaryCountries  = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("countriesToBeSaved")).Value;
            var deliverableId         = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("DeliverableId")).ToList();
            var type            = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("Type")).ToList();
            var name            = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("Name")).ToList();
            var plannedDate     = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("PlannedDate")).ToList();
            var budgetId        = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("BudgetId")).ToList();
            var activities      = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("Activity")).ToList();
            var consultations   = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("Consultation")).ToList();
            var travels         = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("Travel")).ToList();
            var others          = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("Other")).ToList();
            var otherFinancings = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Equals("OtherFinancing")).ToList();
            var requestedAmount = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("RequestedAmount")).Value;

            var objectives  = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextObjectives")).Value;
            var mainOutputs = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextMainOutputs")).Value;

            string mainQuestions = null;
            string earlierLiteratureQuestions = null;
            string methodologicalAproach      = null;
            string strategyAndActivities      = null;

            //string nameOfPeerReview = null;
            //string additionalTechnicalInformation = null;
            string reportDeliverables = null;

            if (viewModel.ProposalType.Equals(ESWCIPEnums.TYPE_ESW))
            {
                mainQuestions = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextMainQuestions")).Value;
                earlierLiteratureQuestions = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextEarlierLiteratureQuestions")).Value;
                methodologicalAproach      = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextMethodologicalApproach")).Value;
                strategyAndActivities      = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextStrategyAndActivities")).Value;

                //nameOfPeerReview = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextNameOfPeerReview")).Value;
                //additionalTechnicalInformation = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextAdditionalTechnicalInformation")).Value;
            }

            if (viewModel.ProposalType.Equals(ESWCIPEnums.TYPE_CIP))
            {
                reportDeliverables = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextReportDeliverables")).Value;
            }

            var risks               = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextRisksContent")).Value;
            var coordinationMdbs    = clientFieldData.First(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("inputTextSummaryOfCollaboration")).Value;
            var documentDescription = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("documentDescription"));
            var documentNumber      = clientFieldData.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Name.Contains("documentNumber"));

            viewModel.IsReadyForSubmission = Convert.ToBoolean(readyForSubmission);

            viewModel.GeneralInformation.SubtitleOfProposal = subtitleProposal;

            var alreadyExistingOrganizationalUnits  = viewModel.GeneralInformation.OrganizationalUnit.Select(x => x.UnitId.ToString()).ToList();
            var alreadyExistingBeneficiaryCountries = viewModel.GeneralInformation.BeneficiaryCountries.Select(x => x.CountryId.ToString()).ToList();

            if (viewModel.GeneralInformation.NewOrganizationalUnits == null)
            {
                viewModel.GeneralInformation.NewOrganizationalUnits = new List <int>();
            }

            if (viewModel.GeneralInformation.DeletedOrganizationalUnits == null)
            {
                viewModel.GeneralInformation.DeletedOrganizationalUnits = new List <int>();
            }

            orgUnitJointProposals = orgUnitJointProposals.Where(x => !string.IsNullOrWhiteSpace(x.Value)).ToList();

            foreach (var unit in orgUnitJointProposals)
            {
                if (!alreadyExistingOrganizationalUnits.Contains(unit.Value))
                {
                    viewModel.GeneralInformation.NewOrganizationalUnits.Add(Convert.ToInt32(unit.Value));
                }
            }

            foreach (var eou in alreadyExistingOrganizationalUnits)
            {
                if (!orgUnitJointProposals.Select(x => x.Value).ToList().Contains(eou))
                {
                    viewModel.GeneralInformation.DeletedOrganizationalUnits.Add(Convert.ToInt32(eou));
                }
                viewModel.GeneralInformation.OrganizationalUnit.RemoveAll(bc => bc.UnitId.Equals(Convert.ToInt32(eou)));
            }

            var beneficiaryCountriesSave = beneficiaryCountries.Split('|').Where(x => !string.IsNullOrEmpty(x)).Distinct().ToArray();

            if (viewModel.GeneralInformation.NewBeneficiaryCountries == null)
            {
                viewModel.GeneralInformation.NewBeneficiaryCountries = new List <int>();
            }

            if (viewModel.GeneralInformation.DeletedBeneficiaryCountries == null)
            {
                viewModel.GeneralInformation.DeletedBeneficiaryCountries = new List <int>();
            }

            foreach (var bc in beneficiaryCountriesSave)
            {
                if (!alreadyExistingBeneficiaryCountries.Contains(bc))
                {
                    viewModel.GeneralInformation.NewBeneficiaryCountries.Add(Convert.ToInt32(bc));
                }
            }

            foreach (var bcd in alreadyExistingBeneficiaryCountries)
            {
                if (!beneficiaryCountriesSave.Contains(bcd))
                {
                    viewModel.GeneralInformation.DeletedBeneficiaryCountries.Add(Convert.ToInt32(bcd));
                }
                viewModel.GeneralInformation.BeneficiaryCountries.RemoveAll(bc => bc.CountryId.Equals(Convert.ToInt32(bcd)));
            }

            viewModel.Oera.Objectives                 = objectives;
            viewModel.Oera.MainOutputs                = mainOutputs;
            viewModel.Oera.ReportDeliverables         = reportDeliverables;
            viewModel.Oera.MainQuestions              = mainQuestions;
            viewModel.Oera.EarlierLiteratureQuestions = earlierLiteratureQuestions;
            viewModel.Oera.MethodologicalApproach     = methodologicalAproach;
            viewModel.Oera.StrategyAndActivities      = strategyAndActivities;

            viewModel.Risks.ImplementationRisks = risks;
            viewModel.CoordinationMDBs.SummaryOfCollaborationText = coordinationMdbs;

            for (int i = 0; i < deliverableId.Count(); i++)
            {
                var uType        = type.ElementAt(i).Value;
                var uName        = name.ElementAt(i).Value;
                var uPlannedDate = plannedDate.ElementAt(i).Value;

                if (Convert.ToInt32(deliverableId.ElementAt(i).Value).Equals(0))
                {
                    var deliverable = new DeliverablesViewModel
                    {
                        DeliverableId = Convert.ToInt32(deliverableId.ElementAt(i).Value),
                        Type          = uType,
                        Name          = uName,
                        PlannedDate   = Convert.ToDateTime(uPlannedDate)
                    };

                    viewModel.Deliverables.Add(deliverable);
                }
                else
                {
                    var index = viewModel.Deliverables.FindIndex(x => x.DeliverableId == Convert.ToInt32(deliverableId.ElementAt(i).Value));

                    viewModel.Deliverables.ElementAt(index).Type        = uType;
                    viewModel.Deliverables.ElementAt(index).Name        = uName;
                    viewModel.Deliverables.ElementAt(index).PlannedDate = Convert.ToDateTime(uPlannedDate);
                }
            }

            for (int i = 0; i < budgetId.Count(); i++)
            {
                var act = activities.ElementAt(i).Value;
                var con = !string.IsNullOrEmpty(consultations.ElementAt(i).Value) ? (decimal?)Convert.ToDecimal(consultations.ElementAt(i).Value) : null;
                var tra = !string.IsNullOrEmpty(travels.ElementAt(i).Value) ? (decimal?)Convert.ToDecimal(travels.ElementAt(i).Value) : null;
                var oth = !string.IsNullOrEmpty(others.ElementAt(i).Value) ? (decimal?)Convert.ToDecimal(others.ElementAt(i).Value) : null;
                var ofi = !string.IsNullOrEmpty(otherFinancings.ElementAt(i).Value) ? (decimal?)Convert.ToDecimal(otherFinancings.ElementAt(i).Value) : null;

                if (Convert.ToInt32(budgetId.ElementAt(i).Value).Equals(0))
                {
                    var budget = new BudgetViewModel
                    {
                        BudgetId       = Convert.ToInt32(budgetId.ElementAt(i).Value),
                        Activity       = act,
                        Consultation   = con,
                        Travel         = tra,
                        Other          = oth,
                        OtherFinancing = ofi
                    };

                    viewModel.Budgets.Add(budget);
                }
                else
                {
                    var index = viewModel.Budgets.FindIndex(x => x.BudgetId == Convert.ToInt32(budgetId.ElementAt(i).Value));

                    viewModel.Budgets.ElementAt(index).Activity       = act;
                    viewModel.Budgets.ElementAt(index).Consultation   = con;
                    viewModel.Budgets.ElementAt(index).Travel         = tra;
                    viewModel.Budgets.ElementAt(index).Other          = oth;
                    viewModel.Budgets.ElementAt(index).OtherFinancing = ofi;
                }
            }

            viewModel.RequestedAmount = !string.IsNullOrEmpty(requestedAmount) ? (decimal?)Convert.ToDecimal(requestedAmount) : null;

            var deleteBudgets = clientFieldData.FirstOrDefault(o => o.Name.Equals("deleteBudgets"));

            if (deleteBudgets == null)
            {
                return;
            }

            var deleteB = deleteBudgets.Value.Split('|').Where(x => !string.IsNullOrEmpty(x)).ToArray();

            if (viewModel.DeleteBudgets == null)
            {
                viewModel.DeleteBudgets = new List <int>();
            }

            foreach (var s in deleteB)
            {
                viewModel.DeleteBudgets.Add(Convert.ToInt32(s));
                viewModel.Budgets.RemoveAll(b => b.BudgetId.Equals(Convert.ToInt32(s)));
            }

            var deleteDeliverables = clientFieldData.FirstOrDefault(o => o.Name.Equals("deleteDeliverables"));

            if (deleteDeliverables == null)
            {
                return;
            }

            var deleteD = deleteDeliverables.Value.Split('|').Where(x => !string.IsNullOrEmpty(x)).ToArray();

            if (viewModel.DeleteDeliverables == null)
            {
                viewModel.DeleteDeliverables = new List <int>();
            }

            foreach (var s in deleteD)
            {
                viewModel.DeleteDeliverables.Add(Convert.ToInt32(s));
                viewModel.Deliverables.RemoveAll(b => b.DeliverableId.Equals(Convert.ToInt32(s)));
            }

            //Add
            var documentIndex = 0;

            foreach (var document in documentDescription)
            {
                var documentNumberValue = documentNumber.ToArray()[documentIndex].Value;

                viewModel.Oera.Documents.Add(
                    new DocumentViewModel
                {
                    Description = document.Value,
                    DocNumber   = documentNumberValue
                });

                documentIndex++;
            }
        }
コード例 #3
0
        public async Task <IHttpActionResult> Post(Deliverable del)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Deliverables.Add(del);
            await db.SaveChangesAsync();

            DeliverableDetail delDet = new DeliverableDetail();

            delDet.DelID = del.ID;
            var newDelDate = del.FirstDueDate.ToString().Split(' ')[0];
            var d          = newDelDate.Split('/');

            if (d[0].Length == 1)
            {
                d[0] = '0' + d[0];
            }
            if (d[1].Length == 1)
            {
                d[1] = '0' + d[1];
            }
            newDelDate = d[0] + '/' + d[1] + '/' + d[2];
            System.Diagnostics.Debug.WriteLine(newDelDate);
            var interval = 0;

            if (del.Frequency == "Weekly")
            {
                interval = 1095;
                for (var i = 0; i <= interval; i += 7)
                {
                    delDet.DateDue = DateTime.ParseExact(newDelDate, "MM/dd/yyyy", null).AddDays(i);
                    db.DeliverableDetails.Add(delDet);
                    await db.SaveChangesAsync();
                }
            }
            else if (del.Frequency == "Monthly")
            {
                interval = 36;
                for (var i = 0; i <= interval; i++)
                {
                    delDet.DateDue = DateTime.ParseExact(newDelDate, "MM/dd/yyyy", null).AddMonths(i);
                    db.DeliverableDetails.Add(delDet);
                    await db.SaveChangesAsync();
                }
            }
            else if (del.Frequency == "Quarterly")
            {
                interval = 36;
                for (var i = 0; i <= interval; i += 3)
                {
                    delDet.DateDue = DateTime.ParseExact(newDelDate, "MM/dd/yyyy", null).AddMonths(i);
                    db.DeliverableDetails.Add(delDet);
                    await db.SaveChangesAsync();
                }
            }
            else if (del.Frequency == "Semi-Annual")
            {
                interval = 36;
                for (var i = 0; i <= interval; i += 6)
                {
                    delDet.DateDue = DateTime.ParseExact(newDelDate, "MM/dd/yyyy", null).AddMonths(i);
                    db.DeliverableDetails.Add(delDet);
                    await db.SaveChangesAsync();
                }
            }
            else if (del.Frequency == "Annual")
            {
                interval = 3;
                for (var i = 0; i <= interval; i++)
                {
                    delDet.DateDue = DateTime.ParseExact(newDelDate, "MM/dd/yyyy", null).AddYears(i);
                    db.DeliverableDetails.Add(delDet);
                    await db.SaveChangesAsync();
                }
            }


            return(Ok(DeliverablesViewModel.MapFrom(del)));
        }