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 })); }
public IActionResult ChangeScopeGet(long id, int year) { var organisation = dataRepository.Get <Organisation>(id); var currentScopeStatus = organisation.GetScopeStatus(year); var viewModel = new AdminChangeScopeViewModel { OrganisationName = organisation.OrganisationName, OrganisationId = organisation.OrganisationId, ReportingYear = year, CurrentScopeStatus = currentScopeStatus, NewScopeStatus = GetNewScopeStatus(currentScopeStatus) }; return(View("ChangeScope", viewModel)); }