public ActionResult Store(string categoryId = "")
        {
            ViewBag.Message     = "Your contact page.";
            ViewBag.CateList    = _categoryProductRepository.GetAll();
            ViewBag.lstCatePost = _postRepository.GetPost_Category();
            IList <Product> products = null;

            if (string.IsNullOrEmpty(categoryId))
            {
                ViewBag.CategoryName = "Tất cả sản phẩm";
                products             = _productRepository.GetAll();
            }
            else
            {
                products = _productRepository.GetByCategory(categoryId);
                var category = _categoryProductRepository.Find(categoryId);
                ViewBag.CategoryName = category.CategoryName;
            }
            return(View(products));
        }
Beispiel #2
0
        public async Task Handle(CategoryCreateEvent @event)
        {
            try
            {
                var categoryEvent = @event.CategoryEvent;

                var categoryProduct = new CategoryProduct(categoryEvent.Id, categoryEvent.Name, categoryEvent.Image, categoryEvent.CreatedAt);

                var result = await _categoryProductRepository.GetCategoryProductsByDocumentId(categoryEvent.Id);

                if (result == null)
                {
                    _categoryProductRepository.Add(categoryProduct);

                    await _unitOfWork.Commit();

                    var categoryProducts = await _categoryProductRepository.GetAll();

                    var categories = categoryProducts.Where(x => x.Status == "A")
                                     .GroupBy(g => g.Name)
                                     .Select(s => new CategoryResponse
                    {
                        Id    = s.FirstOrDefault().Id,
                        Name  = s.FirstOrDefault().Name,
                        Image = s.FirstOrDefault().Image
                    }).ToList();

                    if (categories.Any())
                    {
                        _categoryRedisRepository.Remove(KEY_CACHE, (int)RedisBase.Category);
                    }

                    _categoryRedisRepository.Set(KEY_CACHE, categories, (int)RedisBase.Category);
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #3
0
        public async Task <ActionResult> Get()
        {
            try
            {
                var categories = await _categoryRedis.Get <List <CategoryResponse> >(KEY_CACHE, (int)RedisBase.Category, true);

                if (categories != null)
                {
                    return(Ok(categories));
                }
                else
                {
                    var categoryProducts = await _categoryProductRepository.GetAll();

                    var response = categoryProducts.GroupBy(g => g.Name)
                                   .Select(s => new CategoryResponse
                    {
                        Id   = s.FirstOrDefault().Id,
                        Name = s.FirstOrDefault().Name
                    }).ToList();

                    if (categoryProducts.Any())
                    {
                        _categoryRedis.Remove(KEY_CACHE, (int)RedisBase.Category);
                    }

                    _categoryRedis.Set(KEY_CACHE, response, (int)RedisBase.Category);

                    return(Ok(response));
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex.Message);
                return(BadRequest());
            }
        }
Beispiel #4
0
 // GET: Identity/Products/Create
 public ActionResult Create()
 {
     ViewBag.CategoryId = new SelectList(_categoryProductRepository.GetAll(), "CategoryProductId", "CategoryName");
     return(View());
 }
Beispiel #5
0
 public async Task <IEnumerable <CategoryProductDto> > GetAllCategories() => _mapper.Map((await _categoryProductRepository.GetAll()).OrderBy(x => x.Name), new List <CategoryProductDto>());