Exemplo n.º 1
0
        public async Task <IActionResult> AddtoCart()
        {
            var accessToken = await HttpContext.GetTokenAsync("access_token");

            _apiClient.SetBearerToken(accessToken);

            var value = (string)TempData["added_movie"];
            var movie = JsonConvert.DeserializeObject <Movie>(value);

            if (movie?.ID != null)
            {
                var user   = HttpContext.User;
                var basket = await _basketSvc.GetorCreateBasket(user.Claims.Where(c => c.Type == "name").First().Value, _apiClient);

                foreach (var item in basket.Items)
                {
                    if (item.Id.Equals(movie.ID))
                    {
                        return(RedirectToAction("Index", "Movies"));
                    }
                }
                _basketSvc.AddItemtoBasket(basket, movie);
                await _basketSvc.UpdateBasket(basket, _apiClient);
            }
            return(RedirectToAction("Index", "Movies"));
        }