Exemple #1
0
 private void btnAllClear_Click(object sender, EventArgs e)
 {
     labelMeat.Text       = "";
     labelFruit.Text      = "";
     labelTotalPrice.Text = "";
     cartMeat.ClearCart();
     cartFruit.ClearCart();
 }
        public async Task <bool> Handle(PlaceOrderCommand request, CancellationToken cancellationToken)
        {
            IEnumerable <Game> cartItems = _cartService.GetGames(request.UserCartID);

            var user = await _userManager.FindByIdAsync(request.UserID);

            var itemsOwner = await _userManager.FindByIdAsync(cartItems.First().OwnerID);

            var totalPrice = CalculateTotalPrice(cartItems);

            request.OrderModel.Placed      = DateTime.UtcNow;
            request.OrderModel.TotalPrice  = totalPrice;
            request.OrderModel.Email       = (string.IsNullOrEmpty(request.OrderModel.AlternativeEmailAdress)) ? user.Email : request.OrderModel.AlternativeEmailAdress;
            request.OrderModel.PhoneNumber = (string.IsNullOrEmpty(request.OrderModel.AlternativePhoneNumber)) ? user.PhoneNumber : request.OrderModel.AlternativePhoneNumber;

            var result  = _mapper.Map <Order>(request.OrderModel);
            var orderID = _dbContext.Orders.Last().ID;

            string gameTitles = string.Empty;

            foreach (var item in cartItems)
            {
                gameTitles = gameTitles.Concat(item.Title).ToString();
                _dbContext.OrderItems.Add(new OrderItem
                {
                    GameID  = item.ID,
                    CartID  = user.CartID,
                    OrderID = orderID
                });
            }

            var message = new GamingShop.Data.Models.Message
            {
                Content        = $"Ordered items: {gameTitles}",
                RecipientEmail = itemsOwner.Email,
                RecipientID    = itemsOwner.Id,
                SenderID       = user.Id,
                Sent           = DateTime.UtcNow,
                Subject        = $"A {user.UserName} ordered your game(s)"
            };

            _dbContext.Messages.Add(message);

            await _emailSender.SendOrderDetailsEmail(request.OrderModel.Email, "Order", cartItems, new Address { Street = request.OrderModel.Street, City = request.OrderModel.City, Country = request.OrderModel.Country, PhoneNumber = request.OrderModel.PhoneNumber }, totalPrice);

            await _emailSender.SendEmail(message);

            await _cartService.ClearCart(request.UserCartID);

            await _orderService.MarkGameAsSold(cartItems);

            if (await _dbContext.SaveChangesAsync() > 0)
            {
                return(true);
            }

            return(false);
        }
 private static void ProcessCart(ICart cart)
 {
     Console.WriteLine($"{cart.TotalItems} items in cart:");
     foreach (var item in cart.Items)
     {
         Console.WriteLine($"{item.Name}: ${item.Price}");
     }
     cart.ClearCart();
     Console.WriteLine("Total price: "); // TODO
 }
Exemple #4
0
 public static void ClearCart(int userID)
 {
     if (userID > 0)
     {
         dal.ClearCart(userID);
     }
     else
     {
         CartHelper.ClearCart();
     }
 }
Exemple #5
0
        public IActionResult ClearCart()
        {
            var login = jwtHelper.GetClaimsFromToken()
                        .Claims.Single(x => x.Type == "login")
                        .Value;

            cart.ClearCart(login);
            var response = cart.GetCart(login);

            return(new JsonResult(response));
        }
Exemple #6
0
        public async Task <Guid> CreateOrder(string login)
        {
            var userCart = cart.GetCart(login);

            if (!userCart.Any())
            {
                throw new NotFoundException(AppErrorCodes.EmptyCart, "Cart in empty");
            }

            var userId = (await userService.Get(login)).UserId;
            var order  = new Order(userId);

            foreach (var cartPosition in userCart)
            {
                if (cartPosition.Book.NumberOfPieces < cartPosition.NumberOfBooks)
                {
                    throw new NotFoundException($"Book '{cartPosition.Book.Title}' is not available");
                }

                order.BooksInOrder.Add(new BookInOrder(
                                           order.OrderId,
                                           cartPosition.Book.BookId,
                                           cartPosition.NumberOfBooks,
                                           cartPosition.Book,
                                           order));

                cartPosition.Book.DecreaseAmount(cartPosition.NumberOfBooks);
            }

            await orderRepository.AddOrder(order);

            cart.ClearCart(login);
            await orderRepository.SaveChanges();

            return(order.OrderId);
        }
Exemple #7
0
        public async Task <JsonResult> ClearCart(string reference)
        {
            await _cart.ClearCart(reference);

            return(Json("Proccess completed successfuly", JsonRequestBehavior.AllowGet));
        }