コード例 #1
0
        public void GetShoppingCart_AlreadySavedShoppingCart_IsReturned()
        {
            var cart = new ShoppingCart();

            cart.AddLineItem(new OrderLine()
            {
                BookId = 1, Quantity = 1, OrderId = 1, Book = new Book()
                {
                    Id    = 1,
                    Price = 1m
                }
            });
            var serializedCart = JsonConvert.SerializeObject(cart);


            var shoppingCartLogic = new ShoppingCartLogic(new Mock <IDatabaseContext>().Object);

            var sessionMock = new Mock <ISession>();

            sessionMock.Setup(m => m.TryGetValue(It.IsAny <string>(), out It.Ref <byte[]> .IsAny))
            .Callback(new GobbleCallback((string key, out byte[] data) =>
            {
                data = Encoding.UTF8.GetBytes(serializedCart);
            })).Returns(true);


            var shoppingCart = shoppingCartLogic.GetShoppingCart(sessionMock.Object);

            shoppingCart.Should().BeEquivalentTo(cart);
        }
コード例 #2
0
        public ActionResult ProcedToCheckout(CreateOrderViewModel viewModel)
        {
            var customer = orderRepo.GetSingleEntity(x => x.UserId == User.Identity.Name);

            if (ModelState.IsValid)
            {
                Order order = ConvertViewModelToOrder(viewModel, User.Identity.Name);

                orderRepo.Insert(order);
                orderRepo.SaveChanges();

                shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);
                order.TotalPrice  = shoppingCartLogic.ShoppingCartToOrderDetails(order);

                orderRepo.Update(order);
                orderRepo.SaveChanges();

                return(RedirectToAction("Index"));
            }


            viewModel.PaymentMethods    = paymentMethodRepo.GetWithFilterAndOrder();
            viewModel.CollectionMethods = collectionRepo.GetWithFilterAndOrder();

            return(View(viewModel));
        }
