public async Task <BasePageList <FarmResult> > GetAsync(FarmFilter filter) { var famrsPageList = await _farmRepository.GetAsync(filter); var createdByIds = famrsPageList.Collections.Select(x => x.CreatedById).ToArray(); var updatedByIds = famrsPageList.Collections.Select(x => x.UpdatedById).ToArray(); var createdByUsers = await _userRepository.GetNameByIdsAsync(createdByIds); var updatedByUsers = await _userRepository.GetNameByIdsAsync(updatedByIds); var farmIds = famrsPageList.Collections.Select(x => x.Id); var pictures = await _farmPictureRepository.GetFarmPicturesByFarmIdsAsync(farmIds, new IdRequestFilter <long> { CanGetDeleted = filter.CanGetDeleted, CanGetInactived = filter.CanGetInactived }, FarmPictureType.Thumbnail); var userAvatars = await _userPhotoRepository.GetUserPhotosByUserIdsAsync(createdByIds, UserPictureType.Avatar); foreach (var farm in famrsPageList.Collections) { var createdBy = createdByUsers.FirstOrDefault(x => x.Id == farm.CreatedById); farm.CreatedBy = createdBy.DisplayName; var updatedBy = updatedByUsers.FirstOrDefault(x => x.Id == farm.UpdatedById); farm.UpdatedBy = updatedBy.DisplayName; var farmPictures = pictures.Where(x => x.FarmId == farm.Id); if (farmPictures != null && farmPictures.Any()) { farm.Pictures = farmPictures.Select(x => new PictureResult { Id = x.PictureId }); } var avatar = userAvatars.FirstOrDefault(x => x.UserId == farm.CreatedById); if (avatar != null) { farm.CreatedByPhotoCode = avatar.Code; } } return(famrsPageList); }