コード例 #1
0
        public async Task <IActionResult> Add(int?id)
        {
            var user = await _userManager.FindByEmailAsync(User.Identity.Name);

            Product product = _robotoRepo.GetProductById(id).Result;
            Basket  basket  = await _basketRepo.GetUserBasketByEmail(user.Email);

            if (basket == null)
            {
                Basket datBasket = new Basket
                {
                    CustomerEmail = user.Email
                };
                await _basketRepo.CreateBasket(datBasket);
            }

            await _basketRepo.AddProductToBasket(user.Email, product);

            return(RedirectToAction(nameof(MyBasket)));
        }