private async Task UpdateEmployerProfile(VacancyEmployerInfoModel employerInfoModel,
                                                 EmployerProfile employerProfile, Address address, VacancyUser user)
        {
            var updateProfile = false;

            if (string.IsNullOrEmpty(employerProfile.AccountLegalEntityPublicHashedId) && !string.IsNullOrEmpty(employerInfoModel?.AccountLegalEntityPublicHashedId))
            {
                updateProfile = true;
                employerProfile.AccountLegalEntityPublicHashedId = employerInfoModel.AccountLegalEntityPublicHashedId;
            }
            if (employerInfoModel != null && employerInfoModel.EmployerIdentityOption == EmployerIdentityOption.NewTradingName)
            {
                updateProfile = true;
                employerProfile.TradingName = employerInfoModel.NewTradingName;
            }
            if (address != null)
            {
                updateProfile = true;
                employerProfile.OtherLocations.Add(address);
            }
            if (updateProfile)
            {
                await _recruitVacancyClient.UpdateEmployerProfileAsync(employerProfile, user);
            }
        }
        public async Task Then_If_The_Command_Is_Valid_And_The_RegisteredName_Is_Used_Then_Employer_Profile_Updated(
            Vacancy vacancy,
            CreateVacancyCommand command,
            TrainingProvider provider,
            EmployerProfile employerProfile,
            [Frozen] Mock <IEmployerVacancyClient> employerVacancyClient,
            [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient,
            [Frozen] Mock <IMessaging> messaging,
            [Frozen] Mock <ITrainingProviderService> trainingProviderService,
            CreateVacancyCommandHandler handler)
        {
            command.ValidateOnly = false;
            command.Vacancy.EmployerNameOption = EmployerNameOption.TradingName;
            trainingProviderService.Setup(x => x.GetProviderAsync(command.VacancyUserDetails.Ukprn.Value))
            .ReturnsAsync(provider);
            recruitVacancyClient.Setup(x => x.Validate(It.IsAny <Vacancy>(), VacancyRuleSet.All))
            .Returns(new EntityValidationResult());
            recruitVacancyClient.Setup(x => x.GetVacancyAsync(command.Vacancy.Id)).ReturnsAsync(vacancy);
            recruitVacancyClient
            .Setup(x => x.GetEmployerProfileAsync(command.Vacancy.EmployerAccountId,
                                                  command.Vacancy.AccountLegalEntityPublicHashedId)).ReturnsAsync(employerProfile);

            await handler.Handle(command, CancellationToken.None);

            recruitVacancyClient.Verify(x => x.UpdateEmployerProfileAsync(It.Is <EmployerProfile>(c =>
                                                                                                  c.TradingName.Equals(command.Vacancy.EmployerName)
                                                                                                  ), It.IsAny <VacancyUser>()), Times.Once);
        }
Example #3
0
        public async Task GetEmployerNameAsync_ShouldReturnTradingName(VacancyStatus status)
        {
            var employerName    = "Employer Name";
            var legalEntityName = "Legal Entity Name";
            var tradingName     = "Trading Name";
            var vacancy         = new Vacancy()
            {
                Status             = status,
                EmployerName       = employerName,
                LegalEntityName    = legalEntityName,
                EmployerNameOption = EmployerNameOption.TradingName
            };

            var profile = new EmployerProfile
            {
                TradingName = tradingName
            };

            _mockEmployerProfileRepository.Setup(pr => pr.GetAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(profile);

            var sut = GetSut();

            var result = await sut.GetEmployerNameAsync(vacancy);

            result.Should().Be(tradingName);
        }
 public async Task CreateAsync(EmployerProfile profile)
 {
     var collection = GetCollection <EmployerProfile>();
     await RetryPolicy.ExecuteAsync(_ =>
                                    collection.InsertOneAsync(profile),
                                    new Context(nameof(CreateAsync)));
 }
Example #5
0
        public async Task Handle(RefreshEmployerProfilesCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Refreshing Employer Profiles for {employerAccountId}", message.EmployerAccountId);
            var employerVacancyInfoTask =
                _employerVacancyClient.GetEditVacancyInfoAsync(message.EmployerAccountId);
            var tasks           = new List <Task>();
            var editVacancyInfo = employerVacancyInfoTask.Result;
            // Get all current profiles for the employer
            var profiles = await _employerProfileRepository.GetEmployerProfilesForEmployerAsync(message.EmployerAccountId);

            foreach (var accountLegalEntityPublicHashedId in message.AccountLegalEntityPublicHashedIds)
            {
                var selectedOrganisation =
                    editVacancyInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId);
                if (!profiles.Any(x => x.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId))
                {
                    var currentTime = _time.Now;

                    // Create new profile
                    var newProfile = new EmployerProfile
                    {
                        EmployerAccountId = message.EmployerAccountId,
                        CreatedDate       = currentTime,
                        AccountLegalEntityPublicHashedId = selectedOrganisation.AccountLegalEntityPublicHashedId
                    };

                    _logger.LogInformation("Adding new profile for employer account: {employerAccountId} and Account LegalEntityPublicHashed id: {accountLegalEntityPublicHashedId}", message.EmployerAccountId, accountLegalEntityPublicHashedId);
                    tasks.Add(_employerProfileRepository.CreateAsync(newProfile));
                }
            }
            await Task.WhenAll(tasks);

            _logger.LogInformation($"Added {tasks.Count} new profile/s for {{employerAccountId}}", message.EmployerAccountId);
        }
        public async Task Handle(RefreshEmployerProfilesCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Refreshing Employer Profiles for {employerAccountId}", message.EmployerAccountId);

            var tasks = new List <Task>();

            // Get all current profiles for the employer
            var profiles = await _employerProfileRepository.GetEmployerProfilesForEmployerAsync(message.EmployerAccountId);

            foreach (var legalEntity in message.LegalEntityIds)
            {
                if (!profiles.Any(x => x.LegalEntityId == legalEntity))
                {
                    var currentTime = _time.Now;

                    // Create new profile
                    var newProfile = new EmployerProfile
                    {
                        EmployerAccountId = message.EmployerAccountId,
                        LegalEntityId     = legalEntity,
                        CreatedDate       = currentTime
                    };

                    _logger.LogInformation("Adding new profile for employer account: {employerAccountId} and legal entity id: {legalEntityId}", message.EmployerAccountId, legalEntity);
                    tasks.Add(_employerProfileRepository.CreateAsync(newProfile));
                }
            }

            await Task.WhenAll(tasks);

            _logger.LogInformation($"Added {tasks.Count} new profile/s for {{employerAccountId}}", message.EmployerAccountId);
        }
Example #7
0
        public static EmployerProfileEntity Map(this EmployerProfile profile, Guid employerId)
        {
            var entity = new EmployerProfileEntity {
                employerId = employerId
            };

            profile.MapTo(entity);
            return(entity);
        }
        public Task UpdateAsync(EmployerProfile profile)
        {
            var builder = Builders <EmployerProfile> .Filter;
            var filter  = builder.Eq(x => x.EmployerAccountId, profile.EmployerAccountId) &
                          builder.Eq(x => x.LegalEntityId, profile.LegalEntityId);

            var collection = GetCollection <EmployerProfile>();

            return(RetryPolicy.ExecuteAsync(context => collection.ReplaceOneAsync(filter, profile), new Context(nameof(UpdateAsync))));
        }
        public Task UpdateEmployerProfileAsync(EmployerProfile employerProfile, VacancyUser user)
        {
            var command = new UpdateEmployerProfileCommand
            {
                Profile = employerProfile,
                User    = user
            };

            return(_messaging.SendCommandAsync(command));
        }
Example #10
0
        public static EmployerProfile Map(this EmployerProfileEntity entity)
        {
            var profile = new EmployerProfile
            {
                HideCreditReminder     = entity.hideCreditReminder,
                HideBulkCreditReminder = entity.hideBulkCreditReminder,
            };

            entity.MapTo(profile);
            return(profile);
        }
        public async Task <EmployerProfile> GetAsync(string employerAccountId, long legalEntityId)
        {
            var builder = Builders <EmployerProfile> .Filter;
            var filter  = builder.Eq(x => x.Id, EmployerProfile.GetId(employerAccountId, legalEntityId));

            var collection = GetCollection <EmployerProfile>();

            var result = await RetryPolicy.ExecuteAsync(context => collection.FindAsync(filter), new Context(nameof(GetAsync)));

            return(result.SingleOrDefault());
        }
        private async Task <List <Address> > GetAllAvailableLocationsAsync(EmployerProfile employerProfile)
        {
            var employerData = await _employerVacancyClient.GetEditVacancyInfoAsync(employerProfile.EmployerAccountId);

            var legalEntity = employerData.LegalEntities.First(l => l.AccountLegalEntityPublicHashedId == employerProfile.AccountLegalEntityPublicHashedId);

            var locations = new List <Address>();

            locations.Add(legalEntity.Address.ConvertToDomainAddress());
            locations.AddRange(employerProfile.OtherLocations);
            return(locations);
        }
        private async Task <List <Address> > GetAllAvailableLocationsAsync(EmployerProfile employerProfile, Vacancy vacancy, long ukprn)
        {
            var providerData = await _providerVacancyClient.GetProviderEditVacancyInfoAsync(ukprn);

            var employerInfo = providerData.Employers.Single(e => e.EmployerAccountId == vacancy.EmployerAccountId);
            var legalEntity  = employerInfo.LegalEntities.First(l => l.LegalEntityId == employerProfile.LegalEntityId);
            var locations    = new List <Address>();

            locations.Add(legalEntity.Address.ConvertToDomainAddress());
            locations.AddRange(employerProfile.OtherLocations);
            return(locations);
        }
Example #14
0
        public async Task <EmployerProfile> GetAsync(string employerAccountId, string accountLegalEntityPublicHashedId)
        {
            var builder = Builders <EmployerProfile> .Filter;
            var filter  = builder.Eq(x => x.Id, EmployerProfile.GetId(employerAccountId, accountLegalEntityPublicHashedId));

            var collection = GetCollection <EmployerProfile>();

            var result = await RetryPolicy.Execute(_ =>
                                                   collection.Find(filter).SingleOrDefaultAsync(),
                                                   new Context(nameof(GetAsync)));

            return(result);
        }
Example #15
0
        void IProfilesRepository.UpdateEmployerProfile(Guid employerId, EmployerProfile profile)
        {
            using (var dc = CreateContext())
            {
                // Create or update as needed.

                var entity = GetEmployerProfileEntity(dc, employerId);
                if (entity == null)
                {
                    dc.EmployerProfileEntities.InsertOnSubmit(profile.Map(employerId));
                }
                else
                {
                    profile.MapTo(entity);
                }
                dc.SubmitChanges();
            }
        }
        private async Task UpdateEmployerProfileAsync(VacancyEmployerInfoModel employerInfoModel,
                                                      EmployerProfile employerProfile, Address address, VacancyUser user)
        {
            var updateProfile = false;

            if (employerInfoModel != null && employerInfoModel.EmployerIdentityOption == EmployerIdentityOption.NewTradingName)
            {
                updateProfile = true;
                employerProfile.TradingName = employerInfoModel.NewTradingName;
            }
            if (address != null)
            {
                updateProfile = true;
                employerProfile.OtherLocations.Add(address);
            }
            if (updateProfile)
            {
                await _recruitVacancyClient.UpdateEmployerProfileAsync(employerProfile, user);
            }
        }
        public async Task GetEmployerDescriptionAsync_ShouldReturnEmployerProfileAboutOrganisation(VacancyStatus status)
        {
            var employerProfileAboutOrganisation = "Employer Profile About Organisation";

            var vacancy = new Vacancy()
            {
                Status = status,
                EmployerDescription = "Employer Description",
            };

            var profile = new EmployerProfile {
                AboutOrganisation = employerProfileAboutOrganisation
            };

            _mockEmployerProfileRepository.Setup(pr => pr.GetAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(profile);

            var sut = GetSut();

            var result = await sut.GetEmployerDescriptionAsync(vacancy);

            result.Should().Be(employerProfileAboutOrganisation);
        }
Example #18
0
 public static void MapTo(this EmployerProfile profile, EmployerProfileEntity entity)
 {
     entity.hideCreditReminder     = profile.HideCreditReminder;
     entity.hideBulkCreditReminder = profile.HideBulkCreditReminder;
     ((UserProfile)profile).MapTo(entity);
 }
Example #19
0
 void IProfilesCommand.UpdateEmployerProfile(Guid employerId, EmployerProfile profile)
 {
     profile.Prepare();
     profile.Validate();
     _repository.UpdateEmployerProfile(employerId, profile);
 }