private void SaveChangesToSicCodes(AdminSicCodeUploadCheckViewModel viewModel) { foreach (SicCode sicCodeFromUser in viewModel.AddsEditsDeletesSet.ItemsToAdd) { var sicCode = new SicCode { SicCodeId = sicCodeFromUser.SicCodeId, SicSectionId = sicCodeFromUser.SicSectionId, Description = sicCodeFromUser.Description, Synonyms = sicCodeFromUser.Synonyms }; dataRepository.Insert(sicCode); } foreach (OldAndNew <SicCode> oldAndNew in viewModel.AddsEditsDeletesSet.ItemsToChange) { SicCode sicCode = dataRepository.Get <SicCode>(oldAndNew.Old.SicCodeId); sicCode.SicSectionId = oldAndNew.New.SicSectionId; sicCode.Description = oldAndNew.New.Description; sicCode.Synonyms = oldAndNew.New.Synonyms; } foreach (SicCode sicCodeFromUser in viewModel.AddsEditsDeletesSet.ItemsToDelete) { SicCode sicCode = dataRepository.Get <SicCode>(sicCodeFromUser.SicCodeId); dataRepository.Delete(sicCode); } dataRepository.SaveChanges(); }
private void PopulateViewModelFromCompaniesHouseSicCodes( ChangeOrganisationSicCodesViewModel viewModel, List <string> sicCodeIdStringsFromCompaniesHouse, Organisation organisation) { var sicCodesFromCompaniesHouse = new Dictionary <string, SicCode>(); var sicCodeIdsFromCompaniesHouse = new List <int>(); List <int> sicCodeIdsFromDatabase = organisation.GetSicCodeIds().ToList(); foreach (string sicCodeIdString in sicCodeIdStringsFromCompaniesHouse.Distinct()) { SicCode sicCode = null; if (int.TryParse(sicCodeIdString, out int sicCodeId)) { sicCode = dataRepository.Get <SicCode>(sicCodeId); if (sicCode != null) { sicCodeIdsFromCompaniesHouse.Add(sicCodeId); } } sicCodesFromCompaniesHouse.Add(sicCodeIdString, sicCode); } List <int> sicCodeIdsToAdd = sicCodeIdsFromCompaniesHouse.Except(sicCodeIdsFromDatabase).ToList(); List <int> sicCodeIdsToRemove = sicCodeIdsFromDatabase.Except(sicCodeIdsFromCompaniesHouse).ToList(); viewModel.Organisation = organisation; viewModel.SicCodesFromCoHo = sicCodesFromCompaniesHouse; viewModel.SicCodeIdsFromCoHo = sicCodeIdStringsFromCompaniesHouse; viewModel.SicCodeIdsToAdd = sicCodeIdsToAdd; viewModel.SicCodeIdsToRemove = sicCodeIdsToRemove; }
public override int GetHashCode() { unchecked { var hashCode = (PrimarySymbol != null ? PrimarySymbol.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (SicCode != null ? SicCode.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Dcn != null ? Dcn.GetHashCode() : 0); return(hashCode); } }
public SortedSet <int> GetSicCodesIds() { var codes = new SortedSet <int>(); foreach (var sicCode in SicCode.SplitI()) { codes.Add(sicCode.ToInt32()); } return(codes); }
public override int GetHashCode() { unchecked { var hash = 17; hash = hash * 29 + RequestId != null?RequestId.GetHashCode() : 0; hash = hash * 29 + SicCode.GetHashCode(); hash = hash * 29 + Description.GetHashCode(); return(hash); } }
public override int GetHashCode() { unchecked { var hash = 17; hash = hash * 29 + RequestId != null?RequestId.GetHashCode() : 0; hash = hash * 29 + SicCode.GetHashCode(); hash = hash * 29 + Symbol.GetHashCode(); hash = hash * 29 + ListedMarketId.GetHashCode(); hash = hash * 29 + SecurityTypeId.GetHashCode(); hash = hash * 29 + Description.GetHashCode(); return(hash); } }
private void AddOrganisationSicCode(Organisation organisation, int sicCodeInt, SourceOfData sourceOfData) { SicCode sicCode = dataRepository.Get <SicCode>(sicCodeInt); if (sicCode == null) { CustomLogger.Warning( "Bad SIC code", new { OrganisationName = organisation.OrganisationName, CompanyNumber = organisation.CompanyNumber, SicCode = sicCodeInt, Source = sourceOfData.ToString(), Error = $"SIC code ({sicCodeInt}) not found in our database" }); return; } string source; switch (sourceOfData) { case SourceOfData.CompaniesHouse: source = "CoHo"; break; case SourceOfData.Manual: source = "Manual"; break; default: throw new ArgumentOutOfRangeException(nameof(sourceOfData), sourceOfData, null); } var organisationSicCode = new OrganisationSicCode { Organisation = organisation, SicCode = sicCode, Source = source }; organisation.OrganisationSicCodes.Add(organisationSicCode); dataRepository.Insert(organisationSicCode); }
private void AddSicCodes(ChangeOrganisationSicCodesViewModel viewModel, Organisation organisation) { if (viewModel.SicCodeIdsToAdd != null) { foreach (int sicCodeId in viewModel.SicCodeIdsToAdd) { // This line validates that the SIC code ID is in our database SicCode sicCode = dataRepository.Get <SicCode>(sicCodeId); var newSicCode = new OrganisationSicCode { OrganisationId = organisation.OrganisationId, SicCodeId = sicCode.SicCodeId, Source = "Service Desk", Created = VirtualDateTime.Now, }; organisation.OrganisationSicCodes.Add(newSicCode); dataRepository.Insert(newSicCode); } } }
private IActionResult AddNewSicCode(ChangeOrganisationSicCodesViewModel viewModel, Organisation organisation) { viewModel.ParseAndValidateParameters(Request, m => m.SicCodeIdToChange); if (viewModel.HasAnyErrors()) { PopulateViewModelWithSicCodeData(viewModel, organisation); return(View("ManuallyChangeOrganisationSicCodes", viewModel)); } SicCode newSicCode = dataRepository.Get <SicCode>(viewModel.SicCodeIdToChange.Value); if (newSicCode == null) { viewModel.AddErrorFor( m => m.SicCodeIdToChange, "This SIC code is not valid (it is not in our database of SIC codes)"); } if (viewModel.HasAnyErrors()) { PopulateViewModelWithSicCodeData(viewModel, organisation); return(View("ManuallyChangeOrganisationSicCodes", viewModel)); } if (viewModel.SicCodeIdsToAdd == null) { viewModel.SicCodeIdsToAdd = new List <int>(); } viewModel.SicCodeIdsToAdd.Add(newSicCode.SicCodeId); viewModel.SicCodeIdToChange = null; PopulateViewModelWithSicCodeData(viewModel, organisation); return(View("ManuallyChangeOrganisationSicCodes", viewModel)); }
public void RegistrationController_AddSector_POST_Success() { //ARRANGE: //1.Arrange the test setup variables var user = new User { UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now }; //Set user email address verified code and expired sent date var routeData = new RouteData(); routeData.Values.Add("Action", nameof(RegistrationController.AddSector)); routeData.Values.Add("Controller", "Registration"); var employerResult = new PagedResult <EmployerRecord>(); employerResult.Results = new List <EmployerRecord>(); //use the include and exclude functions here to save typing var model = new OrganisationViewModel { NoReference = false, OrganisationName = "Acme ltd", NameSource = "CoHo", DUNSNumber = "012345678", CompanyNumber = "12345678", CharityNumber = "Charity1", MutualNumber = "Mutual1", OtherName = "OtherName1", OtherValue = "OtherValue1", DateOfCessation = VirtualDateTime.Now, ManualAddress = false, AddressSource = "CoHo", Address1 = "123", Address2 = "evergreen terrace", Address3 = "Westminster", City = "City1", County = "County1", Country = "United Kingdom", PoBox = "PoBox 12", Postcode = "W1 5qr", ContactEmailAddress = "*****@*****.**", ContactFirstName = "test firstName", ContactLastName = "test lastName", ContactJobTitle = "test job title", ContactPhoneNumber = "79000 000 000", SicCodeIds = "1,2,3,4", SicSource = "CoHo", SearchText = "Searchtext", ManualRegistration = false, SectorType = SectorTypes.Private, PINExpired = false, PINSent = false, SelectedEmployerIndex = 0, Employers = employerResult, //0 record returned ManualEmployers = new List <EmployerRecord>(), ManualEmployerIndex = -1, AddressReturnAction = nameof(RegistrationController.ConfirmOrganisation), ConfirmReturnAction = nameof(RegistrationController.ChooseOrganisation) }; var sic1 = new SicCode { SicCodeId = 1420, SicSectionId = "SSID1", SicSection = new SicSection { SicSectionId = "5221" }, Description = "" }; var sic2 = new SicCode { SicCodeId = 14310, SicSectionId = "SSID1", SicSection = new SicSection { SicSectionId = "4115" }, Description = "" }; var controller = UiTestHelper.GetController <RegistrationController>(1, routeData, user, sic1, sic2); //Stash the object for the unstash to happen in code controller.StashModel(model); OrganisationViewModel savedModel = model.GetClone(); savedModel.SicCodeIds = "1420,14310"; controller.Bind(savedModel); OrganisationViewModel expectedModel = savedModel.GetClone(); expectedModel.SicSource = user.EmailAddress; expectedModel.ConfirmReturnAction = nameof(RegistrationController.AddSector); //ACT: //2.Run and get the result of the test var result = controller.AddSector(savedModel) as RedirectToActionResult; //ASSERTS: //3.Check that the result is not null Assert.NotNull(result, "Expected RedirectToActionResult"); //4.Check that the redirection went to the right url step. Assert.That(result.ActionName == nameof(RegistrationController.ConfirmOrganisation), "Redirected to the wrong view"); //5.If the redirection successfull retrieve the model stash sent with the redirect. var unstashedModel = controller.UnstashModel <OrganisationViewModel>(); //6.Check that the unstashed model is not null Assert.NotNull(unstashedModel, "Expected OrganisationViewModel"); //Check result is same as expected expectedModel.Compare(unstashedModel); }
public void RegistrationController_AddAddress_POST_AuthorisedNoAddress_ToConfirm() { //ARRANGE: //1.Arrange the test setup variables var user = new User { UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now }; var address0 = new OrganisationAddress { AddressId = 1, Status = AddressStatuses.Active, Source = "CoHo", Address1 = "123", Address2 = "evergreen terrace", Address3 = "Westminster", TownCity = "City1", County = "County1", Country = "United Kingdom", PoBox = "PoBox 12", PostCode = "W1 5qr" }; var sicCode1 = new SicCode { SicCodeId = 2100, Description = "Desc1", SicSection = new SicSection { SicSectionId = "4321", Description = "Section1" } }; var sicCode2 = new SicCode { SicCodeId = 10520, Description = "Desc2", SicSection = new SicSection { SicSectionId = "4326", Description = "Section2" } }; var org0 = new Core.Entities.Organisation { OrganisationId = 1, OrganisationName = "Company1", SectorType = SectorTypes.Private, Status = OrganisationStatuses.Active, CompanyNumber = "12345678" }; org0.OrganisationAddresses.Add(address0); var name = new OrganisationName { OrganisationNameId = 1, Name = org0.OrganisationName, Created = org0.Created, Organisation = org0, OrganisationId = org0.OrganisationId }; org0.OrganisationNames.Add(name); var sic1 = new OrganisationSicCode { SicCode = sicCode1, SicCodeId = 2100, Created = org0.Created, Organisation = org0, OrganisationId = org0.OrganisationId }; org0.OrganisationSicCodes.Add(sic1); var sic2 = new OrganisationSicCode { SicCode = sicCode2, SicCodeId = 10520, Created = org0.Created, Organisation = org0, OrganisationId = org0.OrganisationId }; org0.OrganisationSicCodes.Add(sic2); //Set user email address verified code and expired sent date var routeData = new RouteData(); routeData.Values.Add("Action", nameof(RegistrationController.AddAddress)); routeData.Values.Add("Controller", "Registration"); var controller = UiTestHelper.GetController <RegistrationController>(user.UserId, routeData, user, org0, address0, name, sic1, sic2); var employerResult = new PagedResult <EmployerRecord>(); employerResult.Results = new List <EmployerRecord> { EmployerRecord.Create(org0) }; //use the include and exclude functions here to save typing var model = new OrganisationViewModel { NoReference = false, SearchText = "Searchtext", ManualAddress = true, SelectedAuthorised = true, ManualRegistration = false, SectorType = SectorTypes.Public, PINExpired = false, PINSent = false, SelectedEmployerIndex = 0, Employers = employerResult, //0 record returned ManualEmployers = new List <EmployerRecord>(), ManualEmployerIndex = -1, AddressReturnAction = nameof(RegistrationController.ConfirmOrganisation), ConfirmReturnAction = nameof(RegistrationController.ChooseOrganisation) }; //Stash the object for the unstash to happen in code controller.StashModel(model); OrganisationViewModel savedModel = model.GetClone(); savedModel.Address1 = "Unit 2"; savedModel.Address2 = "Bank Road"; savedModel.Address3 = "Essex"; savedModel.Postcode = "PoStCode 13"; controller.Bind(savedModel); //Set the expected model OrganisationViewModel expectedModel = savedModel.GetClone(); expectedModel.AddressSource = user.EmailAddress; expectedModel.ConfirmReturnAction = nameof(RegistrationController.AddAddress); //ACT: var result = controller.AddAddress(savedModel) as RedirectToActionResult; //ASSERTS: //3.Check that the result is not null Assert.NotNull(result, "Expected RedirectToActionResult"); //4.Check that the redirection went to the right url step. Assert.That(result.ActionName == nameof(RegistrationController.ConfirmOrganisation), "Redirected to the wrong view"); //5.If the redirection successfull retrieve the model stash sent with the redirect. var unstashedModel = controller.UnstashModel <OrganisationViewModel>(); //6.Check that the unstashed model is not null Assert.NotNull(unstashedModel, "Expected OrganisationViewModel"); //Check model is same as expected expectedModel.Compare(unstashedModel); }
private static object GetSicCodeDetails(SicCode sicCode) { return(new { sicCode.SicCodeId, sicCode.SicSectionId, sicCode.Description, sicCode.Synonyms }); }