public IActionResult OptIn(long id, AdminChangeCompaniesHouseOptInOutViewModel viewModel) { var organisation = dataRepository.Get <Organisation>(id); viewModel.ParseAndValidateParameters(Request, m => m.Reason); if (viewModel.HasAnyErrors()) { viewModel.Organisation = organisation; PopulateViewModelWithCompanyFromCompaniesHouse(viewModel, organisation); // If there are any errors, return the user back to the same page to correct the mistakes return(View("OptIn", viewModel)); } updateFromCompaniesHouseService.UpdateOrganisationDetails(organisation.OrganisationId); organisation.OptedOutFromCompaniesHouseUpdate = false; dataRepository.SaveChanges(); auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeCompaniesHouseOpting, organisation, new { Opt = "In", Reason = viewModel.Reason }, User); return(RedirectToAction("ViewOrganisation", "AdminViewOrganisation", new { id = organisation.OrganisationId })); }
private IActionResult Remove(Organisation organisation, AdminOrganisationCompanyNumberViewModel viewModel) { viewModel.ParseAndValidateParameters(Request, m => m.Reason); if (viewModel.HasAnyErrors()) { viewModel.Organisation = organisation; return(View("RemoveOrganisationCompanyNumber", viewModel)); } auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeOrganisationCompanyNumber, organisation, new { OldCompanyNumber = organisation.CompanyNumber, NewCompanyNumber = "(removed)", Reason = viewModel.Reason }, User ); organisation.CompanyNumber = null; dataRepository.SaveChanges(); return(RedirectToAction("ViewOrganisation", "AdminViewOrganisation", new { id = organisation.OrganisationId })); }
public void RemoveRetiredUserRegistrations(User userToRetire) { // We extract this list of Organisations BEFORE deleting the UserOrganisations to prevent an Entity Framework error: // "Attempted to update or delete an entity that does not exist in the store." List <Organisation> organisationsToAuditLog = userToRetire.UserOrganisations .Select(userOrg => userOrg.Organisation) .ToList(); foreach (UserOrganisation userOrgToUnregister in userToRetire.UserOrganisations) { // remove all the user registrations associated with the organisation userOrgToUnregister.Organisation.UserOrganisations.Remove(userOrgToUnregister); // Remove user organisation dataRepository.Delete(userOrgToUnregister); } foreach (Organisation organisation in organisationsToAuditLog) { // log unregistered via closed account auditLogger.AuditChangeToOrganisation( AuditedAction.RegistrationLog, organisation, new { Status = "Unregistered closed account" }, userToRetire); } // save changes to database dataRepository.SaveChanges(); }
private void SaveChangesAndAuditAction(ChangeOrganisationAddressViewModel viewModel, Organisation organisation) { var oldAddressString = organisation.GetLatestAddress()?.GetAddressString(); RetireOldAddress(organisation); var newOrganisationAddress = CreateOrganisationAddressFromViewModel(viewModel); AddNewAddressToOrganisation(newOrganisationAddress, organisation); SharedBusinessLogic.DataRepository.SaveChangesAsync().Wait(); auditLogger.AuditChangeToOrganisation( this, AuditedAction.AdminChangeOrganisationAddress, organisation, new { viewModel.Action, OldAddress = oldAddressString, NewAddress = newOrganisationAddress.GetAddressString(), NewAddressId = newOrganisationAddress.AddressId, viewModel.Reason }); }
private void SaveChangesAndAuditAction(ChangeOrganisationAddressViewModel viewModel, Organisation organisation) { string oldAddressString = organisation.GetLatestAddress().GetAddressString(); RetireOldAddress(organisation); OrganisationAddress newOrganisationAddress = CreateOrganisationAddressFromViewModel(viewModel); AddNewAddressToOrganisation(newOrganisationAddress, organisation); dataRepository.SaveChanges(); auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeOrganisationAddress, organisation, new { Action = viewModel.Action, OldAddress = oldAddressString, NewAddress = newOrganisationAddress.GetAddressString(), NewAddressId = newOrganisationAddress.AddressId, Reason = viewModel.Reason }, User); }
private void AuditChange( AdminChangePublicSectorClassificationViewModel viewModel, Organisation organisation, PublicSectorType newPublicSectorType) { auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeOrganisationPublicSectorClassification, organisation, new { OldClassification = organisation.LatestPublicSectorType?.PublicSectorType?.Description, NewClassification = newPublicSectorType.Description, viewModel.Reason }, User); }
private void ChangeStatus(AdminChangeStatusViewModel viewModel, long organisationId) { var organisation = dataRepository.Get <Organisation>(organisationId); User currentUser = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository); OrganisationStatuses previousStatus = organisation.Status; OrganisationStatuses newStatus = viewModel.NewStatus ?? OrganisationStatuses.Unknown; // Update the status organisation.SetStatus( newStatus, currentUser.UserId, viewModel.Reason); // [In]Activate users of the organisation if (newStatus == OrganisationStatuses.Active) { ActivateUsersOfOrganisation(organisation); } if (previousStatus == OrganisationStatuses.Active) { InactivateUsersOfOrganisation(organisation); } dataRepository.SaveChanges(); // Audit log auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeOrganisationStatus, organisation, new { PreviousStatus = previousStatus, NewStatus = newStatus, viewModel.Reason }, User); }
private void PurgeOrganisation(Organisation org) { EmployerSearchModel searchRecord = org.ToEmployerSearchResult(true); auditLogger.AuditChangeToOrganisation( AuditedAction.PurgeOrganisation, org, new { org.OrganisationId, Address = org.GetLatestAddress()?.GetAddressString(), org.EmployerReference, org.CompanyNumber, org.OrganisationName, org.SectorType, org.Status, SicCodes = org.GetSicSectionIdsString(), SicSource = org.GetSicSource(), org.DateOfCessation }); // Un-register all users for this Organisation org.UserOrganisations.ForEach(uo => dataRepository.Delete(uo)); // Soft-Delete the Organisation org.SetStatus(OrganisationStatuses.Deleted, details: "Organisation deleted by PurgeOrganisationJob"); dataRepository.SaveChanges(); }
public IActionResult ChangeScopePost(long id, int year, AdminChangeScopeViewModel viewModel) { var organisation = dataRepository.Get <Organisation>(id); var currentOrganisationScope = organisation.GetScopeForYear(year); if (currentOrganisationScope.ScopeStatus != ScopeStatuses.InScope && currentOrganisationScope.ScopeStatus != ScopeStatuses.OutOfScope) { viewModel.ParseAndValidateParameters(Request, m => m.NewScopeStatus); } viewModel.ParseAndValidateParameters(Request, m => m.Reason); if (viewModel.HasAnyErrors()) { // If there are any errors, return the user back to the same page to correct the mistakes var currentScopeStatus = organisation.GetScopeStatus(year); viewModel.OrganisationName = organisation.OrganisationName; viewModel.OrganisationId = organisation.OrganisationId; viewModel.ReportingYear = year; viewModel.CurrentScopeStatus = currentScopeStatus; return(View("ChangeScope", viewModel)); } RetireOldScopesForCurrentSnapshotDate(organisation, year); ScopeStatuses newScope = ConvertNewScopeStatusToScopeStatus(viewModel.NewScopeStatus); var newOrganisationScope = new OrganisationScope { Organisation = organisation, ScopeStatus = newScope, ScopeStatusDate = VirtualDateTime.Now, ContactFirstname = currentOrganisationScope.ContactFirstname, ContactLastname = currentOrganisationScope.ContactLastname, ContactEmailAddress = currentOrganisationScope.ContactEmailAddress, Reason = viewModel.Reason, SnapshotDate = currentOrganisationScope.SnapshotDate, StatusDetails = "Changed by Admin", Status = ScopeRowStatuses.Active }; dataRepository.Insert(newOrganisationScope); dataRepository.SaveChanges(); auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeOrganisationScope, organisation, new { PreviousScope = currentOrganisationScope.ScopeStatus.ToString(), NewScope = newScope.ToString(), Reason = viewModel.Reason }, User); return(RedirectToAction("ViewScopeHistory", "AdminOrganisationScope", new { id = organisation.OrganisationId })); }
private void SaveChangesAndAuditAction(ChangeOrganisationNameViewModel viewModel, Organisation organisation) { string oldName = organisation.OrganisationName; OrganisationName newOrganisationName = CreateOrganisationNameFromViewModel(viewModel); AddNewNameToOrganisation(newOrganisationName, organisation); dataRepository.SaveChanges(); auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeOrganisationName, organisation, new { Action = viewModel.Action, OldName = oldName, NewName = newOrganisationName.Name, NewNameId = newOrganisationName.OrganisationNameId, Reason = viewModel.Reason }, User); }
public IActionResult DeleteReturnsPost(long id, int year, AdminDeleteReturnViewModel viewModel) { var organisation = dataRepository.Get <Organisation>(id); User currentUser = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository); viewModel.ParseAndValidateParameters(Request, m => m.Reason); if (viewModel.HasAnyErrors()) { viewModel.Organisation = organisation; viewModel.Year = year; return(View("DeleteReturns", viewModel)); } foreach (long returnId in viewModel.ReturnIds) { if (!organisation.Returns.Select(r => r.ReturnId).Contains(returnId)) { throw new Exception("The ReturnID that the user requested to be deleted does not belong to this Organisation"); } } foreach (long returnId in viewModel.ReturnIds) { dataRepository.Get <Return>(returnId).SetStatus(ReturnStatuses.Deleted, currentUser.UserId, viewModel.Reason); } // Audit log auditLogger.AuditChangeToOrganisation( AuditedAction.AdminDeleteReturn, organisation, new { ReportingYear = year, ReturnIds = string.Join(", ", viewModel.ReturnIds), Reason = viewModel.Reason }, User); return(RedirectToAction("ViewReturns", "AdminOrganisationReturn", new { id })); }
private void SaveChangesAndAuditAction(ChangeOrganisationNameViewModel viewModel, Organisation organisation) { var oldName = organisation.OrganisationName; var newOrganisationName = CreateOrganisationNameFromViewModel(viewModel); AddNewNameToOrganisation(newOrganisationName, organisation); SharedBusinessLogic.DataRepository.SaveChangesAsync().Wait(); auditLogger.AuditChangeToOrganisation( this, AuditedAction.AdminChangeOrganisationName, organisation, new { viewModel.Action, OldName = oldName, NewName = newOrganisationName.Name, NewNameId = newOrganisationName.OrganisationNameId, viewModel.Reason }); }
private void SaveChangesAndAuditAction(ChangeOrganisationSicCodesViewModel viewModel, Organisation organisation) { string oldSicCodes = organisation.GetSicCodeIdsString(); RemoveSicCodes(viewModel, organisation); AddSicCodes(viewModel, organisation); dataRepository.SaveChanges(); string newSicCodes = organisation.GetSicCodeIdsString(); auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeOrganisationSicCode, organisation, new { Action = viewModel.Action, OldSicCodes = oldSicCodes, NewSicCodes = newSicCodes, Reason = viewModel.Reason }, User); }
private void SaveChangesAndAuditAction(ChangeOrganisationSicCodesViewModel viewModel, Organisation organisation) { var oldSicCodes = organisation.GetLatestSicCodeIdsString(); RemoveSicCodes(viewModel, organisation); AddSicCodes(viewModel, organisation); SharedBusinessLogic.DataRepository.SaveChangesAsync().Wait(); var newSicCodes = organisation.GetLatestSicCodeIdsString(); auditLogger.AuditChangeToOrganisation( this, AuditedAction.AdminChangeOrganisationSicCode, organisation, new { viewModel.Action, OldSicCodes = oldSicCodes, NewSicCodes = newSicCodes, viewModel.Reason }); }
public IActionResult ChangeLateFlag(long id, AdminReturnLateFlagViewModel viewModel) { var specifiedReturn = _adminService.SharedBusinessLogic.DataRepository.Get <Return>(id); viewModel.ParseAndValidateParameters(Request, m => m.Reason); if (viewModel.HasAnyErrors()) { viewModel.Return = specifiedReturn; // If there are any errors, return the user back to the same page to correct the mistakes return(View("ChangeLateFlag", viewModel)); } if (viewModel.NewLateFlag is null) { throw new ArgumentNullException(nameof(viewModel.NewLateFlag)); } specifiedReturn.IsLateSubmission = viewModel.NewLateFlag.Value; _adminService.SharedBusinessLogic.DataRepository.SaveChangesAsync().Wait(); auditLogger.AuditChangeToOrganisation( this, AuditedAction.AdminChangeLateFlag, specifiedReturn.Organisation, new { ReturnId = id, LateFlagChangedTo = viewModel.NewLateFlag, viewModel.Reason }); return(RedirectToAction("ViewOrganisation", "AdminViewOrganisation", new { id = specifiedReturn.OrganisationId })); }
private IActionResult UnlinkUserAndOrganisationPost( long organisationId, long userId, AdminRemoveUserViewModel viewModel, bool fromViewUserPage) { UpdateAdminRemoveUserViewModelFromUserOrganisation(viewModel, organisationId, userId); viewModel.FromViewUserPage = fromViewUserPage; viewModel.ParseAndValidateParameters(Request, m => m.Reason); if (viewModel.HasAnyErrors()) { // If there are any errors, return the user back to the same page to correct the mistakes return(View("ConfirmRemoving", viewModel)); } var user = dataRepository.Get <User>(viewModel.UserId); var organisation = dataRepository.Get <Organisation>(viewModel.OrganisationId); // Remove user organisation UserOrganisation userOrg = dataRepository.GetAll <UserOrganisation>() .Where(u => u.UserId == viewModel.UserId) .Where(u => u.OrganisationId == viewModel.OrganisationId) .FirstOrDefault(); dataRepository.Delete(userOrg); dataRepository.SaveChanges(); // Email user that has been unregistered emailSendingService.SendRemovedUserFromOrganisationEmail( user.EmailAddress, organisation.OrganisationName, user.Fullname); // Email the other users of the organisation IEnumerable <string> emailAddressesForOrganisation = organisation.UserOrganisations.Select(uo => uo.User.EmailAddress); foreach (string emailAddress in emailAddressesForOrganisation) { emailSendingService.SendRemovedUserFromOrganisationEmail( emailAddress, organisation.OrganisationName, user.Fullname); } // Send the notification to GEO for each newly orphaned organisation if (organisation.GetIsOrphan()) { emailSendingService.SendGeoOrphanOrganisationEmail(organisation.OrganisationName); } // Audit log auditLogger.AuditChangeToOrganisation( AuditedAction.AdminRemoveUserFromOrganisation, organisation, new { RemovedUserId = user.UserId, viewModel.Reason }, User); return(View("SuccessfullyRemoved", viewModel)); }