Beispiel #1
0
        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 ActionResult New(NewGrantViewModel viewModel)
 {
     if (!ModelState.IsValid)
     {
         return ViewNew(viewModel, EditGrantType.NewGrant);
     }
     var grantStatus = HttpRequestStorage.DatabaseEntities.GrantStatuses.Single(g => g.GrantStatusID == viewModel.GrantStatusID);
     var grantOrganization = HttpRequestStorage.DatabaseEntities.Organizations.Single(g => g.OrganizationID == viewModel.OrganizationID);
     var grant = Grant.CreateNewBlank(grantStatus, grantOrganization);
     viewModel.UpdateModel(grant, CurrentPerson);
     SetMessageForDisplay($"{FieldDefinition.Grant.GetFieldDefinitionLabel()} \"{grant.GrantName}\" has been created.");
     return new ModalDialogFormJsonResult();
 }