public IActionResult SaveIsPreviousPrincipalAuthority(IsPreviousPrincipalAuthorityViewModel model)
        {
            Session.SetSubmittedPage(FormSection.DirectorOrPartner, 1);

            if (!ModelState.IsValid || !model.IsPreviousPrincipalAuthority.HasValue)
            {
                return(View(GetViewPath(FormSection.DirectorOrPartner, 1), model));
            }

            var dopId = LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), l => l.DirectorOrPartners, model,
                                                                 Session.GetCurrentDopId());

            Session.SetCurrentDopStatus(dopId, model.IsPreviousPrincipalAuthority.Value);

            if (model.IsPreviousPrincipalAuthority.Value)
            {
                var paId = LicenceApplicationPostDataHandler.UpsertPrincipalAuthorityAndLinkToDirectorOrPartner(
                    Session.GetCurrentLicenceId(), dopId, Session.GetCurrentPaId(), model);
                Session.SetCurrentPaStatus(paId, true);
            }
            else
            {
                LicenceApplicationPostDataHandler.UnlinkPrincipalAuthorityFromDirectorOrPartner(Session.GetCurrentDopId());
            }

            return(CheckParentValidityAndRedirect(FormSection.DirectorOrPartner, 1));
        }
        public IActionResult SubmitApplication(LicenceApplicationViewModel model)
        {
            var licenceId = Session.GetCurrentLicenceId();

            if (!model.AgreedToTermsAndConditions)
            {
                ModelState.AddModelError("AgreedToTermsAndConditions", "You must agree to the terms and conditions in order to submit your application.");

                var dbModel = LicenceApplicationViewModelBuilder.Build(licenceId);
                model.OrganisationDetails = dbModel.OrganisationDetails;
                model.PrincipalAuthority  = dbModel.PrincipalAuthority;
                model.AlternativeBusinessRepresentatives = dbModel.AlternativeBusinessRepresentatives;
                model.DirectorOrPartner = dbModel.DirectorOrPartner;
                model.NamedIndividuals  = dbModel.NamedIndividuals;
                model.Organisation      = dbModel.Organisation;
                return(View("SubmitApplication", model));
            }

            model.NewLicenceStatus = new LicenceStatusViewModel
            {
                Id = ConstantService.ApplicationSubmittedOnlineStatusId
            };

            LicenceApplicationPostDataHandler.Update(licenceId, model);

            return(RedirectToAction("Portal"));
        }
        public void it_should_create_and_update_a_new_entity_if_one_does_not_exist_with_the_specified_id()
        {
            const int    expectedId   = 1;
            const string expectedName = "Name";
            var          licence      = new Licence
            {
                Id = expectedId,
                NamedIndividuals = new List <NamedIndividual>()
            };
            var model = new FullNameViewModel
            {
                FullName = expectedName
            };

            licenceRepository.GetById(expectedId).Returns(licence);
            repository.Create <NamedIndividual>().Returns(new NamedIndividual {
                Id = expectedId
            });
            repository.Upsert(Arg.Any <NamedIndividual>()).Returns(expectedId);

            var pdh    = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);
            var result = pdh.Update(expectedId, l => l.NamedIndividuals, model, expectedId);

            Assert.AreEqual(expectedId, result);
            repository.Received(1).Upsert(Arg.Is <NamedIndividual>(a => a.Id == expectedId && a.FullName.Equals(expectedName)));
        }
        public IActionResult TaskList()
        {
            Session.SetCurrentUserIsAdmin(false);
            Session.ClearCurrentPaStatus();
            Session.ClearCurrentAbrId();
            Session.ClearCurrentDopStatus();

            var licenceId = Session.GetCurrentLicenceId();

            var model = LicenceApplicationViewModelBuilder.Build <LicenceApplicationViewModel>(licenceId);

            if (licenceId == 0)
            {
                Session.SetCurrentLicenceId(LicenceApplicationPostDataHandler.Insert(model));
            }

            //TODO: It's feasible we could access this page with no licenceId where the model will be null
            //TODO: how should we handle this
            model.Declaration?.Validate();
            model.OrganisationDetails?.Validate();
            model.PrincipalAuthority?.Validate();
            model.AlternativeBusinessRepresentatives?.Validate();
            model.DirectorOrPartner?.Validate();
            model.NamedIndividuals?.Validate();
            model.Organisation?.Validate();

            return(View(model));
        }
