Esempio n. 1
0
        public async Task <ActionResult> AddToBasketAsync([FromBody] BasketDto basketDto)
        {
            try
            {
                await _basketService.AddToBasketAsync(basketDto);

                return(Created("Item added to basket.", basketDto));
            }
            catch (Exception ex)
            {
                return(BadRequest($"{ex.Message} \n {ex.InnerException.Message}"));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Add(int?productId)
        {
            if (!productId.HasValue)
            {
                ViewBag.BadRequestMassage = "Product Id can not be NULL";
                return(View("BadRequest"));
            }

            try
            {
                User user = await _userManager.GetUserAsync(User);

                await _basketService.AddToBasketAsync(productId.Value, user);

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e));
            }
        }