public PartialViewResult New()
        {
            var viewModel = new EditObligationRequestViewModel();
            var projectStatusFirmaPage = FirmaPageTypeEnum.ObligationRequestFromGridDialog.GetFirmaPage();

            return(ViewEdit(viewModel, projectStatusFirmaPage));
        }
        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 PartialViewResult Edit(ObligationRequestPrimaryKey obligationRequestPrimaryKey)
        {
            var obligationRequest      = obligationRequestPrimaryKey.EntityObject;
            var viewModel              = new EditObligationRequestViewModel(obligationRequest);
            var projectStatusFirmaPage = FirmaPageTypeEnum.ObligationRequestFromGridDialog.GetFirmaPage();

            return(ViewEdit(viewModel, projectStatusFirmaPage));
        }
 public ActionResult New(EditObligationRequestViewModel viewModel)
 {
     if (!ModelState.IsValid)
     {
         var firmaPage = FirmaPageTypeEnum.ObligationRequestFromGridDialog.GetFirmaPage();
         return(ViewEdit(viewModel, firmaPage));
     }
     return(MakeTheNewObligationRequest(viewModel));
 }
        private PartialViewResult ViewEdit(EditObligationRequestViewModel viewModel, FirmaPage firmaPage)
        {
            var projectStatusFirmaPage = firmaPage;
            var allAgreements          = HttpRequestStorage.DatabaseEntities.Agreements.ToList();
            var allContractTypes       = HttpRequestStorage.DatabaseEntities.ContractTypes.ToList();
            var allRequestStatuses     = ObligationRequestStatus.All;
            var allFundingPriorities   = ObligationRequestFundingPriority.All;
            var viewData = new EditObligationRequestViewData(projectStatusFirmaPage, CurrentFirmaSession, allAgreements, allContractTypes, allRequestStatuses, allFundingPriorities);

            return(RazorPartialView <EditObligationRequest, EditObligationRequestViewData, EditObligationRequestViewModel>(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());
 }