Beispiel #5
0
        public void it_creates_and_updates_a_new_director_if_one_does_not_exist()
        {
            const int    licenceId    = 1;
            const int    paId         = 2;
            const int    dopId        = 3;
            const string expectedName = "Name";
            var          licence      = new Licence
            {
                Id = licenceId,
                DirectorOrPartners = new List <DirectorOrPartner>()
            };
            var model = new FullNameViewModel {
                FullName = expectedName
            };

            licenceRepository.GetById(licenceId).Returns(licence);
            repository.GetById <PrincipalAuthority>(paId).Returns(new PrincipalAuthority {
                Id = paId
            });
            repository.Create <DirectorOrPartner>().Returns(new DirectorOrPartner {
                Id = dopId
            });
            repository.Upsert(Arg.Any <DirectorOrPartner>()).Returns(dopId);

            var pdh    = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);
            var result = pdh.UpsertDirectorOrPartnerAndLinkToPrincipalAuthority(licenceId, paId, dopId, model);

            Assert.AreEqual(dopId, result);
            repository.Received(1).Upsert(Arg.Is <DirectorOrPartner>(p => p.FullName.Equals(expectedName) && p.PrincipalAuthority.Id == paId && p.Licence.Id == licenceId));
            repository.Received(1).Create <DirectorOrPartner>();
            repository.Received(1).GetById <PrincipalAuthority>(paId);
        }
        public void it_should_create_a_new_address_entity_if_one_is_not_present_and_update_the_address_from_the_address_view_model()
        {
            const int    expectedId       = 1;
            const string expectedLine1    = "Line 1";
            const int    expectedCounty   = 1;
            const int    expectedCountry  = 1;
            const string expectedPostcode = "BA2 3DQ";
            var          licence          = new Licence {
                Id = expectedId, Address = null
            };
            var model = new AddressViewModel
            {
                AddressLine1 = expectedLine1,
                CountyId     = expectedCounty,
                CountryId    = expectedCountry,
                Postcode     = expectedPostcode
            };

            licenceRepository.GetById(expectedId).Returns(licence);
            repository.Create <Address>().Returns(new Address());

            var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);

            pdh.UpdateAddress(expectedId, l => l, model);

            repository.Received(1).Create <Address>();
            repository.Received(1).Upsert(Arg.Is <Licence>(l =>
                                                           l.Address.AddressLine1.Equals(expectedLine1) && l.Address.CountyId == expectedCounty &&
                                                           l.Address.CountryId == expectedCountry && l.Address.Postcode.Equals(expectedPostcode)));
        }
        public void it_should_create_and_update_a_new_entity_with_an_address_if_one_does_not_exist_with_the_specified_id_and_it_is_addressable()
        {
            const int    expectedId   = 1;
            const string expectedName = "Name";
            var          licence      = new Licence
            {
                Id = expectedId,
                DirectorOrPartners = new List <DirectorOrPartner>()
            };
            var model = new FullNameViewModel
            {
                FullName = expectedName
            };

            licenceRepository.GetById(expectedId).Returns(licence);
            repository.Create <DirectorOrPartner>().Returns(new DirectorOrPartner {
                Id = expectedId
            });
            repository.Create <Address>().Returns(new Address {
                Id = expectedId
            });
            repository.Upsert(Arg.Any <DirectorOrPartner>()).Returns(expectedId);

            var pdh    = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);
            var result = pdh.Update(expectedId, l => l.DirectorOrPartners, model, expectedId);

            Assert.AreEqual(expectedId, result);
            repository.Received(1).Create <Address>();
            repository.Received(1).Upsert(Arg.Is <DirectorOrPartner>(a => a.Id == expectedId && a.FullName.Equals(expectedName) && a.Address.Id == expectedId));
        }
        public void it_should_update_an_entity_in_a_collection_by_its_id()
        {
            const int    expectedId   = 1;
            const string expectedName = "Name";
            var          licence      = new Licence
            {
                Id = expectedId,
                NamedIndividuals = new List <NamedIndividual>
                {
                    new NamedIndividual
                    {
                        Id       = expectedId,
                        FullName = string.Empty
                    }
                }
            };
            var model = new FullNameViewModel
            {
                FullName = expectedName
            };

            licenceRepository.GetById(expectedId).Returns(licence);
            repository.Upsert(Arg.Any <NamedIndividual>()).Returns(expectedId);

            var pdh    = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);
            var result = pdh.Update(expectedId, l => l.NamedIndividuals, model, expectedId);

            Assert.AreEqual(expectedId, result);
            repository.Received(1).Upsert(Arg.Is <NamedIndividual>(a => a.Id == expectedId && a.FullName.Equals(expectedName)));
        }
        public IActionResult RemovePreviousTradingName(PreviousTradingNameViewModel model, string section, int id)
        {
            LicenceApplicationPostDataHandler.Delete <PreviousTradingName>(id);

            var lastLoaded = Session.GetLoadedPage();

            return(RedirectToAction(section, lastLoaded));
        }
        public IActionResult RemoveOffenceAwaitingTrial(OffenceAwaitingTrialViewModel model, FormSection section, int id)
        {
            LicenceApplicationPostDataHandler.Delete <OffenceAwaitingTrial>(id);

            var lastLoaded = Session.GetLoadedPage();

            return(RedirectToAction(section, lastLoaded));
        }
        public IActionResult RemoveConviction(UnspentConvictionViewModel model, FormSection section, int id)
        {
            LicenceApplicationPostDataHandler.Delete <Conviction>(id);

            var lastLoaded = Session.GetLoadedPage();

            return(RedirectToAction(section, lastLoaded));
        }
        public IActionResult RemoveRestraintOrder(RestraintOrderViewModel model, FormSection section, int id)
        {
            LicenceApplicationPostDataHandler.Delete <RestraintOrder>(id);

            var lastLoaded = Session.GetLoadedPage();

            return(RedirectToAction(section, lastLoaded));
        }
        public IActionResult DeleteNamedJobTitle(NamedJobTitleViewModel model)
        {
            var id = Session.GetCurrentNamedIndividualId();

            LicenceApplicationPostDataHandler.Delete <NamedJobTitle>(id);

            return(RedirectToLastAction(FormSection.NamedIndividuals));
        }
