Exemplo n.º 1
0
        public async Task <IActionResult> Checkout(CheckoutBindingModel checkoutBindingModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(checkoutBindingModel));
            }

            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            checkoutBindingModel.IssuerId = userId;

            // var pendingStatus = this.orderService.GetOrderStatusByName(GlobalConstants.PendingOrderStatus);
            checkoutBindingModel.OrderStatusId = this.orderService.GetOrderStatusIdByName(GlobalConstants.PendingOrderStatus);

            checkoutBindingModel.IssuedOn = DateTime.UtcNow;

            // var shoppingCartItems = await this.shoppingCartService.CheckOutGetCartItems(userId);
            checkoutBindingModel.TotalPrice = this.shoppingCartService.GetPriceOfAllShoppingCartItemsByUserId(userId);

            // shoppingCartItems.Sum(x => x.Recipe.Price);
            await this.orderService.Checkout <CheckoutBindingModel>(checkoutBindingModel, userId);

            await this.shoppingCartService.ClearShoppingCart(userId);

            return(this.Redirect("/"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Checkout()
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (!this.shoppingCartService.HasItemsInCart(userId))
            {
                return(this.Redirect("/"));
            }

            var model = new CheckoutBindingModel();

            model.FullName = this.User.FindFirstValue("FullName");
            var user = await this.userManager.GetUserAsync(this.User);

            model.PhoneNumber = await this.userManager.GetPhoneNumberAsync(user);

            model.DeliveryDate = DateTime.UtcNow.ToLocalTime();

            return(this.View(model));
        }