Beispiel #1
0
        public async Task <IActionResult> ProductByCategory(int id)
        {
            var result = await _productApiClient.GetProductsByCategoryId(id);

            ViewBag.CategoryName = _categoryApiClient.GetCategories().Result.Where(x => x.Id == id).Select(x => x.CategoryName).First();
            return(View(result));
        }
Beispiel #2
0
        public async Task <IActionResult> Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                var categories = await _categoryApiClient.GetCategories();

                return(View(categories));
            }
            return(View());
        }
        public async Task <IActionResult> GetCategories(CancellationToken cancellationToken)
        {
            var response = await _categoryApiClient.GetCategories(HttpContext, cancellationToken);

            _responseConfigurator.Apply(response, Response);

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            var categories = JsonSerializer.Deserialize <IEnumerable <Category> >(content);

            return(new JsonResult(categories));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var categories = await _categoryApiClient.GetCategories();

            var popularKnowledgeBases = await _knowledgeBaseApiClient.GetPopularKnowledgeBases(4);

            var recentComments = await _knowledgeBaseApiClient.GetRecentComments(4);

            var viewModel = new SideBarViewModel()
            {
                Categories            = categories,
                PopularKnowledgeBases = popularKnowledgeBases,
                RecentComments        = recentComments
            };

            return(View("Default", viewModel));
        }
Beispiel #5
0
        private async Task SetCategoriesViewBag(int?selectedValue = null)
        {
            var categories = await _categoryApiClient.GetCategories();

            var items = categories.Select(i => new SelectListItem()
            {
                Text  = i.Name,
                Value = i.Id.ToString(),
            }).ToList();

            items.Insert(0, new SelectListItem()
            {
                Value = null,
                Text  = "--Chọn danh mục--"
            });
            ViewBag.Categories = new SelectList(items, "Value", "Text", selectedValue);
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var categories = await _categoryApiClient.GetCategories();

            return(View(categories));
        }