public async Task <ActionResult <GetAdmSchoolGroupSitesResponse> > GetAdmSchoolGroupSites([FromQuery] GetAdmSchoolGroupSiteRequest request) { _logger.LogInformation($"{nameof(SchoolGroupsController)}.{nameof(GetAdmSchoolGroupSites)} params: ({JsonConvert.SerializeObject(request, Formatting.Indented)})"); return(new GetAdmSchoolGroupSitesResponse { Items = await _logic.GetAdmSchoolGroupSites(request) }); }
public async Task <List <AdmSchoolGroupSiteViewModel> > GetAdmSchoolGroupSites(GetAdmSchoolGroupSiteRequest request) { IList <AdmSite> admSites; //I know it looks much shorter than in old site code, but it works in the same way, I tested it on the real data //it always returns the same set as old code if (request.IsCep) { admSites = await _repository.GetListAsync <AdmSite>(x => x.IsActive && x.AdmSchoolGroups.All(y => !y.IsCEPGroup)); } else { admSites = await _repository.GetListAsync <AdmSite>(x => x.IsActive); } //using automapper here will be tripple more code, because we need to make a profile and then use additionally parametrized Map<> function return(admSites.Select(x => new AdmSchoolGroupSiteViewModel { AdmSiteID = x.AdmSiteID, SchoolID = x.SiteID, SchoolName = x.SiteDescription, //due to the repository limitation we will have 1 additional db request per AdmSite here //we should have smarter repository to avoid this //in old site there are even more requests however, even using the IQueriable ... IsSelected = x.AdmSchoolGroups.Any(y => y.AdmSchoolGroupID == request.Id), IsCEPSchool = request.IsCep }).ToList()); }