Exemplo n.º 1
0
        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
            });
        }
Exemplo n.º 2
0
        private OrganisationAddress CreateOrganisationAddressFromViewModel(ChangeOrganisationAddressViewModel viewModel)
        {
            var organisationAddress = new OrganisationAddress
            {
                PoBox         = viewModel.PoBox,
                Address1      = viewModel.Address1,
                Address2      = viewModel.Address2,
                Address3      = viewModel.Address3,
                TownCity      = viewModel.TownCity,
                County        = viewModel.County,
                Country       = viewModel.Country,
                PostCode      = viewModel.PostCode,
                Status        = AddressStatuses.Active,
                StatusDate    = VirtualDateTime.Now,
                StatusDetails = viewModel.Reason,
                Modified      = VirtualDateTime.Now,
                Created       = VirtualDateTime.Now,
                Source        = "Service Desk"
            };

            if (viewModel.IsUkAddress.HasValue)
            {
                organisationAddress.IsUkAddress =
                    viewModel.IsUkAddress == ManuallyChangeOrganisationAddressIsUkAddress.Yes;
            }

            return(organisationAddress);
        }
Exemplo n.º 3
0
        private IActionResult OfferNewCompaniesHouseAction(ChangeOrganisationAddressViewModel viewModel,
                                                           Organisation organisation)
        {
            viewModel.ParseAndValidateParameters(Request, m => m.AcceptCompaniesHouseAddress);

            if (viewModel.HasAnyErrors())
            {
                viewModel.Organisation = organisation;
                viewModel.Action       = ManuallyChangeOrganisationAddressViewModelActions.OfferNewCompaniesHouseAddress;
                return(View("OfferNewCompaniesHouseAddress", viewModel));
            }

            if (viewModel.AcceptCompaniesHouseAddress == AcceptCompaniesHouseAddress.Reject)
            {
                return(SendToManualChangePage(organisation));
            }

            viewModel.ParseAndValidateParameters(Request, m => m.Reason);

            if (viewModel.HasAnyErrors())
            {
                viewModel.Organisation = organisation;
                viewModel.Action       = ManuallyChangeOrganisationAddressViewModelActions.OfferNewCompaniesHouseAddress;
                return(View("OfferNewCompaniesHouseAddress", viewModel));
            }

            viewModel.Organisation = organisation;
            viewModel.Action       = ManuallyChangeOrganisationAddressViewModelActions.CheckChangesCoHo;
            return(View("ConfirmAddressChange", viewModel));
        }
Exemplo n.º 4
0
        private IActionResult ManualChangeAction(ChangeOrganisationAddressViewModel viewModel,
                                                 Organisation organisation)
        {
            viewModel.ParseAndValidateParameters(Request, m => m.PoBox);
            viewModel.ParseAndValidateParameters(Request, m => m.Address1);
            viewModel.ParseAndValidateParameters(Request, m => m.Address2);
            viewModel.ParseAndValidateParameters(Request, m => m.Address3);
            viewModel.ParseAndValidateParameters(Request, m => m.TownCity);
            viewModel.ParseAndValidateParameters(Request, m => m.County);
            viewModel.ParseAndValidateParameters(Request, m => m.Country);
            viewModel.ParseAndValidateParameters(Request, m => m.PostCode);
            viewModel.ParseAndValidateParameters(Request, m => m.IsUkAddress);
            viewModel.ParseAndValidateParameters(Request, m => m.Reason);

            if (viewModel.HasAnyErrors())
            {
                viewModel.Organisation = organisation;
                viewModel.Action       = ManuallyChangeOrganisationAddressViewModelActions.ManualChange;
                return(View("ManuallyChangeOrganisationAddress", viewModel));
            }

            viewModel.Organisation = organisation;
            viewModel.Action       = ManuallyChangeOrganisationAddressViewModelActions.CheckChangesManual;
            return(View("ConfirmAddressChange", viewModel));
        }
Exemplo n.º 5
0
        public IActionResult ChangeAddressPost(long id, ChangeOrganisationAddressViewModel viewModel)
        {
            // We might need to change the value of Action before we go to the view
            // Apparently this is necessary
            // https://stackoverflow.com/questions/4837744/hiddenfor-not-getting-correct-value-from-view-model
            ModelState.Clear();

            var organisation = SharedBusinessLogic.DataRepository.Get <Organisation>(id);

            switch (viewModel.Action)
            {
            case ManuallyChangeOrganisationAddressViewModelActions.OfferNewCompaniesHouseAddress:
                return(OfferNewCompaniesHouseAction(viewModel, organisation));

            case ManuallyChangeOrganisationAddressViewModelActions.ManualChange:
                return(ManualChangeAction(viewModel, organisation));

            case ManuallyChangeOrganisationAddressViewModelActions.CheckChangesManual:
            case ManuallyChangeOrganisationAddressViewModelActions.CheckChangesCoHo:
                return(CheckChangesAction(viewModel, organisation));

            default:
                throw new ArgumentException(
                          "Unknown action in AdminOrganisationAddressController.ChangeAddressPost");
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        private IActionResult OfferNewCompaniesHouseAddress(Organisation organisation, OrganisationAddress addressFromCompaniesHouse)
        {
            var viewModel = new ChangeOrganisationAddressViewModel {
                Organisation = organisation,
                Action       = ManuallyChangeOrganisationAddressViewModelActions.OfferNewCompaniesHouseAddress
            };

            viewModel.PopulateFromOrganisationAddress(addressFromCompaniesHouse);

            return(View("OfferNewCompaniesHouseAddress", viewModel));
        }
Exemplo n.º 8
0
        private IActionResult CheckChangesAction(ChangeOrganisationAddressViewModel viewModel, Organisation organisation)
        {
            if (viewModel.Action == ManuallyChangeOrganisationAddressViewModelActions.CheckChangesManual)
            {
                OptOrganisationOutOfCompaniesHouseUpdates(organisation);
            }

            SaveChangesAndAuditAction(viewModel, organisation);

            return(View("SuccessfullyChangedOrganisationAddress", organisation));
        }
Exemplo n.º 9
0
        private IActionResult SendToManualChangePage(Organisation organisation)
        {
            var address = organisation.OrganisationAddresses.OrderByDescending(a => a.Created).First();

            var viewModel = new ChangeOrganisationAddressViewModel
            {
                Organisation = organisation,
                Action       = ManuallyChangeOrganisationAddressViewModelActions.ManualChange
            };

            viewModel.PopulateFromOrganisationAddress(address);

            return(View("ManuallyChangeOrganisationAddress", viewModel));
        }