public async Task <WarehouseSearchItem[]> GetWarehousesAsync(string searchKey, int?limit = null, int?page = null) { var request = new WarehouseSearchRequest(searchKey, limit, page); var response = await this._httpService.GetData <WarehouseSearchResponse>("AddressGeneral/getWarehouses/", request); return(response.data); }
public async Task <WarehouseSearchResponse> Search(WarehouseSearchRequest request) { WarehouseSearchResponse response = new WarehouseSearchResponse(); try { List <WarehouseViewModel> warehouseViewModels = new List <WarehouseViewModel>(); RefSqlPaging paging = new RefSqlPaging(request.PageIndex, request.PageSize); var data = await _warehouseService.Search(request.Code, request.Email, request.Phone, request.Name, request.Status, request.Type, paging); var venderIds = data.Select(p => p.VendorId).ToArray(); Dictionary <string, string> vendorNameByIds = new Dictionary <string, string>(); if (venderIds.Length > 0) { var vendors = await _vendorService.GetFromDb(venderIds); vendorNameByIds = vendors.ToDictionary(p => p.Id, p => p.Name); } response.TotalRow = paging.TotalRow; foreach (var item in data) { //item.VendorName = dataVendor.Where(x => x.Id == item.VendorId.ToString()).FirstOrDefault().Name; var province = await _locationService.GetProvinceById(item.ProvinceId.ToString()); var district = await _locationService.GetDistrictById(item.DistrictId.ToString()); var village = await _locationService.GetWardById(item.VillageId.ToString()); RStreet road = await _locationService.GetStreetById(item.RoadId.ToString()); string venderName = string.Empty; if (!string.IsNullOrEmpty(item.VendorId)) { venderName = vendorNameByIds.ContainsKey(item.VendorId) ? vendorNameByIds[item.VendorId] : string.Empty; } var warehouseModel = item.ToModel(province.ProvinceName, district.DistrictName, village.WardName, road.StreetName, venderName); warehouseViewModels.Add(warehouseModel); } response.Warehouses = warehouseViewModels.ToArray(); response.PageIndex = request.PageIndex; response.PageSize = request.PageSize; response.SetSucess(); } catch (Exception e) { response.SetFail(e); _logger.LogError(e, e.Message, request); } return(response); }
public async Task <IActionResult> Index([FromBody] WarehouseSearchRequest request) { try { var response = await _warehouseAppService.Search(request); return(Json(response)); } catch (Exception e) { _logger.LogError(e, Common.Common.GetMethodName(), request); throw; } }
public async Task <WarehouseSearchItem[]> GetAllWarehousesAsync(CancellationToken cancellationToken) { var warehouses = GetCachedWarehouses(); if (warehouses == null) { var request = new WarehouseSearchRequest(null, null, null); var response = await SendRequestAsync <WarehouseSearchResponse>( "AddressGeneral/getWarehouses/", request, cancellationToken); warehouses = response.data; CacheWarehouses(warehouses); } return(warehouses); }