public async Task <ActionResult> SubmitPaymentAction()
        {
            string apiUrl = "http://localhost:3000/PayForItem";

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(apiUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.GetAsync(apiUrl);

                if (response.IsSuccessStatusCode)
                {
                    var data = await response.Content.ReadAsStringAsync();

                    var parsedData = (JObject)JsonConvert.DeserializeObject(data);
                    var result     = parsedData["response"].ToString();

                    if (result.Equals("true"))
                    {
                        string       accountId = HttpContext.Session.GetString("username"); //session
                        ShoppingCart cart      = _shoppingCartRepository.GetShoppingCart(accountId);
                        _shoppingCartRepository.ClearCart(cart);
                        TempData["success"] = "Payment has been succesfull";
                        return(RedirectToAction("Index", "ShoppingCart"));
                    }
                }
            }

            TempData["error"] = "Payment failed. Try Again.";
            return(RedirectToAction("Index", "ShoppingCart"));
        }
Exemplo n.º 2
0
        public async Task <bool> CreateOrder(Order order)
        {
            var items = _shoppingCart.GetShoppingCartItems().ToList();

            if (items.Count != 0)
            {
                await _checkout.CreateOrder(order, items);

                await _shoppingCart.ClearCart();

                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public IActionResult Checkout(Order order)
        {
            if (shoppingCart.GetShoppingCartItems().Count == 0)
            {
                ModelState.AddModelError("empty", "Your cart is empty please add some pies first!");
            }
            if (ModelState.IsValid)
            {
                orderRepository.CreateOrder(order);
                shoppingCart.ClearCart();

                return(RedirectToAction("CheckoutComplete"));
            }
            return(View(order));
        }
Exemplo n.º 4
0
        public IActionResult Checkout(Order order)
        {
            var items = _shoppingCartRepository.GetShoppingCartItems();

            _shoppingCartRepository.ShoppingCartItems = items;

            if (_shoppingCartRepository.ShoppingCartItems.Count == 0)
            {
                ModelState.AddModelError("", "Your cart is empty, add some pies first");
            }

            if (ModelState.IsValid)
            {
                _orderRepository.CreateOrder(order);
                _shoppingCartRepository.ClearCart();
                return(RedirectToAction("CheckoutComplete"));
            }
            return(View(order));
        }
Exemplo n.º 5
0
 public ActionResult AddCart(OrderViewModel model)
 {
     try
     {
         HttpRequest cookie = services.GetRequiredService <IHttpContextAccessor>()?.HttpContext.Request;
         string      cartId = cookie.Cookies["cardId"];
         Cart        cart   = cartRepository.Get(cartId);
         cart.CustomerId = model.CustomerId;
         cart.CreateAt   = DateTime.UtcNow;
         cart.Total     += shoppingCart.GetShoppingCartTotal(cartId);
         cartRepository.Update(cart);
         cartRepository.Save();
         shoppingCart.ClearCart(cookie.Cookies["cardId"]);
         return(View());
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 6
0
        public async Task <IActionResult> CheckoutAsync(Order order)
        {
            var shoppingCart = await _shoppingCartRepository.GetCartAsync();

            var items = _shoppingCartRepository.GetShoppingCartItems();

            shoppingCart.ShoppingCartItems = items;

            if (shoppingCart.ShoppingCartItems.Count == 0)
            {
                ModelState.AddModelError("", "Your cart is empty, add some pies first");
            }

            if (ModelState.IsValid)
            {
                await _orderRepository.CreateOrderAsync(order);

                _shoppingCartRepository.ClearCart();
                return(RedirectToAction("CheckoutComplete"));
            }

            return(View("Checkout", order));
        }
Exemplo n.º 7
0
 public void ClearCart(string email)
 {
     _shoppingCartRepository.ClearCart(email);
 }
Exemplo n.º 8
0
 public async Task ClearCart()
 {
     await _shoppingCartRepository.ClearCart();
 }
Exemplo n.º 9
0
 public async Task ClearCart(string shoppingCartId)
 {
     await _shoppingCartRepository.ClearCart(shoppingCartId);
 }
Exemplo n.º 10
0
        public Order CreateOrder(Order order)
        {
            var customLunch = _cartRepository.GetSessionLunchIfNotEmpty(order.BookingId);

            if (customLunch != null)
            {
                _lunchRep.SaveLunch(order.BookingId);
                _cartRepository.AddCateringToOrder(customLunch);
            }

            order.BookingId        = order.BookingId ?? _cartRepository.GetSessionCartId();
            order.PhoneNumber      = order.Registration?.PhoneNumber;
            order.OrderTotal       = _cartRepository.GetTotal(order.BookingId);
            order.Discount         = _cartRepository.GetDiscount(order.BookingId);
            order.DeliveryAddress  = _cartRepository.GetDelivery(order.BookingId);
            order.CustomerComments = _cartRepository.GetComments(order.BookingId)?.Comments;
            order.PreparationTime  = _cartRepository.GetPreparationTime(order.BookingId);
            order.PickUpTime       = _calendarRepository.GetPickupEstimate(order.PreparationTime);
            order.OrderPlaced      = _calendarRepository.LocalTime();
            order.PickedUp         = false;

            var pickUpTime = _cartRepository.GetPickUpDate(order.BookingId);

            order.PickUpTimeFrom           = pickUpTime.From;
            order.TimeLeftUntilStoreCloses = pickUpTime.To;

            _appDbContext.Orders.Add(order);
            _appDbContext.SaveChanges();

            /**********************/

            var shoppingItems = _cartRepository.GetItems(order.BookingId);

            _appDbContext.OrderDetails.AddRange(shoppingItems.Select(x => new OrderDetail()
            {
                Amount  = x.Amount,
                PieId   = x.Pie.PieId,
                OrderId = order.OrderId,
                Price   = x.Pie.Price
            }));
            _appDbContext.SaveChanges();

            /**********************/

            var shoppingProductItems = _cartRepository.GetCatalogItems(order.BookingId);

            _appDbContext.OrderCatalogItems.AddRange(shoppingProductItems.Select(x => new OrderCatalogItem()
            {
                Amount    = x.Amount,
                Price     = x.Product.Price,
                OrderId   = order.OrderId,
                ProductId = x.Product.ProductId,
                Product   = x.Product
            }));
            _appDbContext.SaveChanges();

            /**********************/

            var shoppingLunches = _cartRepository.GetShoppingCaterings(order.BookingId).Select(x => _mapper.Map <ShoppingCartComboCatering, OrderCatering>(x)).ToList();

            foreach (var lunch in shoppingLunches)
            {
                lunch.Order   = order;
                lunch.OrderId = order.OrderId;
            }
            _appDbContext.OrderCaterings.AddRange(shoppingLunches);
            _appDbContext.SaveChanges();

            /**********************/

            _cartRepository.ClearCart(order.BookingId);

            return(order);
        }
Exemplo n.º 11
0
 public void ClearCart(IShoppingCart cart)
 {
     _shoppingCartRepository.ClearCart(cart);
 }