public async Task <IActionResult> AddBasketItem(string courseId)
        {
            var course = await _catalogService.GetByCourseId(courseId);

            var basketItem = new BasketItemViewModel {
                CourseId = course.Id, CourseName = course.Name, Price = course.Price
            };

            await _basketService.AddBasketItem(basketItem);

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult AddBasketItem(string clientId, string basketId, string itemId, string name, string description, string specification,
                                           string comment, float unitPrice, int quantity, float discount)
        {
            BasketItemModel basketItemModel = new BasketItemModel();

            basketItemModel.Id            = itemId;
            basketItemModel.Name          = name;
            basketItemModel.Description   = description;
            basketItemModel.Specification = specification;
            basketItemModel.Comment       = comment;
            basketItemModel.UnitPrice     = unitPrice;
            basketItemModel.Quantity      = quantity;
            basketItemModel.Discount      = discount;

            bool isAdded = _basketService.AddBasketItem(clientId, basketId, basketItemModel);

            return(new JsonResult(isAdded));
        }
Beispiel #3
0
        public ActionResult AddGameToBasket(string key, int quantity = 1)
        {
            GameModel   gameModel   = _gameService.GetGameModelByKey(key);
            string      sessionKey  = Session.SessionID;
            BasketModel basketModel = _basketService.GetBasketModelForUser(sessionKey);

            var basketItemModel = new BasketItemModel
            {
                BasketId = basketModel.BasketId,
                Quantity = quantity,
                Price    = gameModel.Price,
                Discount = 0,
                GameId   = gameModel.GameId,
                Game     = Mapper.Map <GameModel>(gameModel)
            };

            _basketService.AddBasketItem(basketItemModel);

            MessageSuccess("The game has been added to your basket.");
            return(RedirectToAction("Get", "Basket"));
        }
Beispiel #4
0
        public ActionResult <Basket> Post([FromBody] AddBasketItem basketItem)
        {
            var serviceResult = _basketService.AddBasketItem(basketItem.ProductId, basketItem.Quantity);

            if (serviceResult.ResponseCode != ResponseCode.Success)
            {
                return(BadRequest(serviceResult.Error));
            }
            var result = new BasketDto
            {
                Id      = serviceResult.Result.Id,
                BuyerId = serviceResult.Result.BuyerId,
                Total   = serviceResult.Result.Total,
                Items   = serviceResult.Result.Items.Select(x => new BasketItemDto
                {
                    Price    = x.Price,
                    Quantity = x.Quantity,
                    Id       = x.Id,
                    Name     = x.Name
                })
            };

            return(Ok(result));
        }