Exemple #1
0
 public CartWindow()
 {
     InitializeComponent();
     bookCart         = new BookCart();
     dsBookCar        = bookCart.loadCart(user.UserID);
     this.DataContext = dsBookCar.Tables["Cart"];
 }
        /// <summary>
        /// Remove book from the cart asynchronously
        /// </summary>
        /// <param name="userID">unique user Id</param>
        /// <param name="bookID">unique book Id</param>
        /// <returns>book cart object</returns>
        public async Task <BookCart> RemoveBookAsync(string userID, string bookID)
        {
            BookCart bookCart = null;

            try
            {
                var bookStore = new BookStoreHelper();
                var customer  = bookStore.GetCustomer(userID);
                var book      = await bookStore.SearchBookById(bookID);

                if (customer != null && book != null)
                {
                    customer.BookCart.RemoveBook(new BookCartItem {
                        Book = book
                    });
                    bookCart = customer.BookCart;
                }
            }
            catch
            {
                // Log the exception
            }

            return(bookCart ?? new BookCart());
        }
Exemple #3
0
        public async Task <ActionResult> Details(BookCart bookCart)
        {
            bookCart.Id = 0;
            if (ModelState.IsValid)
            {
                var claimsIdentity = (ClaimsIdentity)User.Identity;
                var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
                bookCart.AppUserId = claim.Value;

                // u cant borrow the same book many times
                var borrowedBook = await _bookCartRepository.GetAll().Where(b => b.BookId == bookCart.BookId).ToListAsync();

                if (borrowedBook.Count == 0)
                {
                    // borrow book
                    await _bookCartRepository.Insert(bookCart);

                    await _bookRepository.ChangeBookStatus(bookCart.BookId);
                }
                else
                {
                    await _bookRepository.ChangeBookStatus(bookCart.BookId);

                    //TODO: Notification this book has already been rented by someone
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Exemple #4
0
 public Cart(UserData u)
 {
     InitializeComponent();
     this.user        = u;
     bookCart         = new BookCart();
     dsBookCar        = bookCart.loadCart(user.UserID);
     this.DataContext = dsBookCar.Tables["Cart"];
     cart_val.Text    = "" + bookCart.cartItems(user.UserID);
 }
Exemple #5
0
 private void AddBook(object obj)
 {
     if (SelectedBook.IsBorrowed)
     {
         return;
     }
     BookCart.Add(SelectedBook);
     BookCode = "";
 }
Exemple #6
0
        public Store(UserData u)
        {
            InitializeComponent();
            this.user   = u;
            bookCatalog = new BookCatalog();
            bookCart    = new BookCart();

            dsBookCat        = bookCatalog.GetBookInfo();
            this.DataContext = dsBookCat.Tables["Category"];
            cart_val.Text    = "" + bookCart.cartItems(user.UserID);
        }
Exemple #7
0
        public Item(UserData u, string i)
        {
            InitializeComponent();
            this.user = u;
            this.isbn = i;
            bookItem  = new BookCatalog();
            bookCart  = new BookCart();

            dsBookItem       = bookItem.load_Item(isbn);
            this.DataContext = dsBookItem.Tables["Item"];
            cart_val.Text    = "" + bookCart.cartItems(user.UserID);
        }
Exemple #8
0
        public async Task <IActionResult> Details(int id)
        {
            var book = await _bookRepository.GetFirstOrDefaultWithProperties(u => u.Id == id, includeProperties : "Category");

            var bookCart = new BookCart()
            {
                Book   = book,
                BookId = book.Id
            };

            return(View(bookCart));
        }
Exemple #9
0
        public Checkout(UserData u, List <List <string> > b)
        {
            InitializeComponent();
            this.user  = u;
            this.books = b;
            cart       = new BookCart();
            UserControl usc = new Store(user);
            int         a   = cart.colSum(user.UserID);

            total = a;
            label_Copy.Content = "Total:$ " + a;
        }
Exemple #10
0
        public Dashboard(UserData u)
        {
            InitializeComponent();
            this.user   = u;
            bookHistory = new BookCatalog();
            bookCart    = new BookCart();

            dsBookHistory       = bookHistory.load_History(user.UserID);
            this.DataContext    = dsBookHistory.Tables["History"];
            cart_val.Content    = "" + bookCart.cartItems(user.UserID);
            total_books.Content = "" + bookCart.totalBooks(user.UserID);
            total_money.Content = "$" + bookCart.totalPrice(user.UserID);
        }
Exemple #11
0
        /// <summary>
        /// Create order asynchronously
        /// </summary>
        /// <param name="userID">unique user Id</param>
        /// <param name="bookCart">book cart object</param>
        /// <returns>json order details object</returns>
        public async Task <ActionResult> CreateOrderAsync(string userID, BookCart bookCart)
        {
            try
            {
                var client = new BookstoreServiceClient();
                var result = await client.CreateOrderAsync(userID, bookCart);

                return(Json(result));
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemple #12
0
 private void CloseScreen(object obj = null)
 {
     if (BookCode.Length > 0)
     {
         BookCode = "";
     }
     else if (Barcode.Length > 0)
     {
         BookCart.Clear();
         BookCode = "";
         Barcode  = "";
         Borrower = null;
     }
     else
     {
         Messenger.Default.Broadcast(Messages.HOME_CloseScreen);
     }
 }
Exemple #13
0
 private void TakeoutBooks(object obj)
 {
     foreach (var book in BookCart)
     {
         var to = new Takeout()
         {
             UserId           = 0,//Session.Current.User.Id,
             BookId           = book.Id,
             BorrowerId       = Borrower.Id,
             TakeOutCondition = book.Condition,
         };
         to.Save();
         book.Update(nameof(Book.TakeoutId), to.Id);
     }
     BookCart.Clear();
     BookCode = "";
     Barcode  = "";
     Borrower = null;
     Messenger.Default.Broadcast(Messages.TakeoutsChanged);
 }
        /// <summary>
        /// Create order asynchronously
        /// </summary>
        /// <param name="userID">unique user Id</param>
        /// <param name="bookCart">book cart object</param>
        /// <returns>order details</returns>
        public async Task <OrderDetails> CreateOrderAsync(string userID, BookCart bookCart)
        {
            OrderDetails orderDetails = null;

            try
            {
                var bookStore = new BookStoreHelper();
                var customer  = bookStore.GetCustomer(userID);
                customer.BookCart = bookCart;

                if (customer != null && bookCart != null)
                {
                    orderDetails = await customer.PlaceOrder();;
                }
            }
            catch
            {
                // Log the exception
            }

            return(orderDetails ?? new OrderDetails());
        }
Exemple #15
0
 public CheckoutWindow()
 {
     InitializeComponent();
     cart = new BookCart();
 }
Exemple #16
0
        public async Task PlaceOrder()
        {
            // Clear the cache
            Cache.Clear();

            var bookStoreHelper = new BookStoreHelper();
            var bookAsync1      = await bookStoreHelper.SearchBooksAsync("title eq 'Mastering едц'");

            var bookAsync2 = await bookStoreHelper.SearchBooksAsync("author eq 'Cunning Bastard'");

            var bookAsync3 = await bookStoreHelper.SearchBooksAsync("title eq 'Generic Title'");

            var bookAsync4 = await bookStoreHelper.SearchBooksAsync("title eq 'How To Spend Money'");

            var book1 = bookAsync1.First();
            var book2 = bookAsync2.First();
            var book3 = bookAsync3.First();
            var book4 = bookAsync4.First();

            var bookCartItem1 = new BookCartItem {
                Book = book1, Quantity = 5
            };
            var bookCartItem2 = new BookCartItem {
                Book = book2, Quantity = 2
            };
            var bookCartItem3 = new BookCartItem {
                Book = book3, Quantity = 3
            };
            var bookCartItem4 = new BookCartItem {
                Book = book4, Quantity = 2
            };

            // Add books to the cart
            var bookCart = new BookCart();

            bookCart.AddBook(bookCartItem1);
            bookCart.AddBook(bookCartItem2);
            bookCart.AddBook(bookCartItem3);
            bookCart.AddBook(bookCartItem4);

            // Test empty cart
            var customer = bookStoreHelper.GetCustomer("dummy");
            await Assert.ThrowsExceptionAsync <DataException>(() => customer.PlaceOrder());

            // Create customer order (combination of In-stock and not In-stock)
            customer          = bookStoreHelper.GetCustomer("dummy");
            customer.BookCart = bookCart;
            var orderDetails = await customer.PlaceOrder();

            Assert.AreEqual(4, orderDetails.PurchasedBooks.Count);
            Assert.AreEqual(1, orderDetails.NotInStockBooks.Count);
            Assert.AreEqual(11, orderDetails.TotalQuantity);
            Assert.AreEqual(Convert.ToDecimal(1006364.5), orderDetails.TotalPrice);
            Assert.AreEqual(0, customer.BookCart.BookCartItems.Count);
            Assert.IsTrue(customer.Orders.IsNotEmpty());
            // Check In-Stock
            Assert.AreEqual(10, book1.InStock);
            Assert.AreEqual(18, book2.InStock);
            Assert.AreEqual(2, book3.InStock);
            Assert.AreEqual(0, book4.InStock);

            // Add books to the cart
            bookCart.AddBook(bookCartItem4);

            // Create customer order (not In-stock)
            orderDetails = await customer.PlaceOrder();

            Assert.AreEqual(0, orderDetails.PurchasedBooks.Count);
            Assert.AreEqual(1, orderDetails.NotInStockBooks.Count);
            Assert.AreEqual(0, orderDetails.TotalQuantity);
            Assert.AreEqual(Convert.ToDecimal(0), orderDetails.TotalPrice);
        }
Exemple #17
0
 private void ClearBooks(object obj)
 {
     BookCart.Clear();
 }
Exemple #18
0
 private void RemoveBook(Book obj)
 {
     BookCart.Remove(obj);
 }
Exemple #19
0
        public async Task AddRemoveUpdateClearBook()
        {
            var bookAsync1 = await new BookStoreHelper().SearchBooksAsync("title eq 'Mastering едц'");
            var bookAsync2 = await new BookStoreHelper().SearchBooksAsync("author eq 'Cunning Bastard'");
            var bookAsync3 = await new BookStoreHelper().SearchBooksAsync("title eq 'Generic Title'");

            var book1 = bookAsync1.First();
            var book2 = bookAsync2.First();
            var book3 = bookAsync3.First();

            var bookCartItem1 = new BookCartItem {
                Book = book1, Quantity = 5
            };
            var bookCartItem2 = new BookCartItem {
                Book = book2, Quantity = 2
            };
            var bookCartItem3 = new BookCartItem {
                Book = book3, Quantity = 3
            };

            // Create book cart
            var bookCart = new BookCart();

            Assert.AreEqual(0, bookCart.BookCartItems.Count);
            Assert.AreEqual(0, bookCart.TotalQuantity);
            Assert.AreEqual(0, bookCart.TotalPrice);

            // Add 1st book cart item to the cart
            bookCart.AddBook(bookCartItem1);
            Assert.AreEqual(1, bookCart.BookCartItems.Count);
            Assert.AreEqual(5, bookCart.TotalQuantity);
            Assert.AreEqual(3810, bookCart.TotalPrice);

            // Add 2nd book cart item to the cart
            bookCart.AddBook(bookCartItem2);
            Assert.AreEqual(2, bookCart.BookCartItems.Count);
            Assert.AreEqual(7, bookCart.TotalQuantity);
            Assert.AreEqual(5808, bookCart.TotalPrice);

            // Add 3rd book cart item to the cart
            bookCart.AddBook(bookCartItem3);
            Assert.AreEqual(3, bookCart.BookCartItems.Count);
            Assert.AreEqual(10, bookCart.TotalQuantity);
            Assert.AreEqual(Convert.ToDecimal(6364.5), bookCart.TotalPrice);

            // Remove 2nd book cart item from the cart
            bookCart.RemoveBook(bookCartItem2);
            Assert.AreEqual(2, bookCart.BookCartItems.Count);
            Assert.AreEqual(8, bookCart.TotalQuantity);
            Assert.AreEqual(Convert.ToDecimal(4366.5), bookCart.TotalPrice);

            // Update quantity of 2nd book cart item
            bookCart.UpdateQuantity(bookCartItem2, 4);
            Assert.AreEqual(2, bookCart.BookCartItems.Count);
            Assert.AreEqual(8, bookCart.TotalQuantity);
            Assert.AreEqual(Convert.ToDecimal(4366.5), bookCart.TotalPrice);

            // Update quantity of 1st book cart item
            bookCart.UpdateQuantity(bookCartItem1, 1);
            Assert.AreEqual(2, bookCart.BookCartItems.Count);
            Assert.AreEqual(4, bookCart.TotalQuantity);
            Assert.AreEqual(Convert.ToDecimal(1318.5), bookCart.TotalPrice);

            // Empty the cart
            bookCart.Clear();
            Assert.AreEqual(0, bookCart.BookCartItems.Count);
            Assert.AreEqual(0, bookCart.TotalQuantity);
            Assert.AreEqual(0, bookCart.TotalPrice);
        }
Exemple #20
0
 public CheckoutWindow(UserData u)
 {
     InitializeComponent();
     this.user = u;
     cart      = new BookCart();
 }