Пример #1
0
        public async Task <IActionResult> OnPostCheckoutAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var order = await orderService.PurchaseOrder(HttpContext.Session.GetString(Constants.CartId));

            if (order != null)
            {
                if (await emailSender.Send(Constants.OrderCompletedEmail
                                           (
                                               HttpContext.IsAuthenticated() ? order.OrderDetails.CustomerEmail : CheckoutOrderModel.AnonymousEmail,
                                               order.Id, order.OrderDetails.BookingId, order.OrderDetails.OfferTitle,
                                               order.TotalPrice, order.OrderDetails.StartDate, order.OrderDetails.EndDate, order.OrderDetails.Phone,
                                               order.OrderDetails.ContactEmail, order.OrderDetails.Location
                                           )))
                {
                    Log.Information($"User #{HttpContext.GetCurrentUserId()} completed order for offer {order.OrderDetails.OfferTitle} [Order #{order.Id}]");
                    return((IActionResult)RedirectToPage("/MyBookings", new { area = "Bookings" }));
                }

                Alertify.Push("Order has been completed but email cannot be sent. Please contact MyBooking team", AlertType.Warning);
                return(await this.OnGetAsync());
            }

            return(this.ErrorPage());
        }