Esempio n. 1
0
        public virtual async Task <OrchestratorResponse <OrganisationDetailsViewModel> > ValidateLegalEntityName(
            OrganisationDetailsViewModel request)
        {
            var response = new OrchestratorResponse <OrganisationDetailsViewModel>
            {
                Data = request
            };

            var validator        = new OrganisationDetailsViewModelValidator();
            var validationResult = await validator.ValidateAsync(request);

            if (!validationResult.IsValid)
            {
                response.Data.ErrorDictionary = new Dictionary <string, string>();
                foreach (var validationError in validationResult.Errors)
                {
                    response.Data.ErrorDictionary.Add(validationError.PropertyName, validationError.ErrorMessage);
                }

                response.Status = HttpStatusCode.BadRequest;

                response.FlashMessage = new FlashMessageViewModel
                {
                    Headline      = "Errors to fix",
                    Message       = "Check the following details:",
                    Severity      = FlashMessageSeverityLevel.Error,
                    ErrorMessages = response.Data.ErrorDictionary
                };
            }

            return(response);
        }
Esempio n. 2
0
        public async Task ThenTheNameIsMandatory()
        {
            var request = new OrganisationDetailsViewModel();
            var result  = await _orchestrator.ValidateLegalEntityName(request);

            Assert.IsFalse(result.Data.Valid);
            Assert.IsTrue(result.Data.ErrorDictionary.ContainsKey("Name"));
        }
        private ActionResult FindAddress(string hashedAccountId, OrganisationDetailsViewModel organisation)
        {
            var addressViewModel = _mapper.Map <FindOrganisationAddressViewModel>(organisation);
            var response         = new OrchestratorResponse <FindOrganisationAddressViewModel> {
                Data = addressViewModel
            };

            return(View(ControllerConstants.FindAddressViewName, response));
        }
 public AdminLicenceViewModel()
 {
     Licence             = new LicenceApplicationViewModel();
     OrganisationDetails = new OrganisationDetailsViewModel();
     PrincipalAuthority  = new PrincipalAuthorityViewModel();
     AlternativeBusinessRepresentatives = new AlternativeBusinessRepresentativeCollectionViewModel();
     DirectorsOrPartners = new DirectorOrPartnerCollectionViewModel();
     NamedIndividuals    = new NamedIndividualCollectionViewModel();
     Organisation        = new OrganisationViewModel();
 }
Esempio n. 5
0
        public async Task ThenTheLegalEntityIsValidIfNameIsProvided()
        {
            var request = new OrganisationDetailsViewModel
            {
                Name = "Test Organisation"
            };
            var result = await _orchestrator.ValidateLegalEntityName(request);

            Assert.IsTrue(result.Data.Valid);
        }
        public ActionResult OrganisationLegalAgreement(string hashedAccountId, OrganisationDetailsViewModel model)
        {
            var viewModel = new OrchestratorResponse <OrganisationDetailsViewModel>
            {
                Data   = model,
                Status = HttpStatusCode.OK
            };

            return(View(viewModel));
        }
        public async Task ThenTheDetailsShouldBeValidated()
        {
            //Arrange
            var model = new OrganisationDetailsViewModel();

            //Act
            await CallAddOtherOrganisationDetailsMethodOnControllerAndReturnResult(model);

            //Assert
            base.Orchestrator.Verify(x => x.ValidateLegalEntityName(It.IsAny <OrganisationDetailsViewModel>()), Times.Once);
        }
        public async Task ThenAnAddressViewModelShouldBeGeneratedIfValid()
        {
            //Arrange
            var model = new OrganisationDetailsViewModel();

            //Act
            await CallAddOtherOrganisationDetailsMethodOnControllerAndReturnResult(model);

            //Assert
            base.Mapper.Verify(x => x.Map <FindOrganisationAddressViewModel>(_validationResponse.Data), Times.Once);
        }
        public async Task ThenTheDetailsShouldBeValidated()
        {
            //Arrange
            var model = new OrganisationDetailsViewModel();

            //Act
            await _controller.AddOtherOrganisationDetails(model);

            //Assert
            _orchestrator.Verify(x => x.ValidateLegalEntityName(It.IsAny <OrganisationDetailsViewModel>()), Times.Once);
        }
