示例#1
0
        public async Task <BrandPaggingDTO> ElasticBrandSearch(int page, int pageSize, string search = "")
        {
            var output = new BrandPaggingDTO();
            //try
            //{
            //    var outSearchElastic = await _repoWrapper.Elastic.SearchProductBrandPagination(page, pageSize, search);
            //    output.PageSize = pageSize;
            //    output.CurrentPage = page;
            //    output.TotalRecord = (int)outSearchElastic.TotalRecord;
            //    output.TotalPage = (output.TotalRecord - 1) / pageSize + 1;
            //    output.Data = _mapper.Map<IEnumerable<ProductBrandSearchDTO>>(outSearchElastic.Brands);
            //    output.Data.ToList().ForEach(x => x.Description = HttpUtility.HtmlDecode(Common.CommonUtil.StripHTML(HttpUtility.HtmlDecode(x.Description))));
            //    output.Data.Select(c => { c.LocationName = Util.LocationDictionary[(int)c.LocationId]; return c; }).ToList();
            //}
            //catch (Exception ex)
            //{
            var result = await _repoWrapper.Brand.GetListBrandPagging(page, pageSize, null, 1, productCategoryId : null, keyword : search);

            int totalRow = result.Item1;

            output.PageSize    = pageSize;
            output.CurrentPage = page;
            output.TotalRecord = totalRow;
            output.TotalPage   = (totalRow - 1) / pageSize + 1;
            output.Data        = _mapper.Map <IEnumerable <ProductBrandSearchDTO> >(result.Item2);
            output.Data.ToList().ForEach(x => x.Description = HttpUtility.HtmlDecode(Common.CommonUtil.StripHTML(HttpUtility.HtmlDecode(x.Description))));
            output.Data.Select(c => { c.LocationName = Util.LocationDictionary[(int)c.LocationId]; return(c); }).ToList();
            return(output);

            //}
            return(output);
        }
示例#2
0
        public async Task <BrandPaggingDTO> GetListBrand(int?page, int?pageSize, int?LocationId, int active = 1, int?productCategoryId = null, string keyword = null)
        {
            var output = new BrandPaggingDTO();

            try
            {
                //var cacheKey = $"Brand_GetListBrand{productCategoryId}{keyword}";
                //var redisEncode = await _distributedCache.GetStringAsync(cacheKey);
                //if (redisEncode != null)
                //{
                //    output = JsonConvert.DeserializeObject<BrandPaggingDTO>(redisEncode);
                //}
                //else
                //{
                var result = await _repoWrapper.Brand.GetListBrandPagging(page ?? 1, pageSize ?? 20, LocationId, active, productCategoryId : productCategoryId, keyword);

                int totalRow = result.Item1;
                output.PageSize    = pageSize ?? 20;
                output.CurrentPage = page ?? 1;
                output.TotalRecord = totalRow;
                output.TotalPage   = (totalRow - 1) / pageSize ?? 20 + 1;
                output.Data        = _mapper.Map <IEnumerable <ProductBrandSearchDTO> >(result.Item2);
                output.Data.Select(c => { c.LocationName = Util.LocationDictionary[(int)c.LocationId]; return(c); }).ToList();

                // await _distributedCache.SetStringAsync(cacheKey, JsonConvert.SerializeObject(output), Utils.Util.RedisOptions());
                //}
            }
            catch (Exception ex)
            {
                _logger.LogError($"GetListBrand: " + ex.ToString());
            }
            return(output);
        }
示例#3
0
        public async Task <BrandPaggingDTO> SearchProductBrand(int page = 0, int pageSize = 20, string query = "")
        {
            var    output       = new BrandPaggingDTO();
            string apiUrl       = $"/api/v1/Search/ElasticBrandSearch";
            string paramRequest = $"?page={page}&pageSize={pageSize}&search={query}";
            var    response     = await _client.GetAsync(apiUrl + paramRequest);

            if (response.IsSuccessStatusCode)
            {
                string responseStream = await response.Content.ReadAsStringAsync();

                output = JsonConvert.DeserializeObject <BrandPaggingDTO>(responseStream);
            }
            return(output);
        }