private PartialViewResult ViewDeleteCostAuthority(CostAuthorityObligationRequest costAuthorityObligationRequest, ConfirmDialogFormViewModel viewModel)
        {
            var displayName = $"this Projected Obligation from Cost Authority: {costAuthorityObligationRequest.CostAuthority.CostAuthorityWorkBreakdownStructure}";
            var viewData    = new ConfirmDialogFormViewData($"Are you sure you want to delete \"{displayName}\"?", true);

            return(RazorPartialView <ConfirmDialogForm, ConfirmDialogFormViewData, ConfirmDialogFormViewModel>(viewData, viewModel));
        }
 public ActionResult Edit(ObligationRequestPrimaryKey obligationRequestPrimaryKey, EditObligationRequestViewModel viewModel)
 {
     if (!ModelState.IsValid)
     {
         var firmaPage = FirmaPageTypeEnum.ObligationRequestFromGridDialog.GetFirmaPage();
         return(ViewEdit(viewModel, firmaPage));
     }
     viewModel.UpdateModel(obligationRequestPrimaryKey.EntityObject, CurrentFirmaSession);
     if (viewModel.IsModification)
     {
         var obligationRequest        = obligationRequestPrimaryKey.EntityObject;
         var agreement                = HttpRequestStorage.DatabaseEntities.Agreements.Single(x => x.AgreementID == viewModel.AgreementID.Value);
         var costAuthorities          = HttpRequestStorage.DatabaseEntities.CostAuthorities.ToList();
         var agreementCostAuthorities = agreement.AgreementCostAuthorities;
         var listOfCostAuthorityIDs   = agreementCostAuthorities.Select(x => x.CostAuthorityID).ToList();
         var currentListOfCostAuthoritiesOnObligationRequest = obligationRequest
                                                               .CostAuthorityObligationRequests
                                                               .Select(x => x.CostAuthorityID).ToList();
         foreach (var costAuthorityID in listOfCostAuthorityIDs)
         {
             if (!currentListOfCostAuthoritiesOnObligationRequest.Contains(costAuthorityID))
             {
                 var costAuthority = costAuthorities.Single(x => x.CostAuthorityID == costAuthorityID);
                 var newCostAuthorityReclamationAgreement = new CostAuthorityObligationRequest(costAuthority, obligationRequest);
                 obligationRequest.CostAuthorityObligationRequests.Add(newCostAuthorityReclamationAgreement);
             }
         }
     }
     HttpRequestStorage.DatabaseEntities.SaveChanges();
     ExcelUploadController.DoObligationRequestMatching(obReqLogger);
     return(new ModalDialogFormJsonResult());
 }
        private ActionResult MakeTheNewObligationRequest(EditObligationRequestViewModel viewModel)
        {
            var contractType  = HttpRequestStorage.DatabaseEntities.ContractTypes.Single(x => x.ContractTypeID == viewModel.ContractTypeID);
            var requestStatus = ObligationRequestStatus.AllLookupDictionary[viewModel.ObligationRequestStatusID];
            var obligationRequestFromViewModel = new ObligationRequest(viewModel.IsModification, contractType, requestStatus, viewModel.DescriptionOfNeed, DateTime.Now, CurrentFirmaSession.Person);

            viewModel.UpdateModel(obligationRequestFromViewModel, CurrentFirmaSession);

            if (viewModel.IsModification)
            {
                var agreement                = HttpRequestStorage.DatabaseEntities.Agreements.Single(x => x.AgreementID == viewModel.AgreementID.Value);
                var costAuthorities          = HttpRequestStorage.DatabaseEntities.CostAuthorities.ToList();
                var agreementCostAuthorities = agreement.AgreementCostAuthorities;
                var listOfCostAuthorityIDs   = agreementCostAuthorities.Select(x => x.CostAuthorityID).ToList();
                foreach (var costAuthorityID in listOfCostAuthorityIDs)
                {
                    var costAuthority = costAuthorities.Single(x => x.CostAuthorityID == costAuthorityID);
                    var newCostAuthorityReclamationAgreement = new CostAuthorityObligationRequest(costAuthority, obligationRequestFromViewModel);
                    obligationRequestFromViewModel.CostAuthorityObligationRequests.Add(newCostAuthorityReclamationAgreement);
                }
            }

            HttpRequestStorage.DatabaseEntities.SaveChanges();
            ExcelUploadController.DoObligationRequestMatching(obReqLogger);
            return(new ModalDialogFormJsonResult());
        }
        public ActionResult EditCostAuthorityObligationRequests(ObligationRequestPrimaryKey reclamationObligationRequestPrimaryKey, EditCostAuthorityObligationRequestsViewModel viewModel)
        {
            var reclamationObligationRequest = reclamationObligationRequestPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                var firmaPage = FirmaPageTypeEnum.AddCostAuthorityToObligationRequest.GetFirmaPage();
                return(ViewEditCostAuthorityObligationRequests(reclamationObligationRequest, viewModel, firmaPage));
            }

            var listOfCostAuthorityIDs = viewModel.CostAuthorityJsonList.Select(x => x.CostAuthorityID).ToList();
            var existingCostAuthorityObligationRequests = reclamationObligationRequest.CostAuthorityObligationRequests;

            foreach (var costAuthorityID in listOfCostAuthorityIDs)
            {
                var costAuthorityJson =
                    viewModel.CostAuthorityJsonList.Single(x => x.CostAuthorityID == costAuthorityID);
                if (!existingCostAuthorityObligationRequests.Select(x => x.CostAuthorityID).Contains(costAuthorityID))
                {
                    var newCostAuthorityReclamationAgreement =
                        new CostAuthorityObligationRequest(costAuthorityID, reclamationObligationRequest.ObligationRequestID)
                    {
                        ProjectedObligation = costAuthorityJson.ProjectedObligation
                        , CostAuthorityObligationRequestNote = costAuthorityJson.Note
                        , TechnicalRepresentativePersonID    = costAuthorityJson.TechnicalRepresentativePersonID
                        , RecipientOrganizationID            = costAuthorityJson.RecipientOrganizationID
                        , BudgetObjectCodeID = costAuthorityJson.BudgetObjectCodeID
                    };
                    reclamationObligationRequest.CostAuthorityObligationRequests.Add(newCostAuthorityReclamationAgreement);
                }
            }
            HttpRequestStorage.DatabaseEntities.SaveChanges();
            ExcelUploadController.DoObligationRequestMatching(obReqLogger);
            return(new ModalDialogFormJsonResult());
        }
 public void UpdateModel(CostAuthorityObligationRequest costAuthorityObligationRequest, FirmaSession currentFirmaSession)
 {
     costAuthorityObligationRequest.ProjectedObligation = ProjectedObligation;
     costAuthorityObligationRequest.CostAuthorityObligationRequestNote = CostAuthorityObligationRequestNote;
     costAuthorityObligationRequest.RecipientOrganizationID            = RecipientOgranizationID;
     costAuthorityObligationRequest.TechnicalRepresentativePersonID    = TechnicalRepresentativeID;
     costAuthorityObligationRequest.BudgetObjectCodeID = BudgetObjectCodeID;
 }
 public EditCostAuthorityObligationRequestViewModel(CostAuthorityObligationRequest costAuthorityObligationRequest)
 {
     CostAuthorityWorkBreakdownStructure = costAuthorityObligationRequest.CostAuthority.CostAuthorityWorkBreakdownStructure;
     AccountStructureDescription         = costAuthorityObligationRequest.CostAuthority.AccountStructureDescription;
     ProjectedObligation = costAuthorityObligationRequest.ProjectedObligation;
     CostAuthorityObligationRequestNote = costAuthorityObligationRequest.CostAuthorityObligationRequestNote;
     TechnicalRepresentativeID          = costAuthorityObligationRequest.TechnicalRepresentativePersonID;
     RecipientOgranizationID            = costAuthorityObligationRequest.RecipientOrganizationID;
     BudgetObjectCodeID = costAuthorityObligationRequest.BudgetObjectCodeID;
 }
        private PartialViewResult ViewEditCostAuthorityObligationRequest(CostAuthorityObligationRequest costAuthorityObligationRequest, EditCostAuthorityObligationRequestViewModel viewModel, FirmaPage firmaPage)
        {
            var projectStatusFirmaPage = firmaPage;
            var allOrganizations       = HttpRequestStorage.DatabaseEntities.Organizations.ToList();
            var allPeople            = HttpRequestStorage.DatabaseEntities.People.ToList();
            var allBudgetObjectCodes = HttpRequestStorage.DatabaseEntities.BudgetObjectCodes.ToList();
            var viewData             = new EditCostAuthorityObligationRequestViewData(projectStatusFirmaPage, CurrentFirmaSession, costAuthorityObligationRequest.ObligationRequest, allOrganizations, allPeople, allBudgetObjectCodes);

            return(RazorPartialView <EditCostAuthorityObligationRequest, EditCostAuthorityObligationRequestViewData, EditCostAuthorityObligationRequestViewModel>(viewData, viewModel));
        }
 public static string GetEditUrl(this CostAuthorityObligationRequest costAuthorityObligationRequest)
 {
     return(EditUrlTemplate.ParameterReplace(costAuthorityObligationRequest.PrimaryKey));
 }