// // GET: /Cart/ public ActionResult Index() { var productList = _productBusiness.GetListWT(); var assignedProductList = new List <AddToCart>(); var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); if (currentUserId > 0) { assignedProductList = _AddToCartBusiness.GetListWT(c => c.UserId == currentUserId); } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString()); if (!string.IsNullOrEmpty(products)) { assignedProductList = (from p in products.Split(',') select new AddToCart { ProductId = Convert.ToInt32(p.Split('~')[0]), Quantity = Convert.ToInt32(p.Split('~')[1]), Size = Convert.ToInt32(p.Split('~')[2]), Attributes = p.Split('~')[3] }).ToList(); } } var imgList = _ImageBusiness.GetListWT(); var vmProductList = (from c in productList join ap in assignedProductList on c.ProductID equals ap.ProductId select new CartWishlistViewModel { ProductID = c.ProductID, ProductCode = c.ProductCode, ProductName = c.ProductName, TokenKey = c.TokenKey, ShortDescription = c.ShortDescription, Price = _productBusiness.GetSelectedPrice(c.ProductID, ap.Size.Value, ap.Attributes), DiscountPercent = c.DiscountPercent, DiscountedPrice = Math.Round(_productBusiness.GetSelectedPrice(c.ProductID, ap.Size.Value, ap.Attributes) - Decimal.Divide(c.DiscountPercent ?? 0, 100) * _productBusiness.GetSelectedPrice(c.ProductID, ap.Size.Value, ap.Attributes)), SizeId = ap.Size.Value, Size = _productBusiness.GetSizeName(c.ProductID, ap.Size.Value), AttributeId = ap.Attributes, Attributes = _productBusiness.GetAttributes(c.ProductID, ap.Attributes), quantity = ap.Quantity, ImageList = (from il in imgList where (il.ProductId == c.ProductID) select new ImageViewModel { ProductId = c.ProductID, Images = "/ProductImage/" + il.Images }).ToList() }).ToList(); return(View(vmProductList)); }
public JsonResult AddItemToCart(int ID, int Quantity) { if (CookieStore.GetCookie(cookiekey).Contains(ID.ToString())) { return(Json(new { Added = 2 }, JsonRequestBehavior.AllowGet)); } else { string cookievalue = ID + ":" + Quantity; TimeSpan cookieexpire = new TimeSpan(1000, 0, 0, 0); CookieStore.SetCookie(cookiekey, cookievalue, cookieexpire); return(Json(new { Added = 1 }, JsonRequestBehavior.AllowGet)); } }
// GET: UserAccount public ActionResult Cart() { List <Product> products = new List <Product>(); string cookie = CookieStore.GetCookie(cookiekey); foreach (string s in cookie.Split(',')) { string[] strings = s.Split(':'); if (!string.IsNullOrEmpty(strings[0])) { Product product = DataAccess.ProductDA.GetSingle(Convert.ToInt32(strings[0])); product.quantity = Convert.ToInt32(strings[1]); products.Add(product); } } ViewBag.CartTotal = products.Sum(p => p.Price * p.quantity); return(View(products)); }
public ActionResult AddToCompareList(int productid, int size = 0, string attributes = "") { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); var productSize = _productSizeBusiness.GetListWT(c => c.ProductId == productid).FirstOrDefault(); var defaultSize = productSize == null ? 0 : productSize.Id; if (size == 0) { size = defaultSize; } if (currentUserId > 0) { var count = _CompareListBusiness.GetListWT(c => c.UserId == currentUserId && c.ProductId == productid).Count(); if (count <= 0) { CompareList compareList = new CompareList(); compareList.ProductId = productid; compareList.UserId = currentUserId; _CompareListBusiness.Insert(compareList); _unitOfWork.SaveChanges(); } } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.CompareList.ToString()); var value = string.Empty; if (string.IsNullOrEmpty(products)) { value = productid.ToString() + "~" + size.ToString() + "~" + attributes.ToString(); } else { if (!products.Split(',').Select(c => c.Split('~')[0]).Contains(productid.ToString())) { value = products + "," + productid.ToString() + "~" + size.ToString() + "~" + attributes.ToString(); } } var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.CompareList.ToString(), value, expireCookieTimeHr); } return(new EmptyResult()); }
public ActionResult ProductAddToCart(int productid, int quantity, int size = 0, string attributes = "") { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); var productSize = _productSizeBusiness.GetListWT(c => c.ProductId == productid).FirstOrDefault(); var defaultSize = productSize == null ? 0 : productSize.Id; if (size == 0) { size = defaultSize; } if (currentUserId > 0) { var cartList = _AddToCartBusiness.GetListWT(c => c.UserId == currentUserId && c.ProductId == productid); AddToCart addToCart = new AddToCart(); addToCart.ProductId = productid; addToCart.UserId = currentUserId; addToCart.Quantity = quantity; addToCart.Size = size; addToCart.Attributes = attributes; if (cartList.Count() <= 0) { _AddToCartBusiness.Insert(addToCart); } else { addToCart.ID = cartList.FirstOrDefault().ID; _AddToCartBusiness.Update(addToCart); } _unitOfWork.SaveChanges(); } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString()); var newValue = productid.ToString() + "~" + quantity.ToString() + "~" + size.ToString() + "~" + attributes.ToString(); var value = mycookie.FormatCartCookieValue(products, newValue); var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.AddToCart.ToString(), value, expireCookieTimeHr); } return(new EmptyResult()); }
public ActionResult CheckOut() { if (User.Identity.IsAuthenticated) { List <Product> products = new List <Product>(); string cookie = CookieStore.GetCookie(cookiekey); foreach (string s in cookie.Split(',')) { string[] strings = s.Split(':'); if (!string.IsNullOrEmpty(strings[0])) { Product product = DataAccess.ProductDA.GetSingle(Convert.ToInt32(strings[0])); product.quantity = Convert.ToInt32(strings[1]); products.Add(product); } } ViewBag.CartTotal = products.Sum(p => p.Price * p.quantity) + 7; return(View(products)); } else { return(RedirectToAction("LoginSignUp", "UserAccount")); } }
public ActionResult DeleteFromCompareList(int productid) { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); if (currentUserId > 0) { var compareListProduct = _CompareListBusiness.GetList(c => c.UserId == currentUserId && c.ProductId == productid).FirstOrDefault(); if (compareListProduct != null) { _CompareListBusiness.Delete(compareListProduct); _unitOfWork.SaveChanges(); } } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.CompareList.ToString()); var newCookieValueString = string.Empty; foreach (var prdId in products.Split(',')) { if (prdId.Split('~')[0] != productid.ToString()) { newCookieValueString = newCookieValueString + "," + prdId; } } var value = string.Empty; if (!string.IsNullOrEmpty(newCookieValueString)) { value = newCookieValueString.Substring(1); } var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.CompareList.ToString(), value, expireCookieTimeHr); } return(new EmptyResult()); }
public ActionResult DeleteFromCartList(int productid) { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); if (currentUserId > 0) { var cartProduct = _AddToCartBusiness.GetList(c => c.UserId == currentUserId && c.ProductId == productid).FirstOrDefault(); if (cartProduct != null) { _AddToCartBusiness.Delete(cartProduct); _unitOfWork.SaveChanges(); } } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString()); var productId = productid.ToString(); var value = mycookie.FormatCartCookieValueAfterDelete(products, productId); var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.AddToCart.ToString(), value, expireCookieTimeHr); } return(new EmptyResult()); }
// // GET: /CheckOut/ public ActionResult Index() { EcommerceContext db = new EcommerceContext(); string[] WorkingHour = null; if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday) { WorkingHour = db.Settings.AsNoTracking().ToList()[0].Sat.ToString().Split('-'); } else if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday) { WorkingHour = db.Settings.AsNoTracking().ToList()[0].Sun.ToString().Split('-'); } else if (DateTime.Now.DayOfWeek == DayOfWeek.Monday) { WorkingHour = db.Settings.AsNoTracking().ToList()[0].Mon.ToString().Split('-'); } else if (DateTime.Now.DayOfWeek == DayOfWeek.Tuesday) { WorkingHour = db.Settings.AsNoTracking().ToList()[0].Tue.ToString().Split('-'); } else if (DateTime.Now.DayOfWeek == DayOfWeek.Wednesday) { WorkingHour = db.Settings.AsNoTracking().ToList()[0].Wed.ToString().Split('-'); } else if (DateTime.Now.DayOfWeek == DayOfWeek.Thursday) { WorkingHour = db.Settings.AsNoTracking().ToList()[0].Thur.ToString().Split('-'); } else if (DateTime.Now.DayOfWeek == DayOfWeek.Friday) { WorkingHour = db.Settings.AsNoTracking().ToList()[0].Fri.ToString().Split('-'); } DateTime FromDateTime = DateTime.Parse(DateTime.Now.ToString("MM/dd/yyyy") + " " + WorkingHour[0]); DateTime ToDateTime = DateTime.Parse(DateTime.Now.ToString("MM/dd/yyyy") + " " + WorkingHour[1]); if (FromDateTime.ToString("tt").ToLower() == "pm" && ToDateTime.ToString("tt").ToLower() == "am") { ToDateTime = ToDateTime.AddDays(1); } double iWorkingHour = (ToDateTime - FromDateTime).TotalHours; double CurrentTotalHour = (DateTime.Now - FromDateTime).TotalHours; bool IsClosed = false; if ((CurrentTotalHour >= iWorkingHour) || (DateTime.Now < FromDateTime)) { IsClosed = true; } CheckOutViewModel chkOut = new CheckOutViewModel(); var assignedProductList = new List <AddToCart>(); var productList = _productBusiness.GetListWT(); var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString()); if (!string.IsNullOrEmpty(products)) { assignedProductList = (from p in products.Split(',') select new AddToCart { ProductId = Convert.ToInt32(p.Split('~')[0]), Quantity = Convert.ToInt32(p.Split('~')[1]), Size = Convert.ToInt32(p.Split('~')[2]), Attributes = p.Split('~')[3] }).ToList(); } else { //Can't place order if cart empty // display message here } //assignedProductList = _AddToCartBusiness.GetListWT(c => c.UserId == currentUserId); //showing cartdata to checkout var imgList = _ImageBusiness.GetListWT(); var vmProductList = (from c in productList join ap in assignedProductList on c.ProductID equals ap.ProductId select new CartWishlistViewModel { ProductID = c.ProductID, ProductCode = c.ProductCode, ProductName = c.ProductName, TokenKey = c.TokenKey, ShortDescription = c.ShortDescription, Price = _productBusiness.GetSelectedPrice(c.ProductID, ap.Size.GetValueOrDefault(), ap.Attributes), DiscountPercent = c.DiscountPercent, DiscountedPrice = 0, //Math.Round(_productBusiness.GetSelectedPrice(c.ProductID, ap.Size.Value, ap.Attributes) - Decimal.Divide(c.DiscountPercent ?? 0, 100) * _productBusiness.GetSelectedPrice(c.ProductID, ap.Size.Value, ap.Attributes)), SizeId = ap.Size.Value, Size = _productBusiness.GetSizeName(c.ProductID, ap.Size.GetValueOrDefault()), AttributeId = ap.Attributes, Attributes = _productBusiness.GetAttributes(c.ProductID, ap.Attributes), quantity = ap.Quantity, ImageList = (from il in imgList where (il.ProductId == c.ProductID) select new ImageViewModel { ProductId = c.ProductID, Images = "/ProductImage/" + il.Images }).ToList() }).ToList(); chkOut.OrderList = vmProductList; _userBusiness = new UserBusiness(); Entities.Models.User CurrentUser = (Entities.Models.User)Session["CurrentUserInfo"]; var currentUser = _userBusiness.GetUserByemail(CurrentUser.Email); chkOut.FirstNameShopper = currentUser.FirstName; chkOut.LastNameShopper = currentUser.LastName; chkOut.EmailShopper = currentUser.Email; chkOut.IsBlocked = currentUser.IsBlocked; chkOut.IsStoreClosed = IsClosed; return(View(chkOut)); }
// // GET: /ProductDetail/ public ActionResult Index(int productId) { var product = _productBusiness.GetListWT(c => c.ProductID == productId).FirstOrDefault(); var imgList = _ImageBusiness.GetListWT(c => c.ProductId == productId); Mapper.CreateMap <Product, ProductViewModel>(); var vmProduct = Mapper.Map <Product, ProductViewModel>(product); CookieStore mycookie = new CookieStore(); var assignedProductList = new List <AddToCart>(); var products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString()); if (!string.IsNullOrEmpty(products)) { assignedProductList = (from p in products.Split(',') select new AddToCart { ProductId = Convert.ToInt32(p.Split('~')[0]), Quantity = Convert.ToInt32(p.Split('~')[1]), Size = Convert.ToInt32(p.Split('~')[2]), Attributes = p.Split('~')[3] }).ToList(); } var productAssigned = assignedProductList.Where(c => c.ProductId == productId).FirstOrDefault(); if (productAssigned != null) { vmProduct.SizeId = productAssigned.Size.Value; vmProduct.Attributes = productAssigned.Attributes; vmProduct.Price = _productBusiness.GetSelectedPrice(productId, productAssigned.Size.Value, productAssigned.Attributes) * productAssigned.Quantity; vmProduct.ProductQuantity = productAssigned.Quantity; } else { var defaultSize = _productSizeBusiness.GetListWT(c => c.ProductId == productId).FirstOrDefault(); vmProduct.SizeId = defaultSize == null ? 0 : defaultSize.Id; vmProduct.Attributes = ""; vmProduct.Price = _productBusiness.GetDefaultPrice(productId); vmProduct.ProductQuantity = 1; } vmProduct.DiscountPercent = vmProduct.DiscountPercent ?? 0; vmProduct.DiscountedPrice = Math.Round(vmProduct.Price - Decimal.Divide(vmProduct.DiscountPercent ?? 0, 100) * vmProduct.Price); vmProduct.ImageList = (from il in imgList where (il.ProductId == product.ProductID) select new ImageViewModel { ProductId = product.ProductID, Images = "/ProductImage/" + il.Images }).ToList(); vmProduct.ProductSizeList = (from ps in _productSizeBusiness.GetListWT(c => c.ProductId == productId).ToList() select new ProductSizeViewModel { Id = ps.Id, ProductId = ps.ProductId, Price = ps.Price, Size = ps.Size }).ToList(); vmProduct.ProductAttributeList = (from ps in _productAttributeBusiness.GetListWT(c => c.ProductId == productId).ToList() select new ProductAttributeViewModel { Id = ps.Id, ProductId = ps.ProductId, Price = ps.Price, Attributes = ps.Attributes }).ToList(); var breadcrumb = new List <KeyValuePair <string, string> >(); breadcrumb.Add(new KeyValuePair <string, string>("Home", "/Home/index")); var category = _CategoryBusiness.GetListWT(c => c.CategoryId == vmProduct.CategoryId).FirstOrDefault(); if (category != null) { breadcrumb.Add(new KeyValuePair <string, string>(category.CategoryName, "/Product/index?categoryid=" + category.CategoryId)); } var subcategory = _SubCategoryBusiness.GetListWT(c => c.SubCategoryId == vmProduct.SubCategoryId).FirstOrDefault(); if (subcategory != null) { breadcrumb.Add(new KeyValuePair <string, string>(subcategory.SubCategoryName, "/Product/index?subcategoryid=" + subcategory.SubCategoryId)); } breadcrumb.Add(new KeyValuePair <string, string>(vmProduct.ProductName, "")); ViewBag.BreadCrumb = breadcrumb.ToList(); return(View(vmProduct)); }