Beispiel #14
0
        public IActionResult DeleteAlternativeBusinessRepresentative(AlternativeBusinessRepresentativeViewModel model)
        {
            var id = Session.GetCurrentAbrId();

            LicenceApplicationPostDataHandler.Delete <AlternativeBusinessRepresentative>(id);

            return(RedirectToLastAction(FormSection.AlternativeBusinessRepresentatives));
        }
        public IActionResult DeleteDirectorOrPartner(DirectorOrPartnerViewModel model)
        {
            LicenceApplicationPostDataHandler.Delete <DirectorOrPartner>(Session.GetCurrentDopId());

            if (Session.GetCurrentDopIsPa())
            {
                LicenceApplicationPostDataHandler.Delete <PrincipalAuthority>(Session.GetCurrentPaId());
            }

            return(RedirectToLastAction(FormSection.DirectorsOrPartners));
        }
        public IActionResult AddPreviousTradingName(PreviousTradingNameViewModel model, FormSection section, int id)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("AddPreviousTradingName", new { section, id }));
            }

            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), l => l.PreviousTradingNames, model, model.Id);

            var lastLoaded = Session.GetLoadedPage();

            return(RedirectToAction(section, lastLoaded));
        }
        public IActionResult SaveMultipleBranch(MultipleBranchViewModel model)
        {
            Session.SetSubmittedPage(FormSection.Organisation, 5);

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.Organisation, 5), model));
            }

            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x, model);
            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x.SelectedMultiples, model.SelectedMultiples);

            return(CheckParentValidityAndRedirect(FormSection.Organisation, 5));
        }
        public IActionResult OperatingCountries(OperatingCountriesViewModel model)
        {
            Session.SetSubmittedPage(FormSection.OrganisationDetails, nameof(OperatingCountries));

            if (!ModelState.IsValid)
            {
                return(View(nameof(OperatingCountries), model));
            }

            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x.OperatingCountries,
                                                     model.OperatingCountries);

            return(CheckParentValidityAndRedirect(FormSection.OrganisationDetails, nameof(OperatingCountries)));
        }
