async Task ApplyBrandsFilter(BrandListQueryModel model)
        {
            queryModel.ActiveOnly = model.ActiveOnly;
            queryModel.Query      = model.Query;

            await LoadBrands(queryModel);
        }
        public IActionResult Get([FromQuery] BrandListQueryModel queryModel)
        {
            var model = ControllerServices.GetBrands(queryModel);

            _logger.LogInformation("Found {itemsNumber} brands of {itemsTotal}", model.Items.Count(), model.Total);

            return(Ok(model));
        }
        public async Task <BrandListModel> GetBrands(BrandListQueryModel queryModel)
        {
            var url = UrlBuilder.BrandListUrl(queryModel);

            var brands = await Client.GetFromJsonAsync <BrandListModel>(url);

            return(brands);
        }
        async Task LoadBrands(BrandListQueryModel queryModel = null)
        {
            loading = true;

            try
            {
                brands = await Client.GetBrands(queryModel);
            }
            finally
            {
                StateHasChanged();
                loading = false;
            }
        }
Beispiel #5
0
        public string BrandListUrl(BrandListQueryModel queryModel)
        {
            var url = $"{ApiPrefix}/{ResourceName}";

            if (queryModel != null)
            {
                url = $"{url}?activeOnly={queryModel.ActiveOnly}&page={queryModel.Page}&size={queryModel.Size}";
                if (!string.IsNullOrWhiteSpace(queryModel.Query))
                {
                    url = $"{url}&query={HttpUtility.UrlEncode(queryModel.Query)}";
                }
            }

            return(url);
        }
        public BrandListModel GetBrands(BrandListQueryModel queryModel)
        {
            if (queryModel is null)
            {
                queryModel = new BrandListQueryModel();
            }

            var brandsQuery = Database.Brands;

            if (queryModel.ActiveOnly)
            {
                brandsQuery = brandsQuery.Active();
            }
            if (!string.IsNullOrWhiteSpace(queryModel.Query))
            {
                brandsQuery = brandsQuery.Where(b => b.Name.Contains(queryModel.Query) || b.Description.Contains(queryModel.Query));
            }

            int skip = (queryModel.Page - 1) * queryModel.Size;

            int total = brandsQuery.Count();
            var items = brandsQuery
                        .OrderBy(b => b.Name)
                        .Select(b => new BrandListModel.ListItem
            {
                Id          = b.Id,
                Description = b.Description,
                Name        = b.Name,
                Url         = b.Url,
                Deleted     = b.Deleted
            }).Skip(skip).Take(queryModel.Size).ToArray();

            double pages = total / queryModel.Page;

            var model = new BrandListModel
            {
                Total       = total,
                CurrentPage = pages == 0 ? 0 : queryModel.Page,
                TotalPages  = Convert.ToInt32(Math.Ceiling(pages)),
                Items       = items
            };

            return(model);
        }
 public Brands()
 {
     queryModel = new BrandListQueryModel();
     loading    = false;
 }
 async Task ClearFilters()
 {
     Model = new BrandListQueryModel();
     await OnBrandsFiltered.InvokeAsync(Model);
 }