private PartialViewResult DuplicateGrantViewEdit(DuplicateGrantViewModel viewModel, Grant grantToDuplicate, List<GrantAllocation> grantAllocations) { var grantStatuses = HttpRequestStorage.DatabaseEntities.GrantStatuses; var viewData = new DuplicateGrantViewData(grantStatuses, grantToDuplicate, grantAllocations); return RazorPartialView<DuplicateGrant, DuplicateGrantViewData, DuplicateGrantViewModel>(viewData, viewModel); }
public ActionResult Duplicate(GrantPrimaryKey grantPrimaryKey, DuplicateGrantViewModel viewModel) { var originalGrant = grantPrimaryKey.EntityObject; Check.EnsureNotNull(originalGrant); var initialAwardGrantModificationForCopy = HttpRequestStorage.DatabaseEntities.GrantModifications.Single(gm => gm.GrantModificationID == viewModel.InitialAwardGrantModificationID); if (!ModelState.IsValid) { return(DuplicateGrantViewEdit(viewModel, originalGrant, initialAwardGrantModificationForCopy.GrantAllocations.ToList())); } var grantStatus = HttpRequestStorage.DatabaseEntities.GrantStatuses.Single(gs => gs.GrantStatusID == viewModel.GrantStatusID); var organization = originalGrant.Organization; var newGrant = Grant.CreateNewBlank(grantStatus, organization); viewModel.UpdateModel(newGrant); newGrant.CFDANumber = originalGrant.CFDANumber; newGrant.GrantTypeID = originalGrant.GrantTypeID; var newGrantModification = GrantModification.CreateNewBlank(newGrant, initialAwardGrantModificationForCopy.GrantModificationStatus); newGrantModification.GrantModificationAmount = viewModel.GrantModificationAmount ?? 0; newGrantModification.GrantModificationStartDate = viewModel.GrantStartDate ?? DateTime.Today; newGrantModification.GrantModificationEndDate = viewModel.GrantEndDate ?? DateTime.Today; newGrantModification.GrantModificationName = GrantModificationPurpose.InitialAward.GrantModificationPurposeName; var newGrantModificationPurpose = GrantModificationGrantModificationPurpose.CreateNewBlank(newGrantModification, GrantModificationPurpose.InitialAward); if (viewModel.GrantAllocationsToDuplicate != null && viewModel.GrantAllocationsToDuplicate.Any()) { foreach (var allocationID in viewModel.GrantAllocationsToDuplicate) { var allocationToCopy = HttpRequestStorage.DatabaseEntities.GrantAllocations.Single(ga => ga.GrantAllocationID == allocationID); var newAllocation = GrantAllocation.CreateNewBlank(newGrantModification); newAllocation.GrantAllocationName = allocationToCopy.GrantAllocationName; newAllocation.StartDate = allocationToCopy.StartDate; newAllocation.EndDate = allocationToCopy.EndDate; // 10/7/20 TK - not sure we wanna copy these but going for it anyways newAllocation.FederalFundCodeID = allocationToCopy.FederalFundCodeID; newAllocation.OrganizationID = allocationToCopy.OrganizationID; newAllocation.DNRUplandRegionID = allocationToCopy.DNRUplandRegionID; newAllocation.DivisionID = allocationToCopy.DivisionID; newAllocation.GrantManagerID = allocationToCopy.GrantManagerID; // 10/7/20 TK - make sure we setup the budgetLineItems for the new allocation newAllocation.CreateAllGrantAllocationBudgetLineItemsByCostType(); } } //need to save changes here, because otherwise the MessageForDisplay will link to an item with a negative ID, causing errors HttpRequestStorage.DatabaseEntities.SaveChanges(); SetMessageForDisplay($"{FieldDefinition.Grant.GetFieldDefinitionLabel()} \"{UrlTemplate.MakeHrefString(newGrant.GetDetailUrl(), newGrant.GrantName)}\" has been created."); return(new ModalDialogFormJsonResult()); //return RedirectToAction(new SitkaRoute<GrantController>(gc => gc.GrantDetail(newGrant.GrantID))); }
public PartialViewResult Duplicate(GrantPrimaryKey grantPrimaryKey) { var grantToDuplicate = grantPrimaryKey.EntityObject; Check.EnsureNotNull(grantToDuplicate); //get the grant allocations for the initial award grant mod var grantModifications = grantToDuplicate.GrantModifications; var initialAwardGrantMod = grantModifications.FirstOrDefault(x => x.GrantModificationGrantModificationPurposes.FirstOrDefault(gmp => gmp.GrantModificationPurposeID == GrantModificationPurpose.InitialAward.GrantModificationPurposeID) != null); List<GrantAllocation> grantAllocations = new List<GrantAllocation>(); if (initialAwardGrantMod != null) { grantAllocations = initialAwardGrantMod.GrantAllocations.ToList(); } var viewModel = new DuplicateGrantViewModel(grantToDuplicate, initialAwardGrantMod?.GrantModificationID ?? -1); return DuplicateGrantViewEdit(viewModel, grantToDuplicate, grantAllocations); }