Beispiel #19
0
        public IActionResult SaveAddress(AddressViewModel model)
        {
            Session.SetSubmittedPage(FormSection.AlternativeBusinessRepresentative, 6);

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.AlternativeBusinessRepresentative, 6), model));
            }

            LicenceApplicationPostDataHandler.UpdateAddress(Session.GetCurrentLicenceId(),
                                                            x => x.AlternativeBusinessRepresentatives.Single(abr => abr.Id == Session.GetCurrentAbrId()), model);

            return(CheckParentValidityAndRedirect(FormSection.AlternativeBusinessRepresentative, 6));
        }
        public IActionResult SaveNamedIndividuals(NamedIndividualCollectionViewModel model)
        {
            Session.SetSubmittedPage(FormSection.NamedIndividuals, 2);

            model = RepopulateDropdowns(model);

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.NamedIndividuals, 2), model));
            }

            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x, model);

            return(RedirectToAction(FormSection.NamedIndividuals, 3));
        }
        private IActionResult OrganisationPost <T>(T model, int submittedPageId)
        {
            Session.SetSubmittedPage(FormSection.Organisation, submittedPageId);

            model = RepopulateDropdowns(model);

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.Organisation, submittedPageId), model));
            }

            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x, model);

            return(CheckParentValidityAndRedirect(FormSection.Organisation, submittedPageId));
        }
        public IActionResult SaveOutsideSectors(OutsideSectorsViewModel model)
        {
            Session.SetSubmittedPage(FormSection.Organisation, 2);

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.Organisation, 2), model));
            }

            // update the non collection part
            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x, model);
            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x.SelectedSectors, model.SelectedSectors);

            return(CheckParentValidityAndRedirect(FormSection.Organisation, 2));
        }
Beispiel #23
0
        public void it_unlinks_the_principal_authority_from_a_director()
        {
            const int dopId = 1;
            var       dop   = new DirectorOrPartner {
                Id = dopId, PrincipalAuthority = new PrincipalAuthority()
            };

            repository.GetById <DirectorOrPartner>(dopId).Returns(dop);

            var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);

            pdh.UnlinkPrincipalAuthorityFromDirectorOrPartner(dopId);

            repository.Received(1).Upsert(Arg.Is <DirectorOrPartner>(d => d.PrincipalAuthority == null));
        }
Beispiel #24
0
        public void it_unlinks_a_director_from_the_principal_authority()
        {
            const int paId = 1;
            var       pa   = new PrincipalAuthority {
                Id = paId, DirectorOrPartner = new DirectorOrPartner()
            };

            repository.GetById <PrincipalAuthority>(paId).Returns(pa);

            var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);

            pdh.UnlinkDirectorOrPartnerFromPrincipalAuthority(paId);

            repository.Received(1).Upsert(Arg.Is <PrincipalAuthority>(d => d.DirectorOrPartner == null));
        }
