示例#1
0
        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});
        }