public async Task <IEnumerable <EmployeeModel> > GetEmployeesByLastName(string companyName, string lastName, CancellationToken token) { Logger.LogInformation("Search for employee last name '{LastName}' for company: {Company}", lastName, companyName); var company = await CompanyRepository.GetCompanyByName(companyName, token).ConfigureAwait(false); if (company == null) { // throw some kind of 'NotFound' exception to controller Logger.LogInformation("Company not found: {Company}", companyName); throw new Exception(); } var employees = await EmployeeRepository.GetEmployeesByLastName(company.Id, lastName, token).ConfigureAwait(false); Logger.LogDebug("Found {Count} employees with '{LastName}' for company: {Company}", employees.Count, lastName, companyName); return(employees.OrderBy(x => x.EmployeeId).Select(y => new EmployeeModel { EmployeeId = y.EmployeeId, LastName = y.LastName, FirstName = y.FirstName, SocialSecurity = y.SocialSecurity, HireDate = y.HireDate, ManagerEmployeeId = y.ManagerEmployeeId, })); }