public async Task <IActionResult> OnPostAsync(
            [FromServices] UpdateCart updateCart)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var userId = User?.Claims?.FirstOrDefault(x => x.Type.Equals(ClaimTypes.NameIdentifier))?.Value;
            await updateCart.Do(userId, cart =>
            {
                cart.Name     = Form.Name;
                cart.Email    = Form.Email;
                cart.Phone    = Form.Phone;
                cart.Address1 = Form.Address1;
                cart.Address2 = Form.Address2;
                cart.City     = Form.City;
                cart.Country  = Form.Country;
                cart.PostCode = Form.PostCode;
                cart.State    = Form.State;
                cart.DeliveryInformationComplete = true;
            });

            return(RedirectToPage("/Checkout/Payment"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateCart(
            [FromBody] UpdateCart.Form request,
            [FromServices] UpdateCart updateCart)
        {
            var userId = User?.Claims?.FirstOrDefault(x => x.Type.Equals(ClaimTypes.NameIdentifier))?.Value;

            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest("Cookie Policy not accepted"));
            }

            request.UserId = userId;
            var result = await updateCart.Do(request);

            if (result.Success)
            {
                return(Ok(result.Message));
            }

            return(BadRequest(result.Message));
        }