예제 #1
0
 public async Task <T> Checkout <T>(CartHeaderDto cartHeader, string token = null)
 {
     return(await this.SendAsync <T>(new ApiRequest()
     {
         ApiType = SD.ApiType.POST,
         Data = cartHeader,
         Url = SD.ShoppingCartAPIBase + "/api/cart/checkout",
         AccessToken = token
     }));
 }
예제 #2
0
        public async Task <IActionResult> DetailsPost(ProductDto productDto)
        {
            CartDto cartDto = new()
            {
                CartHeader = new CartHeaderDto
                {
                    UserId = User.Claims.Where(u => u.Type == "sub")?.FirstOrDefault()?.Value
                }
            };

            CartDetailsDto cartDetails = new CartDetailsDto()
            {
                Count     = productDto.Count,
                ProductId = productDto.ProductId
            };

            var resp = await _productService.GetProductByIdAsync <ResponseDto>(productDto.ProductId, "");

            if (resp != null && resp.IsSuccess)
            {
                cartDetails.Product = JsonConvert.DeserializeObject <ProductDto>(Convert.ToString(resp.Result));
            }
            List <CartDetailsDto> cartDetailsDtos = new();

            cartDetailsDtos.Add(cartDetails);
            cartDto.CartDetails = cartDetailsDtos;

            var accessToken = await HttpContext.GetTokenAsync("access_token");

            var addToCartResp = await _cartService.AddToCartAsync <ResponseDto>(cartDto, accessToken);

            if (addToCartResp != null && addToCartResp.IsSuccess)
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(View(productDto));
        }