private PartialViewResult ViewDeleteGrantAllocationFile(GrantAllocationFileResource grantAllocationFileResource, ConfirmDialogFormViewModel viewModel) { var confirmMessage = $"Are you sure you want to delete this \"{grantAllocationFileResource.DisplayName}\" file created on '{grantAllocationFileResource.FileResource.CreateDate}' by '{grantAllocationFileResource.FileResource.CreatePerson.FullNameFirstLast}'?"; var viewData = new ConfirmDialogFormViewData(confirmMessage, true); return(RazorPartialView <ConfirmDialogForm, ConfirmDialogFormViewData, ConfirmDialogFormViewModel>(viewData, viewModel)); }
public void UpdateModel(Models.GrantAllocation grantAllocation, Person currentPerson) { grantAllocation.GrantAllocationName = GrantAllocationName; grantAllocation.OrganizationID = OrganizationID; //grantAllocation.GrantID = GrantID; grantAllocation.FederalFundCodeID = FederalFundCodeID; grantAllocation.DivisionID = DivisionID; grantAllocation.DNRUplandRegionID = DNRUplandRegionID; if (grantAllocation.AllocationAmount != AllocationAmount) { GrantAllocationChangeLog newChange = new GrantAllocationChangeLog( grantAllocation, currentPerson, DateTime.Now ); newChange.GrantAllocationAmountOldValue = grantAllocation.AllocationAmount; newChange.GrantAllocationAmountNewValue = AllocationAmount; newChange.GrantAllocationAmountNote = GrantAllocationChangeLogNote; } grantAllocation.AllocationAmount = AllocationAmount; grantAllocation.StartDate = StartDate; grantAllocation.EndDate = EndDate; grantAllocation.GrantManagerID = GrantManagerID; // Who is actually allowed to be a Program Manager for this Grant Allocation? List <Person> personsAllowedToBeProgramManager = new List <Person>(); // Anyone who CURRENTLY has the role can keep it, even if their Person record has lost the permission in the meantime personsAllowedToBeProgramManager.AddRange(grantAllocation.GrantAllocationProgramManagers.Select(pm => pm.Person).ToList()); // Also, anyone who has the right in the database is allowed personsAllowedToBeProgramManager.AddRange(HttpRequestStorage.DatabaseEntities.People.ToList().Where(p => p.IsProgramManager == true).ToList()); personsAllowedToBeProgramManager = personsAllowedToBeProgramManager.Distinct().ToList(); var personIDsAllowedToBeProgramManager = personsAllowedToBeProgramManager.Select(papm => papm.PersonID).ToList(); var personIDsNotAllowed = new List <int>(); if (this.ProgramManagerPersonIDs != null) { personIDsNotAllowed = this.ProgramManagerPersonIDs.Except(personIDsAllowedToBeProgramManager).ToList(); } Check.Ensure(!personIDsNotAllowed.Any(), $"Found {personIDsNotAllowed.Count} PersonIDs not allowed to be Program Managers attempting to be saved: {string.Join(", ", personIDsNotAllowed)}"); // Deleting existing records grantAllocation.GrantAllocationProgramManagers.ToList().ForEach(gapm => gapm.DeleteFull(HttpRequestStorage.DatabaseEntities)); grantAllocation.GrantAllocationProgramManagers = this.ProgramManagerPersonIDs != null?this.ProgramManagerPersonIDs.Select(p => new GrantAllocationProgramManager(grantAllocation.GrantAllocationID, p)).ToList() : new List <GrantAllocationProgramManager>(); if (GrantAllocationFileResourceDatas?[0] != null) { var fileResources = GrantAllocationFileResourceDatas.Select(fileData => FileResource.CreateNewFromHttpPostedFile(fileData, currentPerson)); foreach (var fileResource in fileResources) { HttpRequestStorage.DatabaseEntities.FileResources.Add(fileResource); var grantAllocationFileResource = new GrantAllocationFileResource(grantAllocation, fileResource, fileResource.OriginalCompleteFileName); grantAllocation.GrantAllocationFileResources.Add(grantAllocationFileResource); } } //delete existing GrantAllocationProgramIndexProjectCode records grantAllocation.GrantAllocationProgramIndexProjectCodes.ToList().ForEach(gapipc => gapipc.DeleteFull(HttpRequestStorage.DatabaseEntities)); //create new rows of GrantAllocationProgramIndexProjectCode grantAllocation.GrantAllocationProgramIndexProjectCodes = ProgramIndexProjectCodeJsons.Where(gapipc => gapipc.ProgramIndexID != null).Select(gapipc => new GrantAllocationProgramIndexProjectCode(grantAllocation.GrantAllocationID, (int)gapipc.ProgramIndexID, gapipc.ProjectCodeID)).ToList(); }