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 })); }
public IActionResult OptOut(long id, AdminChangeCompaniesHouseOptInOutViewModel viewModel) { var organisation = _adminService.SharedBusinessLogic.DataRepository.Get<Organisation>(id); viewModel.ParseAndValidateParameters(Request, m => m.Reason); if (viewModel.HasAnyErrors()) { viewModel.Organisation = organisation; // If there are any errors, return the user back to the same page to correct the mistakes return View("OptOut", viewModel); } organisation.OptedOutFromCompaniesHouseUpdate = true; _adminService.SharedBusinessLogic.DataRepository.SaveChangesAsync().Wait(); auditLogger.AuditChangeToOrganisation( this, AuditedAction.AdminChangeCompaniesHouseOpting, organisation, new { Opt = "Out", viewModel.Reason }); return RedirectToAction("ViewOrganisation", "AdminViewOrganisation", new {id = organisation.OrganisationId}); }
public IActionResult OptOut(long id) { var organisation = _adminService.SharedBusinessLogic.DataRepository.Get<Organisation>(id); var model = new AdminChangeCompaniesHouseOptInOutViewModel(); model.Organisation = organisation; return View("OptOut", model); }
public IActionResult OptOut(long id) { var organisation = dataRepository.Get <Organisation>(id); var model = new AdminChangeCompaniesHouseOptInOutViewModel(); model.Organisation = organisation; return(View("OptOut", model)); }
public IActionResult OptIn(long id) { Organisation organisation = dataRepository.Get <Organisation>(id); var model = new AdminChangeCompaniesHouseOptInOutViewModel(); model.Organisation = organisation; PopulateViewModelWithCompanyFromCompaniesHouse(model, organisation); return(View("OptIn", model)); }
private void PopulateViewModelWithCompanyFromCompaniesHouse(AdminChangeCompaniesHouseOptInOutViewModel viewModel, Organisation organisation) { CompaniesHouseCompany companiesHouseCompany; try { companiesHouseCompany = companiesHouseApi.GetCompany(organisation.CompanyNumber); } catch (Exception) { throw new Exception("This organisation doesn't have a companies house record."); } viewModel.CompaniesHouseCompany = companiesHouseCompany; }