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()); }