Esempio n. 10
0
        CreateAddOrganisationAddressViewModelFromOrganisationDetails(OrganisationDetailsViewModel model)
        {
            var result = new OrchestratorResponse <AddOrganisationAddressViewModel>
            {
                Data = new AddOrganisationAddressViewModel
                {
                    OrganisationType     = OrganisationType.Other,
                    OrganisationHashedId = model.HashedId,
                    OrganisationName     = model.Name
                }
            };

            return(result);
        }
        public async Task ThenIShouldBeRedirectedToTheAddressDetailsPageIfTheDetailsAreValid()
        {
            //Arrange
            var model = new OrganisationDetailsViewModel();

            //Act
            var result = await CallAddOtherOrganisationDetailsMethodOnControllerAndReturnResult(model);

            //Assert
            var viewResult = result as ViewResult;

            Assert.IsNotNull(viewResult);
            Assert.AreEqual(ControllerConstants.FindAddressViewName, viewResult.ViewName);
        }
        public async Task ThenIShouldBeRedirectedToTheAddressDetailsPageIfTheDetailsAreValid()
        {
            //Arrange
            var model = new OrganisationDetailsViewModel();

            //Act
            var result = await _controller.AddOtherOrganisationDetails(model);

            //Assert
            var viewResult = result as ViewResult;

            Assert.IsNotNull(viewResult);
            Assert.AreEqual("FindAddress", viewResult.ViewName);
        }
