public async Task <ClientConsultantRecommendationDto> RecommendConsultantAsync(RecommendConsultantCommand dto) { var existingRecommendation = await applicationDbContext.ConsultantRecommendations .Include(x => x.Consultant) .Include(x => x.Client) .FirstOrDefaultAsync(x => x.ClientId == dto.ClientId && x.ConsultantId == dto.ConsultantId); if (existingRecommendation != null) { throw new InvalidOperationException($"{existingRecommendation.Consultant.Id} has already been presented to {existingRecommendation.Client.Id}"); } var user = await identityService.GetUserAsync(); await applicationDbContext.Entry(user).Reference(e => e.Profile).LoadAsync(); await applicationDbContext.Entry(user.Profile).Reference(e => e.Organization).LoadAsync(); var consultantRecommendation = mapper.Map <ConsultantRecommendation>(dto); consultantRecommendation.Manager = user.Profile as ManagerProfile; consultantRecommendation.Date = DateTime.Now; applicationDbContext.ConsultantRecommendations.Add(consultantRecommendation); await applicationDbContext.SaveChangesAsync(); return(mapper.Map <ClientConsultantRecommendationDto>(consultantRecommendation)); }