コード例 #3
0
        public string[] CheckProductQuantities()
        {
            try
            {
                if (Context.User.IsInRole("User"))
                {
                    User myLoggedUser = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name);
                    List <ShoppingCart> myShoppingCartItems = new ShoppingCartLogic().RetrieveAllShoppingCartItems(myLoggedUser.Id).ToList();

                    List <string> ViolatingIDs = new List <string>();

                    foreach (ShoppingCart myShoppingCartItem in myShoppingCartItems)
                    {
                        if (!new OrdersLogic().HasSufficientQuantity(myShoppingCartItem.ProductFK, myShoppingCartItem.Quantity))
                        {
                            ViolatingIDs.Add(myShoppingCartItem.ProductFK.ToString());
                        }
                    }

                    return(ViolatingIDs.ToArray());
                }
                else
                {
                    return(new string[] { "" });
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
コード例 #4
0
        public ActionResult RemoveFromCart(int id)
        {
            var cart = ShoppingCartLogic.GetCart(this.HttpContext);

            var     shoppingCart    = new ShoppingCartLogic();
            int     productId       = shoppingCart.GetCartItemProductId(id);
            var     productService  = new ProductLogic();
            Product productToRemove = productService.FindProduct(productId);

            int itemCount = cart.RemoveFromCart(id);

            var removeViewModel = new ShoppingCartRemoveVM
            {
                Message = Server.HtmlEncode(productToRemove.Name) +
                          " has been removed from your shopping cart.",
                CartCount    = cart.GetCount(),
                CartSubTotal = cart.GetSubtotal(),
                CartSalesTax = cart.GetSalesTax(),
                CartTotal    = cart.GetTotal(),
                ItemCount    = itemCount,
                DeleteId     = id,
            };

            return(Json(removeViewModel));
        }
コード例 #5
0
        /// <summary>
        /// 把購物車UserId指向真正的UserId
        /// 在登入的時候執行
        /// </summary>
        /// <param name="userId">真正UserId</param>
        public void MigrateShoppingCart(string userId)
        {
            var cart = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            cart.MigrateShoppingCartUserIdToUserId(userId);
            Session[ConfigurationManager.AppSettings["UserIdSession"]] = userId;
        }
コード例 #6
0
        public string LoadShoppingCartItems()
        {
            try
            {
                if (Context.User.IsInRole("User"))
                {
                    string HTML = "";

                    User myLoggedUser = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name);
                    List <ShoppingCart> myShoppingCartItems = new ShoppingCartLogic().RetrieveAllShoppingCartItems(myLoggedUser.Id).ToList();
                    List <Product>      myProductList       = new List <Product>();

                    foreach (ShoppingCart myShoppingCartItem in myShoppingCartItems)
                    {
                        myProductList.Add(new ProductsLogic().RetrieveProductByID(myShoppingCartItem.ProductFK.ToString()));
                    }

                    Product[] myProducts = myProductList.ToArray();

                    if (myProducts.Length > 0)
                    {
                        for (int i = 1; i <= (myProducts.Length + 4 / 4); i++)
                        {
                            int Counter = i * 4;

                            HTML += "<tr>";

                            for (int j = (Counter - 3); j <= Counter; j++)
                            {
                                HTML += "<td>";

                                HTML += TDContents(myProducts[j - 1]);

                                HTML += "</td>";

                                if (j == myProducts.Length)
                                {
                                    goto LoopEnd;
                                }
                            }

                            HTML += "</tr>";
                        }
                    }

LoopEnd:

                    return(HTML);
                }
                else
                {
                    return("");
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
コード例 #7
0
        public ActionResult EmptyShoppingCart(string userId)
        {
            //TODO: Make it ajax. All shopping cart can be wrap up into a partial view
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            shoppingCartLogic.EmptyCart();
            return(RedirectToAction("Index"));
        }
コード例 #8
0
 public Form1()
 {
     RssReader = new RssReader();
     CCP       = new ShoppingCartLogic();
     GetItemsFromDb();
     InitializeComponent();
     Load += Initialize;
 }
コード例 #9
0
        public ActionResult DeleteConfirmed(int shoppingCartId)
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            shoppingCartLogic.RemoveFromCart(shoppingCartId);

            shoppingCartLogic.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #10
0
        /// <summary>
        /// 把一個餐加入到購物車
        /// </summary>
        /// <param name="mealId"></param>
        /// <returns></returns>
        public ActionResult AddToCart(int mealId)
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            shoppingCartLogic.AddToCart(mealId);
            shoppingCartLogic.SaveChanges();

            return(RedirectToAction("Index"));
        }
コード例 #11
0
        public void CompleteCheckout(string CreditCard)
        {
            try
            {
                if (Context.User.IsInRole("User"))
                {
                    User myLoggedUser = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name);
                    List <ShoppingCart> myShoppingCartItems = new ShoppingCartLogic().RetrieveAllShoppingCartItems(myLoggedUser.Id).ToList();
                    List <OrderItem>    myOrderItems        = new List <OrderItem>();

                    foreach (ShoppingCart myShoppingCartItem in myShoppingCartItems)
                    {
                        UserTypeProduct myPriceType = new PriceTypesLogic().RetrievePriceTypeByID(myLoggedUser.UserTypeFK, myShoppingCartItem.ProductFK);

                        OrderItem myOrderItem = new OrderItem();

                        myOrderItem.Id = myShoppingCartItem.ProductFK;

                        double myPrice = 0;

                        if (myPriceType != null)
                        {
                            myPrice = myPriceType.Price;
                            double?NewPrice = 0;

                            if ((myPriceType.DiscountDateFrom != null) && (myPriceType.DiscountDateTo != null) && (myPriceType.DiscountPercentage != null))
                            {
                                if ((DateTime.Now >= myPriceType.DiscountDateFrom) && (DateTime.Now <= myPriceType.DiscountDateTo))
                                {
                                    NewPrice = myPriceType.Price - ((myPriceType.DiscountPercentage / 100) * myPriceType.Price);
                                    myPrice  = Convert.ToDouble(NewPrice);
                                }
                            }
                        }

                        myOrderItem.Price = myPrice;

                        myOrderItem.Quantity = myShoppingCartItem.Quantity;

                        myOrderItems.Add(myOrderItem);
                    }

                    //if (
                    new OrdersLogic().AddOrder(null, myLoggedUser.Id, CreditCard.Trim(), myOrderItems);
                    //{
                    //new UsersLogic().InsertCreditCardNumber(CreditCard.Trim(), myLoggedUser.Id);
                    //new ShoppingCartLogic().EmptyCart(myLoggedUser.Id);

                    //}
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
コード例 #12
0
 public ActionResult ShoppingCart(int ItemId, string math)
 {
     if (ModelState.IsValid)
     {
         var user      = User.Identity.Name;
         var cartLogic = new ShoppingCartLogic();
         cartLogic.AdjustCart(ItemId, user, math);
         return(RedirectToAction("ShoppingCart"));
     }
     return(View());
 }
コード例 #13
0
        public ActionResult AddToCart(int id)
        {
            var productService = new ProductLogic();
            var productAdded   = productService.FindProduct(id);

            ShoppingCartLogic cart = ShoppingCartLogic.GetCart(this.HttpContext);

            cart.AddToCart(productAdded);

            return(RedirectToAction("Index"));
        }
コード例 #14
0
        public ActionResult Delete(int shoppingCartId = 0)
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);
            ShoppingCart shoppingcart = shoppingCartLogic.GetShoppingCartUsingShoppingCartId(shoppingCartId);

            if (shoppingcart == null)
            {
                return(HttpNotFound());
            }
            return(View(shoppingcart));
        }
コード例 #15
0
        public void GetShoppingCart_EmptySession_EmptyShoppingCart()
        {
            var shoppingCartLogic = new ShoppingCartLogic(new Mock <IDatabaseContext>().Object);

            var sessionMock = new Mock <ISession>();

            sessionMock.Setup(m => m.TryGetValue(It.IsAny <string>(), out It.Ref <byte[]> .IsAny)).Returns(false);


            var shoppingCart = shoppingCartLogic.GetShoppingCart(sessionMock.Object);

            shoppingCart.Count.Should().Be(0);
        }
コード例 #16
0
        public void GetShoppingCart_StoredInSession()
        {
            var shoppingCartLogic = new ShoppingCartLogic(new Mock <IDatabaseContext>().Object);

            var sessionMock = new Mock <ISession>();

            sessionMock.Setup(m => m.TryGetValue(It.IsAny <string>(), out It.Ref <byte[]> .IsAny)).Returns(false);


            var shoppingCart = shoppingCartLogic.GetShoppingCart(sessionMock.Object);

            sessionMock.Verify(m => m.Set("CART", It.IsAny <byte[]>()), Times.Once);
        }
コード例 #17
0
        // GET: ShoppingCart
        public ActionResult Index()
        {
            var cart = ShoppingCartLogic.GetCart(this.HttpContext);

            var CartViewModel = new ShoppingCartVM
            {
                CartItems    = cart.GetCartItems(),
                CartSubTotal = cart.GetSubtotal(),
                CartSalesTax = cart.GetSalesTax(),
                CartTotal    = cart.GetTotal(),
            };

            return(View(CartViewModel));
        }
コード例 #18
0
        //
        // GET: /ShoppingCart/


        public ActionResult Index()
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            var viewModel = new ViewModels.ShoppingCartViewModel();

            viewModel.CartItems  = shoppingCartLogic.GetShoppingCartItems().ToList();
            viewModel.TotalPrice = shoppingCartLogic.GetShoppingCartTotalPrice(viewModel.CartItems);

            ViewBag.ShowEdit = true;
            ViewBag.Title    = "購物車內容";

            return(View(viewModel));
        }
コード例 #19
0
 public CheckoutController()
 {
     db = new OrderBLL();
     cartBLL = new ShoppingCartBLL();
 }
コード例 #20
0
 public ShopCartController()
 {
     storeDB = new ShoppingCartBLL();
     prodBLL = new ProductBLL();
 }
コード例 #21
0
        public string LoadShoppingCartItems()
        {
            try
            {
                if (Context.User.IsInRole("User"))
                {
                    string HTML = "";

                    User myLoggedUser = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name);
                    List <ShoppingCart> myShoppingCartItems = new ShoppingCartLogic().RetrieveAllShoppingCartItems(myLoggedUser.Id).ToList();

                    HTML += "<table>";

                    int Counter = 0;

                    foreach (ShoppingCart myShoppingCartItem in myShoppingCartItems)
                    {
                        UserTypeProduct myPriceType = new PriceTypesLogic().RetrievePriceTypeByID(myLoggedUser.UserTypeFK, myShoppingCartItem.ProductFK);

                        string PriceOutput = "";

                        if (myPriceType != null)
                        {
                            PriceOutput = myPriceType.Price.ToString("F");
                            double?NewPrice = 0;

                            if ((myPriceType.DiscountDateFrom != null) && (myPriceType.DiscountDateTo != null) && (myPriceType.DiscountPercentage != null))
                            {
                                if ((DateTime.Now >= myPriceType.DiscountDateFrom) && (DateTime.Now <= myPriceType.DiscountDateTo))
                                {
                                    NewPrice = myPriceType.Price - ((myPriceType.DiscountPercentage / 100) * myPriceType.Price);

                                    string myDisplayedNewPrice = Convert.ToDouble(NewPrice).ToString("F");

                                    PriceOutput = myDisplayedNewPrice + " : " + myPriceType.DiscountPercentage + " % Off";
                                }
                            }
                        }

                        HTML += "<tr class=\"GridViewTuple\">";

                        HTML += "<td>";
                        HTML += new ProductsLogic().RetrieveProductByID(myShoppingCartItem.ProductFK.ToString()).Name;
                        HTML += "</td>";

                        HTML += "<td>";
                        HTML += "<div style=\"padding-top: 4px; float: left;\">x&nbsp;&nbsp;</div><input class=\"CatalogTextBox\" id=\"" + myShoppingCartItem.ProductFK + "\" Use=\"Quantity\" type=\"text\" value=\"" + myShoppingCartItem.Quantity.ToString() + "\">";
                        HTML += "</td>";

                        HTML += "<td> at </td>";

                        HTML += "<td>";
                        HTML += "€ " + PriceOutput;
                        HTML += "</td>";

                        HTML += "<td>";
                        HTML += "<div Use=\"ErrorDiv\" ProductID=\"" + myShoppingCartItem.ProductFK + "\" class=\"MiniFontBlue\">Not Enough Stock</div>";
                        HTML += "</td>";

                        HTML += "</tr>";

                        Counter++;
                    }

                    HTML += "</table>";

                    return(HTML);
                }
                else
                {
                    return("");
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
コード例 #22
0
 public ShopCartController(ShoppingCartLogic stub, ProductLogic prodStub)
 {
     storeDB = stub;
     prodBLL = prodStub;
 }
コード例 #23
0
        public PartialViewResult ShoppingCartCount()
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            return(PartialView("_ShoppingCartCount", shoppingCartLogic.GetShoppingCartCount()));
        }
コード例 #24
0
        /// <summary>
        /// Generates TD Contents for Each Product
        /// Level: External
        /// </summary>
        /// <param name="myProduct">The Product to Display</param>
        /// <returns>HTML</returns>
        private string TDContents(Product myProduct)//ProductsView myCurrentProduct
        {
            try
            {
                string Name        = myProduct.Name;
                string ImageURL    = VirtualPathUtility.ToAbsolute(myProduct.ImageURL);
                string ProductID   = myProduct.Id.ToString();
                string ProductLink = "/user/viewproduct.aspx?id=" + new Encryption().Encrypt(myProduct.Id.ToString());

                User            myLoggedUser       = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name);
                UserTypeProduct myPriceType        = new PriceTypesLogic().RetrievePriceTypeByID(myLoggedUser.UserTypeFK, myProduct.Id);
                ShoppingCart    myShoppingCartItem = new ShoppingCartLogic().RetrieveShoppingCartItemByID(myLoggedUser.Id, myProduct.Id);

                string Price = "";

                if (myPriceType != null)
                {
                    Price = "€" + myPriceType.Price.ToString("F");
                    double?NewPrice = 0;

                    if ((myPriceType.DiscountDateFrom != null) && (myPriceType.DiscountDateTo != null) && (myPriceType.DiscountPercentage != null))
                    {
                        if ((DateTime.Now >= myPriceType.DiscountDateFrom) && (DateTime.Now <= myPriceType.DiscountDateTo))
                        {
                            NewPrice = myPriceType.Price - ((myPriceType.DiscountPercentage / 100) * myPriceType.Price);

                            string myDisplayedNewPrice = Convert.ToDouble(NewPrice).ToString("F");

                            Price = myPriceType.DiscountPercentage + "% Off : €" + myDisplayedNewPrice;
                        }
                    }
                }

                //string Price = new ProductsLogic().RetrieveProductPrice(_UserType, myProduct.Id).ToString("F");
                string ButtonHTML = "<input type=\"image\" class=\"ProductButton\" alt=\"\" ProductID=\"" + ProductID + "\" ClickAction=\"Add\" src=\"/images/Add.jpg\" onclick=\"return false;\" />" +
                                    "<div class=\"ProductButtonSpacer\"></div>" +
                                    "<input type=\"image\" class=\"ProductButton\" alt=\"\" ProductID=\"" + ProductID + "\" ClickAction=\"Remove\" src=\"/images/Remove.jpg\" onclick=\"return false;\"/>";
                string OutOfStock = "No Stock &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                string LowOnStock = "Low Stock &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                string TextBox    = "<div class=\"MiniFontGrey\"><div style=\"padding-top: 5px; float: left;\">Quantity&nbsp;&nbsp;</div><input type=\"text\" value=\"" + myShoppingCartItem.Quantity + "\" name=\"" + ProductID + "\" class=\"CatalogTextBox\"></div>" +
                                    "<br />";

                if (myProduct.StockQuantity == 0)
                {
                    ButtonHTML = "";
                    LowOnStock = "";
                    TextBox    = "<div style=\"height: 27px; width: 1px\"></div>";
                }
                else if (myProduct.StockQuantity <= myProduct.ReorderLevel)
                {
                    OutOfStock = "";
                }
                else
                {
                    LowOnStock = "";
                    OutOfStock = "";
                }

                string HTML = "<div>" +
                              "<div class=\"ProductContent\">" +
                              "<img class=\"ProductImage\" alt=\"\" src=\"" + ImageURL + "\" />" +
                              "<br />" +
                              "<a href=\"" + ProductLink + "\" target=\"_blank\" class=\"MiniFontGrey\">" + Name + "</a><br />" +
                              "<div class=\"MiniFontBlue\">" + OutOfStock + LowOnStock + Price + "</div>" +
                              "<br />" +
                              TextBox +
                              "</div>" +
                              "<div class=\"ProductButtons\">" +
                              ButtonHTML +
                              "</div>";

                return(HTML);
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
コード例 #25
0
 public CheckoutController(OrderLogic stubOrder, ShoppingCartLogic stubCart)
 {
     db = stubOrder;
     cartBLL = stubCart;
 }
コード例 #26
0
 public ShoppingCartLogicTests()
 {
     Shopping = new ShoppingCartLogic();
     //
 }