Beispiel #25
0
        public IActionResult SaveAlternativeBusinessRepresentatives(AlternativeBusinessRepresentativeCollectionViewModel model)
        {
            Session.SetSubmittedPage(FormSection.AlternativeBusinessRepresentatives, 2);

            model = RepopulateDropdowns(model);

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.AlternativeBusinessRepresentatives, 2), model));
            }

            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x, model);

            return(RedirectToAction(FormSection.AlternativeBusinessRepresentatives, 3));
        }
        public IActionResult BusinessCredentials(BusinessCredentialsViewModel model)
        {
            Session.SetSubmittedPage(FormSection.OrganisationDetails, nameof(BusinessCredentials));

            if (!ModelState.IsValid)
            {
                return(View(nameof(BusinessCredentials), model));
            }

            var licenceId = Session.GetCurrentLicenceId();

            LicenceApplicationPostDataHandler.Update(licenceId, x => x, model);
            LicenceApplicationPostDataHandler.UpdateAll(licenceId, x => x.PAYENumbers, model.PAYEStatusViewModel.PAYENumbers);

            return(CheckParentValidityAndRedirect(FormSection.OrganisationDetails, nameof(BusinessCredentials)));
        }
Beispiel #27
0
        private IActionResult NamedIndividualPost <T>(T model, int submittedPageId, Func <T, bool> modelIsInvalid)
        {
            Session.SetSubmittedPage(FormSection.NamedIndividual, submittedPageId);

            model = RepopulateDropdowns(model);

            if (modelIsInvalid(model))
            {
                return(View(GetViewPath(FormSection.NamedIndividual, submittedPageId), model));
            }

            var id = LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x.NamedIndividuals, model, Session.GetCurrentNamedIndividualId());

            Session.SetCurrentNamedIndividualId(id);

            return(CheckParentValidityAndRedirect(FormSection.NamedIndividual, submittedPageId));
        }
        public IActionResult SaveJobTitle(NamedJobTitleViewModel model)
        {
            Session.SetSubmittedPage(FormSection.JobTitle, 1);

            model = RepopulateDropdowns(model);

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.JobTitle, 1), model));
            }

            var id = LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x.NamedJobTitles, model, Session.GetCurrentNamedIndividualId());

            Session.SetCurrentNamedIndividualId(id);

            return(RedirectToAction(FormSection.JobTitle, 2));
        }
        public void it_should_not_add_a_checked_item_to_the_entity_from_the_model_if_it_is_already_present()
        {
            const int    expectedId   = 1;
            const string expectedName = "Name";
            var          licence      = new Licence
            {
                Id = expectedId,
                OperatingIndustries = new List <LicenceIndustry>
                {
                    new LicenceIndustry
                    {
                        LicenceId  = expectedId,
                        IndustryId = expectedId,
                        Industry   = new Industry
                        {
                            Id   = expectedId,
                            Name = expectedName
                        }
                    }
                }
            };
            var model = new OperatingIndustriesViewModel
            {
                OperatingIndustries = new List <CheckboxListItem>
                {
                    new CheckboxListItem {
                        Id = expectedId, Name = expectedName, Checked = true
                    }
                }
            };

            licenceRepository.GetById(expectedId).Returns(licence);
            repository.GetById <Industry>(expectedId).Returns(new Industry {
                Id = expectedId, Name = expectedName
            });

            var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);

            pdh.Update(expectedId, l => l.OperatingIndustries, model.OperatingIndustries);

            repository.Received(1).Upsert(Arg.Is <Licence>(l =>
                                                           l.OperatingIndustries.Single().Id == expectedId &&
                                                           l.OperatingIndustries.Single().IndustryId == expectedId &&
                                                           l.OperatingIndustries.Single().Industry.Name.Equals(expectedName)));
        }
        public IActionResult SaveAddress(AddressViewModel model)
        {
            Session.SetSubmittedPage(FormSection.DirectorOrPartner, 8);

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.DirectorOrPartner, 8), model));
            }

            if (Session.GetCurrentDopIsPa())
            {
                LicenceApplicationPostDataHandler.UpdateAddress(Session.GetCurrentLicenceId(), l => l.PrincipalAuthorities.Single(pa => pa.Id == Session.GetCurrentPaId()), model);
            }

            LicenceApplicationPostDataHandler.UpdateAddress(Session.GetCurrentLicenceId(), l => l.DirectorOrPartners.Single(dop => dop.Id == Session.GetCurrentDopId()), model);

            return(CheckParentValidityAndRedirect(FormSection.DirectorOrPartner, 8));
        }