public async Task <PagingResponseMessage <BuildingResponse> > SearchBuilding([FromBody] BuildingSearch buildingSearch) { var response = new PagingResponseMessage <BuildingResponse>(); if (!ModelState.IsValid) { response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = ModelState.GetAllErrors(); Logger.LogWarning($"获取建筑(SearchBuilding)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (buildingSearch != null ? JsonHelper.ToJson(buildingSearch) : "")); return(response); } try { response = await _buildingManager.Search(buildingSearch, HttpContext.RequestAborted); } catch (Exception e) { response.Code = ResponseCodeDefines.ServiceError; response.Message = e.Message; Logger.LogError($"获取建筑(SearchBuilding)请求失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (buildingSearch != null ? JsonHelper.ToJson(buildingSearch) : "")); } return(response); }
/// <summary> /// 查询楼盘信息 /// </summary> /// <param name="buildingSearch">请求实体</param> /// <param name="cancellationToken">验证</param> /// <returns></returns> public virtual async Task <PagingResponseMessage <BuildingResponse> > Search(BuildingSearch buildingSearch, CancellationToken cancellationToken = default(CancellationToken)) { var response = new PagingResponseMessage <BuildingResponse>(); var buildings = _ibuildingStore.Buildings.Where(x => buildingSearch.Latitudes.Contains(x.Latitude) && buildingSearch.Longitudes.Contains(x.Longitude)); var query = await buildings .Skip(buildingSearch.PageIndex *buildingSearch.PageSize) .Take(buildingSearch.PageSize) .ToListAsync(cancellationToken); //string fr = ApplicationCore.ApplicationContext.Current.FileServerRoot; //fr = (fr ?? "").TrimEnd('/'); //var building = await query.FirstOrDefaultAsync(cancellationToken); //building.Icon = string.IsNullOrEmpty(building.Icon) ? "" : fr + "/" + building.Icon.TrimStart('/'); response.TotalCount = await buildings.CountAsync(cancellationToken); response.PageIndex = buildingSearch.PageIndex; response.PageSize = buildingSearch.PageSize; response.Extension = _mapper.Map <List <BuildingResponse> >(query); return(response); }