Esempio n. 13
0
        public void ThenTheAddOrganisationAddressViewModelPropertiesAreCorrectlyPopulated()
        {
            //Arrange
            var model = new OrganisationDetailsViewModel
            {
                Name     = "Test Organisation",
                HashedId = "ABCD123"
            };

            //Act
            var result = _orchestrator.CreateAddOrganisationAddressViewModelFromOrganisationDetails(model);

            //Assert
            Assert.AreEqual(OrganisationType.Other, result.Data.OrganisationType);
            Assert.AreEqual("Test Organisation", result.Data.OrganisationName);
            Assert.AreEqual("ABCD123", result.Data.OrganisationHashedId);
        }
        /// <summary>
        /// Gets the details of a particular organisation, including the list of linked users
        /// </summary>
        /// <param name="organisationId"></param>
        /// <returns>The organisationdetailsviewmodel containing Organisation Name, Address and List of linked users</returns>
        public OrganisationDetailsViewModel GetOrganisationDetails(int organisationId)
        {
            var org = _dbContext.ApplicationOrganisations.FirstOrDefault(z => z.Id == organisationId);

            if (org == null)
            {
                return(null);
            }
            var model = new OrganisationDetailsViewModel
            {
                OrganisationName    = org.organisationName,
                OrganisationAddress = org.organisationAddress,
                LinkedUsers         = GetAllUsersInOrganisation(organisationId)
            };

            return(model);
        }
        public async Task <ActionResult> AddOtherOrganisationDetails(OrganisationDetailsViewModel model)
        {
            var response = await _orchestrator.ValidateLegalEntityName(model);

            if (response.Status == HttpStatusCode.BadRequest)
            {
                return(View("AddOtherOrganisationDetails", response));
            }

            model.Type = OrganisationType.Other;

            var addressModel = new OrchestratorResponse <FindOrganisationAddressViewModel>
            {
                Data = _mapper.Map <FindOrganisationAddressViewModel>(response.Data)
            };

            return(View("FindAddress", addressModel));
        }
        public async Task ThenIShouldGetCompanyDetailsBackIfTheyExist()
        {
            //Arrange
            var viewModel = new OrganisationDetailsViewModel
            {
                HashedId        = "1",
                Name            = "Test Corp",
                ReferenceNumber = "0123456",
                DateOfInception = DateTime.Now,
                Address         = "1 Test Road, Test City, TE12 3ST",
                Status          = "active"
            };

            _orchestrator.Setup(x => x.GetLimitedCompanyByRegistrationNumber(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new OrchestratorResponse <OrganisationDetailsViewModel>
            {
                Data = viewModel
            });

            var username = "******";

            _owinWrapper.Setup(x => x.GetClaimValue(It.IsAny <string>())).Returns(username);

            var addModel = new AddLegalEntityViewModel
            {
                HashedAccountId      = viewModel.HashedId,
                OrganisationType     = OrganisationType.CompaniesHouse,
                CompaniesHouseNumber = viewModel.ReferenceNumber
            };

            //Act
            var result = await _controller.AddOrganisation(addModel) as ViewResult;

            //Assert
            Assert.IsNotNull(result);

            _orchestrator.Verify(x => x.GetLimitedCompanyByRegistrationNumber(viewModel.ReferenceNumber, viewModel.HashedId, username), Times.Once);

            var model = result.Model as OrchestratorResponse <OrganisationDetailsViewModel>;

            Assert.IsNotNull(model?.Data);
        }
        public async Task ThenIShouldBeRedirectedBackIfTheDetailsAreInvalid()
        {
            //Arrange
            base.Orchestrator.Setup(x => x.ValidateLegalEntityName(It.IsAny <OrganisationDetailsViewModel>()))
            .ReturnsAsync(new OrchestratorResponse <OrganisationDetailsViewModel>
            {
                Data   = new OrganisationDetailsViewModel(),
                Status = HttpStatusCode.BadRequest
            });

            var model = new OrganisationDetailsViewModel();

            //Act
            var result = await CallAddOtherOrganisationDetailsMethodOnControllerAndReturnResult(model);

            //Assert
            var viewResult = result as ViewResult;

            Assert.IsNotNull(viewResult);
            Assert.AreEqual(ControllerConstants.AddOtherOrganisationDetailsViewName, viewResult?.ViewName);
        }
        public static void CreateOrganisationCookie(this OrganisationDetailsViewModel viewModel, IOrchestratorCookie orchestrator,
                                                    HttpContextBase httpContext)
        {
            EmployerAccountData data;

            if (viewModel?.Name != null)
            {
                data = new EmployerAccountData
                {
                    OrganisationType              = viewModel.Type,
                    OrganisationReferenceNumber   = viewModel.ReferenceNumber,
                    OrganisationName              = viewModel.Name,
                    OrganisationDateOfInception   = viewModel.DateOfInception,
                    OrganisationRegisteredAddress = viewModel.Address,
                    OrganisationStatus            = viewModel.Status ?? string.Empty,
                    PublicSectorDataSource        = viewModel.PublicSectorDataSource,
                    Sector    = viewModel.Sector,
                    NewSearch = viewModel.NewSearch
                };
            }
            else
            {
                var existingData = orchestrator.GetCookieData(httpContext);

                data = new EmployerAccountData
                {
                    OrganisationType              = existingData.OrganisationType,
                    OrganisationReferenceNumber   = existingData.OrganisationReferenceNumber,
                    OrganisationName              = existingData.OrganisationName,
                    OrganisationDateOfInception   = existingData.OrganisationDateOfInception,
                    OrganisationRegisteredAddress = existingData.OrganisationRegisteredAddress,
                    OrganisationStatus            = existingData.OrganisationStatus,
                    PublicSectorDataSource        = existingData.PublicSectorDataSource,
                    Sector    = existingData.Sector,
                    NewSearch = existingData.NewSearch
                };
            }

            orchestrator.CreateCookieData(httpContext, data);
        }
Esempio n. 19
0
        public ActionResult Confirm(string hashedAccountId, OrganisationDetailsViewModel viewModel)
        {
            viewModel.NewSearch = true;

            if (string.IsNullOrWhiteSpace(viewModel.Address))
            {
                return(FindAddress(hashedAccountId, viewModel));
            }

            saveOrganisationDataIfItHasAValidName(viewModel);

            if (string.IsNullOrEmpty(hashedAccountId))
            {
                return(RedirectToAction(ControllerConstants.SummaryActionName, ControllerConstants.EmployerAccountControllerName));
            }

            var response = new OrchestratorResponse <OrganisationDetailsViewModel> {
                Data = viewModel
            };

            return(View(ControllerConstants.ConfirmOrganisationDetailsViewName, response));
        }
        public ActionResult Confirm(string hashedAccountId, OrganisationDetailsViewModel viewModel)
        {
            viewModel.NewSearch = true;

            if (string.IsNullOrWhiteSpace(viewModel.Address))
            {
                return(FindAddress(hashedAccountId, viewModel));
            }
            viewModel.CreateOrganisationCookie(_orchestrator, HttpContext);

            if (string.IsNullOrEmpty(hashedAccountId))
            {
                return(RedirectToAction(ControllerConstants.GatewayInformActionName, ControllerConstants.EmployerAccountControllerName));
            }


            var response = new OrchestratorResponse <OrganisationDetailsViewModel> {
                Data = viewModel
            };

            return(View(ControllerConstants.ConfirmOrganisationDetailsViewName, response));
        }
Esempio n. 21
0
 private void saveOrganisationDataIfItHasAValidName(OrganisationDetailsViewModel viewModel)
 {
     if (viewModel?.Name != null)
     {
         _mediatr
         .SendAsync(new SaveOrganisationData
                    (
                        new EmployerAccountOrganisationData
         {
             OrganisationType              = viewModel.Type,
             OrganisationReferenceNumber   = viewModel.ReferenceNumber,
             OrganisationName              = viewModel.Name,
             OrganisationDateOfInception   = viewModel.DateOfInception,
             OrganisationRegisteredAddress = viewModel.Address,
             OrganisationStatus            = viewModel.Status ?? string.Empty,
             PublicSectorDataSource        = viewModel.PublicSectorDataSource,
             Sector    = viewModel.Sector,
             NewSearch = viewModel.NewSearch
         }
                    ));
     }
 }
 private bool ShellfishResolver(OrganisationDetailsViewModel model)
 {
     return(model.OperatingIndustries.OperatingIndustries.Any(x => x.Name == "Shellfish" && x.Checked));
 }
        private async Task <ActionResult> CallAddOtherOrganisationDetailsMethodOnControllerAndReturnResult(OrganisationDetailsViewModel model)
        {
            var result = await base.Controller.AddOtherOrganisationDetails(model);

            return(result);
        }
        public void it_should_map_the_organisation_details_view_model_to_the_licence_entity()
        {
            var expectedAddress = new AddressViewModel
            {
                AddressLine1 = "1",
                AddressLine2 = "2",
                AddressLine3 = "3",
                CountyId     = 1,
                CountryId    = 1,
                Town         = "town",
                Postcode     = "postcode"
            };

            var input = new OrganisationDetailsViewModel
            {
                BusinessName = new BusinessNameViewModel
                {
                    BusinessName           = "org name",
                    HasTradingName         = true,
                    TradingName            = "trading name",
                    HasPreviousTradingName = true
                },
                BusinessPhoneNumber = new BusinessPhoneNumberViewModel
                {
                    BusinessPhoneNumber = "1"
                },
                BusinessMobileNumber = new BusinessMobileNumberViewModel
                {
                    BusinessMobileNumber = "2"
                },
                BusinessWebsite = new BusinessWebsiteViewModel
                {
                    BusinessWebsite = "www"
                },
                BusinessEmailAddress = new BusinessEmailAddressViewModel
                {
                    BusinessEmailAddress = "*****@*****.**"
                },
                Address     = expectedAddress,
                LegalStatus = new LegalStatusViewModel
                {
                    LegalStatus = LegalStatusEnum.RegisteredCompany,
                    Other       = "Some other industry"
                                  //CompaniesHouseNumber = "6",
                                  //CompanyRegistrationDate = new DateViewModel
                                  //{
                                  //    Date = new DateTime(2000, 4, 4)
                                  //}
                }
            };

            var result = this.mapper.Map <Licence>(input);

            Assert.AreEqual(input.BusinessName.BusinessName, result.BusinessName);
            Assert.AreEqual(input.BusinessName.HasTradingName, result.HasTradingName);
            Assert.AreEqual(input.BusinessName.TradingName, result.TradingName);
            Assert.AreEqual(input.BusinessName.HasPreviousTradingName, result.HasPreviousTradingName);
            Assert.AreEqual(input.BusinessPhoneNumber.BusinessPhoneNumber, result.BusinessPhoneNumber);
            Assert.AreEqual(input.BusinessMobileNumber.BusinessMobileNumber, result.BusinessMobileNumber);
            Assert.AreEqual(input.BusinessWebsite.BusinessWebsite, result.BusinessWebsite);
            Assert.AreEqual(input.BusinessEmailAddress.BusinessEmailAddress, result.BusinessEmailAddress);

            AssertAddress(expectedAddress, result.Address);

            Assert.AreEqual(input.LegalStatus.LegalStatus, result.LegalStatus);
            //Assert.AreEqual(input.LegalStatus.CompaniesHouseNumber, result.CompaniesHouseNumber);
            //Assert.AreEqual(input.LegalStatus.CompanyRegistrationDate.Date, result.CompanyRegistrationDate);
        }