public override async Task <GetResponse <IReadOnlyList <ILocation> > > GetAllAsync(int entityId) { var response = new GetResponse <IReadOnlyList <ILocation> >(); try { using (var connection = ConnectionFactory.GetConnection()) { var sql = $@"{GetSelectByParentIdStatement()}; {GetLocationClassCodesSelectStatement(AuditTypeEnum.WC)} WHERE EntityId = @parentId"; var results = await connection.QueryMultipleAsync(sql, new { ParentId = entityId }); // Get locations var locations = results .Read <LocationsDto>() .Select(dto => dto.ToModel()) .AsList(); var classCodeDtos = results .Read <ClassCodeDto>() .AsList(); foreach (var location in locations) { // Get class codes for the location location.ClassCodes = classCodeDtos .Where(dto => dto.LocationID == location.Id) .Select(dto => dto.ToModel()) .AsList(); // get the payroll for this location var payrollResponse = await _payrollRepository.GetAllPayrollAsync(location.Id); if (payrollResponse.IsSuccessful && payrollResponse.Content.Any()) { location.Payroll = payrollResponse .Content .AsList(); } } response.Content = locations; } } catch (Exception e) { var messaage = $@"Unable to retrieve location records."; response.AddError(e); LogManager.LogError(e, messaage); Console.WriteLine(e); } return(response); }