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); }
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)); }
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; } }
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)); }
/// <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; }
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; } }
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")); }
public Form1() { RssReader = new RssReader(); CCP = new ShoppingCartLogic(); GetItemsFromDb(); InitializeComponent(); Load += Initialize; }
public ActionResult DeleteConfirmed(int shoppingCartId) { shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext); shoppingCartLogic.RemoveFromCart(shoppingCartId); shoppingCartLogic.SaveChanges(); return(RedirectToAction("Index")); }
/// <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")); }
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; } }
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()); }
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")); }
public ActionResult Delete(int shoppingCartId = 0) { shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext); ShoppingCart shoppingcart = shoppingCartLogic.GetShoppingCartUsingShoppingCartId(shoppingCartId); if (shoppingcart == null) { return(HttpNotFound()); } return(View(shoppingcart)); }
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); }
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); }
// 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)); }
// // 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)); }
public CheckoutController() { db = new OrderBLL(); cartBLL = new ShoppingCartBLL(); }
public ShopCartController() { storeDB = new ShoppingCartBLL(); prodBLL = new ProductBLL(); }
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 </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; } }
public ShopCartController(ShoppingCartLogic stub, ProductLogic prodStub) { storeDB = stub; prodBLL = prodStub; }
public PartialViewResult ShoppingCartCount() { shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext); return(PartialView("_ShoppingCartCount", shoppingCartLogic.GetShoppingCartCount())); }
/// <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 "; string LowOnStock = "Low Stock "; string TextBox = "<div class=\"MiniFontGrey\"><div style=\"padding-top: 5px; float: left;\">Quantity </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; } }
public CheckoutController(OrderLogic stubOrder, ShoppingCartLogic stubCart) { db = stubOrder; cartBLL = stubCart; }
public ShoppingCartLogicTests() { Shopping = new ShoppingCartLogic(); // }