Пример #1
0
        // Returns basket items count. Retusn 0 if basket does not exist.
        public async Task <BasketItemsCountViewModel> GetBasketItemsCountViewModel(int?basketId = null)
        {
            var vm = new BasketItemsCountViewModel();

            if (!basketId.HasValue)
            {
                string buyerId = GetBuyerId();
                if (buyerId == null)
                {
                    return(vm);
                }
                var spec   = new BasketSpecification(buyerId);
                var basket = await _basketRepository.FirstOrDefaultAsync(spec);

                if (basket == null)
                {
                    return(vm);
                }
                basketId = basket.Id;
            }

            vm.BasketItemsCount = await _basketService.BasketItemsCount(basketId.Value);

            return(vm);
        }
Пример #2
0
        public async Task <BasketItemsCountViewModel> GetBasketItemsCountViewModel(int?basketId = null)
        {
            var vm = new BasketItemsCountViewModel();

            if (!basketId.HasValue)
            {
                //sepet yoksa oluşturma sıfır döndür Returns basket item count ,returns 0 if basket does not exist.
                string buyerId = GetBuyerId();
                if (buyerId == null)
                {
                    return(vm);
                }
                var spec   = new BasketSpecification(buyerId);
                var basket = await _basketRepository.FirstOrDefaultAsync(spec);

                if (basket == null)
                {
                    return(vm);
                }
                basketId = basket.Id;
            }

            //basketId değeri yoksa 0 döndürür varsa basketId değerini döndürür
            vm.BasketItemsCount = await _basketService.BasketItemsCount(basketId.Value);

            return(vm);

            //return new BasketItemsCountViewModel()
            //{
            //    BasketItemsCount = await _basketService.BasketItemsCount(basketId)
            //};
        }
Пример #3
0
        public async Task <IActionResult> AddToBasket(int productId, int quantity)
        {
            // application core projesinde BasketService:IBasketService
            //AddItemToBasket(int basketId, int catologId,int quantity)
            //sepette varsa adedini güncelle yoksa ekle
            //sepetteki öğe sayısını döndür

            var basketId = await _basketViewModelService.GetOrCreateBasketIdAsync();

            await _basketService.AddItemToBasket(basketId, productId, quantity);

            int basketItemsCount = await _basketService.BasketItemsCount(basketId);

            return(Json(await _basketViewModelService.GetBasketItemsCountViewModel(basketId)));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            //get logged in user id
            string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            //if not logged in, get anonymous user id from cookies
            if (userId == null)
            {
                userId = Request.Cookies[Constants.BASKET_COOKIENAME];
            }
            //if user id not exists, return 0 (it means there is no basket)
            if (userId == null)
            {
                return(Content("0"));
            }
            //if userId exists,get basket items count
            int count = await _basketService.BasketItemsCount(userId);

            return(Content(count.ToString()));
        }