Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        public ActionResult Size(string tkn)
        {
            var product   = _productBusiness.GetListWT(c => c.TokenKey == tkn).FirstOrDefault();
            int productId = product.ProductID;
            var sizeList  = _productSizeBusiness.GetListWT(c => c.ProductId == productId);

            Mapper.CreateMap <Product, ProductViewModel>();
            var vmProduct = Mapper.Map <Product, ProductViewModel>(product);

            vmProduct.ProductSizeList = (from il in sizeList
                                         where (il.ProductId == product.ProductID)
                                         select new ProductSizeViewModel
            {
                Id = il.Id,
                ProductId = product.ProductID,
                Size = il.Size,
                Price = il.Price
            }).ToList();
            return(PartialView("_Size", vmProduct));
        }
Esempio n. 3
0
        //
        // 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));
        }