public When_EmployerService_Is_Called_To_Get_Opportunity_Employer_Owner_Null() { var employerRepository = Substitute.For <IRepository <Domain.Models.Employer> >(); _opportunityRepository = Substitute.For <IOpportunityRepository>(); _opportunityRepository.GetFirstOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.Opportunity, bool> > >()) .Returns((Domain.Models.Opportunity)null); var employerService = new EmployerService(employerRepository, _opportunityRepository, Substitute.For <IMapper>(), Substitute.For <IValidator <CrmEmployerEventBase> >(), Substitute.For <IMessageQueueService>()); _result = employerService.GetEmployerOpportunityOwnerAsync(new Guid("11111111-1111-1111-1111-111111111111")).GetAwaiter().GetResult(); }
public async Task DeleteEmployerOpportunityItemAsync(int opportunityId) { var opportunity = await _opportunityRepository.GetFirstOrDefaultAsync(opp => opp.Id == opportunityId); if (opportunity == null) { return; } await DeleteOpportunityItemsAsync(opportunityId, true); await DeleteOpportunityItemsAsync(opportunityId, false); var completedOpportunityItems = _opportunityItemRepository.GetManyAsync(item => item.OpportunityId == opportunityId && item.IsSaved && item.IsCompleted); if (!completedOpportunityItems.Any()) { await _opportunityRepository.DeleteAsync(opportunity); } }
public async Task <EmployerDetailsViewModel> GetOpportunityEmployerDetailAsync(int opportunityId, int opportunityItemId) { var employerCrmId = await _opportunityRepository.GetSingleOrDefaultAsync( opportunity => opportunity.Id == opportunityId, o => o.EmployerCrmId); if (employerCrmId == null || employerCrmId == Guid.Empty) { throw new InvalidOperationException("Unable to Find any Employer Details for current Opportunity. Please go back to Find Employer Screen and select an employer"); } //1 first try getting from current Opportunity if its not null var employerDetails = await _opportunityRepository.GetSingleOrDefaultAsync( o => o.Id == opportunityId && !string.IsNullOrEmpty(o.EmployerContact) && !string.IsNullOrEmpty(o.EmployerContactEmail) && !string.IsNullOrEmpty(o.EmployerContactPhone), o => new EmployerDetailsViewModel { OpportunityItemId = opportunityItemId, OpportunityId = o.Id, CompanyName = o.Employer.CompanyName, AlsoKnownAs = o.Employer.AlsoKnownAs, PrimaryContact = o.EmployerContact, Email = o.EmployerContactEmail, Phone = o.EmployerContactPhone }, o => o.CreatedOn, false); if (employerDetails != null) { return(employerDetails); } //2 then try and find from any previous completed Opportunities using employerCrmId employerDetails = await _opportunityRepository.GetFirstOrDefaultAsync( o => o.EmployerCrmId == employerCrmId && !string.IsNullOrEmpty(o.EmployerContact) && !string.IsNullOrEmpty(o.EmployerContactEmail) && !string.IsNullOrEmpty(o.EmployerContactPhone) && o.OpportunityItem.Any(oi => oi.OpportunityType == OpportunityType.Referral.ToString() && oi.IsCompleted && oi.IsCompleted), o => new EmployerDetailsViewModel { OpportunityItemId = opportunityItemId, OpportunityId = opportunityId, CompanyName = o.Employer.CompanyName, AlsoKnownAs = o.Employer.AlsoKnownAs, PrimaryContact = o.EmployerContact, Email = o.EmployerContactEmail, Phone = o.EmployerContactPhone }); if (employerDetails != null) { return(employerDetails); } //3 Finally we cant find employer details in existing Opportunities so now try to load it from Employer Table return(await _employerRepository.GetSingleOrDefaultAsync( e => e.CrmId == employerCrmId, e => new EmployerDetailsViewModel { OpportunityItemId = opportunityItemId, OpportunityId = opportunityId, CompanyName = e.CompanyName, AlsoKnownAs = e.AlsoKnownAs, PrimaryContact = e.PrimaryContact, Email = e.Email, Phone = e.Phone })); }