Esempio n. 1
0
        public async Task <IActionResult> ProductById(int categoryId)
        {
            var model  = new ProductByCategoryViewForDto();
            var serRes = await _productService.GetProductsByCategory(GetToken(), categoryId);

            if (serRes.ResultStatus.Status != Enums.ResultStatus.Success)
            {
                AddSweetAlert("Beklenmedik bir durum oluştu", serRes.ResultStatus.Explanation, Enums.NotificationType.warning);
                return(View(model));
            }

            model = serRes.Result;

            ViewBag.Title = $"{serRes.Result.CategoryName} Kategorisine Ait Ürünler";

            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> ProductsByCategory(int categoryId)
        {
            try
            {
                var model = new ProductByCategoryViewForDto
                {
                    Products     = new List <ProductViewForDto>(),
                    CategoryName = string.Empty
                };

                model.Products = _mapper.Map <List <ProductViewForDto> >(await _unitOfWork.ProductRepository.SearchBy(x => x.IsActive && x.CategoryId == categoryId, x => x.Category)).OrderByDescending(o => o.Id).ToList();

                // Products ların boş olma ihtimaline karşı özel olarak çekiliyor.
                model.CategoryName = _unitOfWork.CategoryRepository.GetById(categoryId).Result.Name;

                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }