public JsonResult DeleteAll() { if (Session[OnlineShop.Common.CommonConstants.USER_SESSION] != null) { var customerSession = (OnlineShop.Common.UserLogin)Session[OnlineShop.Common.CommonConstants.USER_SESSION]; var customer = new CustomerDao().GetCustomerById(Convert.ToInt32(customerSession.UserId)); var shoppingCartItemDao = new ShoppingCartItemDao(); foreach (var item in customer.ShoppingCartItems) { if (item.ShoppingCartTypeId == (int)ShoppingCartType.Wishlist) { shoppingCartItemDao.DeleteShoppingCartItem(item.Id); } } return(Json(new { Status = true })); } else { Session[WishListSession] = null; return(Json(new { Status = true })); } }
public JsonResult Delete(long Id) { if (Session[OnlineShop.Common.CommonConstants.USER_SESSION] != null) { var customerSession = (OnlineShop.Common.UserLogin)Session[OnlineShop.Common.CommonConstants.USER_SESSION]; var customer = new CustomerDao().GetCustomerById(Convert.ToInt32(customerSession.UserId)); var shoppingCartItemDao = new ShoppingCartItemDao(); foreach (var item in customer.ShoppingCartItems) { if (item.ShoppingCartTypeId == (int)ShoppingCartType.Wishlist && item.ProductId == Id) { shoppingCartItemDao.DeleteShoppingCartItem(item.Id); } } return(Json(new { Status = true })); } else { var shoppingCart = (List <ShoppingCartItemModel>)Session[WishListSession]; shoppingCart.RemoveAll(x => x.Product.Id == Id && x.ShoppingCartTypeId == 2); Session[WishListSession] = shoppingCart; return(Json(new { Status = true })); } }
public JsonResult Update(string cartModel) { if (Session[OnlineShop.Common.CommonConstants.USER_SESSION] != null) { var customerSession = (OnlineShop.Common.UserLogin)Session[OnlineShop.Common.CommonConstants.USER_SESSION]; var customer = new CustomerDao().GetCustomerById(Convert.ToInt32(customerSession.UserId)); var jSonShoppingCart = new JavaScriptSerializer().Deserialize <List <ShoppingCartItemModel> >(cartModel); var shoppingCartItemDao = new ShoppingCartItemDao(); foreach (var item in customer.ShoppingCartItems) { if (item.ShoppingCartTypeId == (int)ShoppingCartType.Wishlist) { var jsonItem = jSonShoppingCart.SingleOrDefault(x => x.Product.Id == item.Product.Id); if (jsonItem != null) { item.Quantity = jsonItem.Quantity; shoppingCartItemDao.UpdateShoppingCartItem(item); } } } return(Json(new { Status = true })); } else { var jSonShoppingCart = new JavaScriptSerializer().Deserialize <List <ShoppingCartItemModel> >(cartModel); var shoppingCart = (List <ShoppingCartItemModel>)Session[WishListSession]; if (shoppingCart != null) { foreach (var item in shoppingCart) { var jsonItem = jSonShoppingCart.SingleOrDefault(x => x.Product.Id == item.Product.Id); if (jsonItem != null) { item.Quantity = jsonItem.Quantity; } } } Session[WishListSession] = shoppingCart; return(Json(new { Status = true })); } }
public ActionResult Confirm(string nextStep) { if (Session[CommonConstants.USER_SESSION] != null) { Customer customer = (Customer)TempData["Customer"]; if (customer.ShoppingCartItems.Where(x => x.ShoppingCartTypeId == 1).Count() == 0) { return(RedirectToAction("Index", "Cart")); } if (nextStep == "Confirm") { Decimal Total = 0; var customerDao = new CustomerDao(); var orderDao = new OrderDao(); var shoppingCartItemDao = new ShoppingCartItemDao(); foreach (var item in customer.Orders) { if (item.Id == 0) { foreach (var ite in item.OrderItems) { Total += Convert.ToDecimal(ite.Quantity) * ite.UnitPriceInclTax; } item.OrderStatusId = (int)Orders.Pending; item.ShippingStatusId = (int)Shipping.Delivered; item.PaymentStatusId = (int)Payment.Pending; item.CustomerCurrencyCode = "VND"; item.CurrencyRate = 1; item.CustomerTaxDisplayTypeId = 1; item.OrderSubtotalInclTax = Total; item.OrderSubtotalExclTax = Total; item.OrderTotal = Total; item.OrderSubTotalDiscountInclTax = 0; item.OrderSubTotalDiscountExclTax = 0; item.OrderShippingInclTax = 0; item.OrderShippingExclTax = 0; item.PaymentMethodAdditionalFeeInclTax = 0; item.PaymentMethodAdditionalFeeExclTax = 0; item.TaxRates = "0"; item.OrderTax = 0; item.OrderDiscount = 0; item.CustomerLanguageId = 1; item.CustomerIp = PublicIPAddress(); item.ShippingRateComputationMethodSystemName = ""; OrderNumer = item.CustomOrderNumber = orderDao.GetMaxOrderNumber(); item.Deleted = false; item.CreatedOnUtc = DateTime.UtcNow; OrderId = orderDao.InserOrder(item); } } var cus = customerDao.GetCustomerById(customer.Id); if (OrderId > 0) { foreach (var item in cus.ShoppingCartItems) { if (item.ShoppingCartTypeId == (int)ShoppingCartType.ShoppingCart) { shoppingCartItemDao.DeleteShoppingCartItem(item.Id); } } TempData["Customer"] = cus; return(RedirectToAction("Completed/" + Convert.ToInt32(OrderNumer) + "", "CheckOut")); } return(View(customer)); } else { return(View(customer)); } } else { return(Redirect("/")); } }
public void Setup() { _tested = new ShoppingCartItemDao(); }
public ActionResult Add(int productId, int shoppingCartTypeId, int quantity) { if (Session[OnlineShop.Common.CommonConstants.USER_SESSION] != null) { var customerSession = (OnlineShop.Common.UserLogin)Session[OnlineShop.Common.CommonConstants.USER_SESSION]; var customerDao = new CustomerDao(); var productDao = new ProductDao(); var customer = customerDao.GetCustomerById(Convert.ToInt32(customerSession.UserId)); var model = productDao.GetProductById(productId); var shoppingCartItemDao = new ShoppingCartItemDao(); if (customer.ShoppingCartItems.ToList().Exists(x => x.Product.Id == productId)) { foreach (var item in customer.ShoppingCartItems) { if (item.Product.Id == productId && item.ShoppingCartTypeId == (int)ShoppingCartType.Wishlist) { item.Quantity += quantity; shoppingCartItemDao.UpdateShoppingCartItem(item); } } } else { var shoppingCartItem = new ShoppingCartItem(); //shoppingCartItem.Product = model; //shoppingCartItem.Customer = customer; shoppingCartItem.ShoppingCartTypeId = (int)ShoppingCartType.Wishlist; shoppingCartItem.CustomerId = customer.Id; shoppingCartItem.ProductId = model.Id; shoppingCartItem.CustomerEnteredPrice = model.Price; shoppingCartItem.Quantity = quantity; shoppingCartItem.CreatedOnUtc = DateTime.UtcNow; shoppingCartItem.UpdatedOnUtc = DateTime.UtcNow; customer.ShoppingCartItems.Add(shoppingCartItem); customerDao.UpdateCustomer(customer); } var html = RenderViewToString(this.ControllerContext, "MiniViewAddWishList", model); var headerWishList = "(" + customer.ShoppingCartItems.Where(x => x.ShoppingCartTypeId == 2).Count().ToString() + ")"; return(Json(new { success = true, html, headerWishList })); } else { var cartType = (ShoppingCartType)shoppingCartTypeId; var listwishListItem = new List <ShoppingCartItemModel>(); var model = new ProductDao().GetProductById(productId); var wishListItem = Session[WishListSession]; if (wishListItem != null) { listwishListItem = (List <ShoppingCartItemModel>)wishListItem; if (listwishListItem.Exists(x => x.Product.Id == productId)) { foreach (var item in listwishListItem) { if (item.Product.Id == productId) { item.Quantity += quantity; } } } else { var wishList = new ShoppingCartItemModel(); wishList.Product = model; wishList.Quantity = quantity; wishList.ShoppingCartTypeId = (int)ShoppingCartType.Wishlist; listwishListItem.Add(wishList); } Session[WishListSession] = listwishListItem; } else { var wishList = new ShoppingCartItemModel(); wishList.Product = model; wishList.Quantity = quantity; wishList.ShoppingCartTypeId = (int)ShoppingCartType.Wishlist; listwishListItem.Add(wishList); Session[WishListSession] = listwishListItem; } var html = RenderViewToString(this.ControllerContext, "MiniViewAddWishList", model); var headerWishList = "(" + listwishListItem.Count().ToString() + ")"; return(Json(new { success = true, html, headerWishList })); } }
public JsonResult AddToCart(string cartModel) { if (Session[OnlineShop.Common.CommonConstants.USER_SESSION] != null) { var customerDao = new CustomerDao(); var productDao = new ProductDao(); var customerSession = (OnlineShop.Common.UserLogin)Session[OnlineShop.Common.CommonConstants.USER_SESSION]; var customer = customerDao.GetCustomerById(Convert.ToInt32(customerSession.UserId)); var jSonShoppingCart = new JavaScriptSerializer().Deserialize <List <ShoppingCartItemModel> >(cartModel); var shoppingCartItemDao = new ShoppingCartItemDao(); if (customer.ShoppingCartItems.Where(x => x.ShoppingCartTypeId == 1).Count() > 0) { foreach (var ite in jSonShoppingCart) { if (customer.ShoppingCartItems.ToList().Exists(x => x.Product.Id == ite.Product.Id && x.ShoppingCartTypeId == 1)) { foreach (var item in customer.ShoppingCartItems) { if (item.Product.Id == ite.Product.Id && item.ShoppingCartTypeId == 1) { item.Quantity += ite.Quantity; shoppingCartItemDao.UpdateShoppingCartItem(item); } } } else { var shoppingCartItem = new ShoppingCartItem(); var model = productDao.GetProductById(ite.Product.Id); shoppingCartItem.ShoppingCartTypeId = (int)ShoppingCartType.ShoppingCart; shoppingCartItem.CustomerId = customer.Id; shoppingCartItem.ProductId = model.Id; shoppingCartItem.CustomerEnteredPrice = model.Price; shoppingCartItem.Quantity = ite.Quantity; shoppingCartItem.CreatedOnUtc = DateTime.UtcNow; shoppingCartItem.UpdatedOnUtc = DateTime.UtcNow; shoppingCartItemDao.InsertShoppingCartItem(shoppingCartItem); customer.ShoppingCartItems.Add(shoppingCartItem); customerDao.UpdateCustomer(customer); } } foreach (var item in customer.ShoppingCartItems) { if (item.ShoppingCartTypeId == (int)ShoppingCartType.Wishlist) { shoppingCartItemDao.DeleteShoppingCartItem(item.Id); } } Session[WishListSession] = null; return(Json(new { Status = true })); } else { foreach (var item in jSonShoppingCart) { var shoppingCartItem = new ShoppingCartItem(); var model = productDao.GetProductById(item.Product.Id); shoppingCartItem.ShoppingCartTypeId = (int)ShoppingCartType.ShoppingCart; shoppingCartItem.CustomerId = customer.Id; shoppingCartItem.ProductId = model.Id; shoppingCartItem.CustomerEnteredPrice = model.Price; shoppingCartItem.Quantity = item.Quantity; shoppingCartItem.CreatedOnUtc = DateTime.UtcNow; shoppingCartItem.UpdatedOnUtc = DateTime.UtcNow; customer.ShoppingCartItems.Add(shoppingCartItem); customerDao.UpdateCustomer(customer); } foreach (var item in customer.ShoppingCartItems) { if (item.ShoppingCartTypeId == (int)ShoppingCartType.Wishlist) { shoppingCartItemDao.DeleteShoppingCartItem(item.Id); } } Session[WishListSession] = null; return(Json(new { Status = true })); } } else { var jSonShoppingCart = new JavaScriptSerializer().Deserialize <List <ShoppingCartItemModel> >(cartModel); var shoppingCart = (List <ShoppingCartItemModel>)Session[ShoppingCartSession]; if (shoppingCart != null) { foreach (var ite in jSonShoppingCart) { if (shoppingCart.Exists(x => x.Product.Id == ite.Product.Id && x.ShoppingCartTypeId == 1)) { foreach (var item in shoppingCart) { if (item.Product.Id == ite.Product.Id && item.ShoppingCartTypeId == 1) { item.Quantity += ite.Quantity; } } } else { var model = new ProductDao().GetProductById(ite.Product.Id); var shoppingCartItem = new ShoppingCartItemModel(); shoppingCartItem.Product = model; shoppingCartItem.Quantity = ite.Quantity; shoppingCartItem.ShoppingCartTypeId = (int)ShoppingCartType.ShoppingCart; shoppingCart.Add(shoppingCartItem); } } Session[ShoppingCartSession] = shoppingCart; } else { var listShoppingCart = new List <ShoppingCartItemModel>(); foreach (var item in jSonShoppingCart) { var model = new ProductDao().GetProductById(item.Product.Id); var shoppingCartItem = new ShoppingCartItemModel(); shoppingCartItem.Product = model; shoppingCartItem.Quantity = item.Quantity; shoppingCartItem.ShoppingCartTypeId = (int)ShoppingCartType.ShoppingCart; listShoppingCart.Add(shoppingCartItem); } Session[ShoppingCartSession] = listShoppingCart; } Session[WishListSession] = null; return(Json(new { Status = true })); } }
public ActionResult AddProductToCartAjax(int productId, int quantity, bool isAddToCartButton) { if (Session[OnlineShop.Common.CommonConstants.USER_SESSION] != null) { var customerDao = new CustomerDao(); var productDao = new ProductDao(); var customerSession = (OnlineShop.Common.UserLogin)Session[OnlineShop.Common.CommonConstants.USER_SESSION]; var customer = customerDao.GetCustomerById(Convert.ToInt32(customerSession.UserId)); var model = productDao.GetProductById(productId); var shoppingCartItemDao = new ShoppingCartItemDao(); if (customer.ShoppingCartItems.ToList().Exists(x => x.Product.Id == productId && x.ShoppingCartTypeId == 1)) { foreach (var item in customer.ShoppingCartItems) { if (item.Product.Id == productId && item.ShoppingCartTypeId == (int)ShoppingCartType.ShoppingCart) { item.Quantity += quantity; shoppingCartItemDao.UpdateShoppingCartItem(item); } } } else { var shoppingCartItem = new ShoppingCartItem(); shoppingCartItem.ShoppingCartTypeId = (int)ShoppingCartType.ShoppingCart; shoppingCartItem.CustomerId = customer.Id; shoppingCartItem.ProductId = model.Id; shoppingCartItem.CustomerEnteredPrice = model.Price; shoppingCartItem.Quantity = quantity; shoppingCartItem.CreatedOnUtc = DateTime.UtcNow; shoppingCartItem.UpdatedOnUtc = DateTime.UtcNow; customer.ShoppingCartItems.Add(shoppingCartItem); customerDao.UpdateCustomer(customer); } if (!isAddToCartButton) { foreach (var item in customer.ShoppingCartItems) { if (item.ShoppingCartTypeId == (int)ShoppingCartType.Wishlist && item.ProductId == productId) { shoppingCartItemDao.DeleteShoppingCartItem(item.Id); } } } var listShoppingCart = new List <ShoppingCartItemModel>(); foreach (var item in customer.ShoppingCartItems) { if (item.ShoppingCartTypeId == (int)ShoppingCartType.ShoppingCart) { var shoppingCartItem = new ShoppingCartItemModel(); shoppingCartItem.Product = item.Product; shoppingCartItem.Quantity = item.Quantity; shoppingCartItem.ShoppingCartTypeId = (int)ShoppingCartType.ShoppingCart; listShoppingCart.Add(shoppingCartItem); } } var html = RenderViewToString(this.ControllerContext, "AddProductToCartAjax", model); var flyoutShoppingCart = RenderViewToString(this.ControllerContext, "FlyoutShoppingCart", listShoppingCart); var headerCart = "" + customer.ShoppingCartItems.Where(x => x.ShoppingCartTypeId == 1).Count().ToString() + ""; return(Json(new { success = true, html, flyoutShoppingCart, headerCart })); } else { var listShoppingCart = new List <ShoppingCartItemModel>(); var model = new ProductDao().GetProductById(productId); var shoppingCart = Session[ShoppingCartSession]; if (shoppingCart != null) { listShoppingCart = (List <ShoppingCartItemModel>)shoppingCart; if (listShoppingCart.Exists(x => x.Product.Id == productId)) { foreach (var item in listShoppingCart) { if (item.Product.Id == productId) { item.Quantity += quantity; } } } else { var shoppingCartItem = new ShoppingCartItemModel(); shoppingCartItem.Product = model; shoppingCartItem.Quantity = quantity; shoppingCartItem.ShoppingCartTypeId = (int)ShoppingCartType.ShoppingCart; listShoppingCart.Add(shoppingCartItem); } Session[ShoppingCartSession] = listShoppingCart; } else { var shoppingCartItem = new ShoppingCartItemModel(); shoppingCartItem.Product = model; shoppingCartItem.Quantity = quantity; shoppingCartItem.ShoppingCartTypeId = (int)ShoppingCartType.ShoppingCart; listShoppingCart.Add(shoppingCartItem); Session[ShoppingCartSession] = listShoppingCart; } if (!isAddToCartButton) { var wishlistCart = (List <ShoppingCartItemModel>)Session[WishListSession]; wishlistCart.RemoveAll(x => x.Product.Id == productId && x.ShoppingCartTypeId == 2); Session[WishListSession] = wishlistCart; } var html = RenderViewToString(this.ControllerContext, "AddProductToCartAjax", model); var flyoutShoppingCart = RenderViewToString(this.ControllerContext, "FlyoutShoppingCart", listShoppingCart); var headerCart = "" + listShoppingCart.Count().ToString() + ""; return(Json(new { success = true, html, flyoutShoppingCart, headerCart })); } }