コード例 #1
0
        public void addItemToCart(int Id, ItemOrderEntity model)
        {
            ViewBag.CustomerDetail = objSession.GetSessionCustomer(this);
            ITEMDETAILS = _DataFactory.GetItemDetail().Where(t => t.ID == Id).FirstOrDefault();
            model.ItemId = Id;
            model.NAME_EN = ITEMDETAILS.NAME_EN;
            model.NAME_TH = ITEMDETAILS.NAME_TH;
            model.PRICE = ITEMDETAILS.PRICE;
            model.SHORT_DESCR_EN = ITEMDETAILS.SHORT_DESCR_EN;
            model.SHORT_DESCR_TH = ITEMDETAILS.SHORT_DESCR_TH;
            model.IMAGES = ITEMDETAILS.IMAGES;
            List<ItemOrderEntity> objOrderDetail = new List<ItemOrderEntity>();

            if (Session["Orders"] == null)
            {
                objOrderDetail.Add(model);
                Session["Orders"] = objOrderDetail;
                var json = JsonConvert.SerializeObject(objOrderDetail);
                var orderCookie = new HttpCookie("OrdersCookie", json);
                orderCookie.Expires.AddDays(365);
                this.ControllerContext.HttpContext.Response.SetCookie(orderCookie);

            }
            else
            {
                objOrderDetail = (List<ItemOrderEntity>)Session["Orders"];
                //Check items
                var currentItem = objOrderDetail.Where(p => p.ItemId == Id && p.Color == model.Color && p.Size == model.Size).FirstOrDefault();

                if (currentItem != null)
                {
                    //  currentItem.ForEach(p => p.Amount += model.Amount);
                    objOrderDetail.Where(p => p.ItemId == Id && p.Color == model.Color && p.Size == model.Size).ToList().ForEach(p => p.Amount += model.Amount);
                }
                else
                {
                    objOrderDetail.Add(model);
                }

                Session["Orders"] = objOrderDetail;
                var json = JsonConvert.SerializeObject(objOrderDetail);
                var orderCookie = new HttpCookie("OrdersCookie", json);
                orderCookie.Expires.AddDays(365);
                this.ControllerContext.HttpContext.Response.SetCookie(orderCookie);
            }
        }
コード例 #2
0
        public ActionResult RemoveItem(int Id)
        {
            ViewBag.CustomerDetail = objSession.GetSessionCustomer(this);
            RedirectToRouteResult r = RedirectToAction("Index", "Cart");
            if (Session["Orders"] != null)
            {
                ItemOrderEntity objOrderEntity = new ItemOrderEntity();
                List<ItemOrderEntity> objOrderDetail = (List<ItemOrderEntity>)Session["Orders"];
                objOrderEntity = objOrderDetail.Where(p => p.ItemId == Id).FirstOrDefault();
                objOrderDetail.Remove(objOrderEntity);
                Session["Orders"] = objOrderDetail;
                var json = JsonConvert.SerializeObject(objOrderDetail);
                var orderCookie = new HttpCookie("OrdersCookie", json);
                orderCookie.Expires.AddDays(365);
                this.ControllerContext.HttpContext.Response.SetCookie(orderCookie);
            }

            return r;
        }
コード例 #3
0
        public ActionResult Detail(int Id, ItemOrderEntity model, String button)
        {
            RedirectToRouteResult r = RedirectToAction("Index", "Cart");
            T_CUSTOMER objCustomer = objSession.GetSessionCustomer(this);
            switch (button)
            {
                case "Add":
                    r = RedirectToAction("Index", "Cart");
                    addItemToCart(Id, model);
                    break;
                case "Wishlist":
                    if (objCustomer != null)
                    {
                        r = RedirectToAction("Detail", "Item");
                        addItemToWislist(Id, objCustomer.ID);
                    }
                    else
                    {
                        r = RedirectToAction("Login", "Home");
                    }

                    break;
                default:

                    break;
            }

            return r;
        }
コード例 #4
0
        public ActionResult Categories(int Id, int page = 1, ItemOrderEntity model = null)
        {
            List<ProductsEntity> objProducts = null;
            if (model.NAME_EN != null)
            {
                Session["CURRENTSORT"] = model.NAME_EN;
            }
            else
            {
                if (Session["CURRENTSORT"] == null)
                {
                    Session["CURRENTSORT"] = "";
                }
                model.NAME_EN = Session["CURRENTSORT"].ToString();
            }

            switch (model.NAME_EN)
            {
                case "Newest":
                    objProducts = _DataFactory.GetProductByCateId(Id).Where(p=>p.NEW_ARRIVAL_FLAG == 1).ToList();
                    break;
                case "OrderByAZ":
                    objProducts = _DataFactory.GetProductByCateId(Id).OrderBy(p => p.NAME_EN).ToList();
                    break;
                case "OrderByZA":
                    objProducts = _DataFactory.GetProductByCateId(Id).OrderByDescending(p => p.NAME_EN).ToList();
                    break;
                case "OrderByHL":
                    objProducts = _DataFactory.GetProductByCateId(Id).OrderBy(p => p.PRICE).ToList();
                    break;
                case "OrderByLH":
                    objProducts = _DataFactory.GetProductByCateId(Id).OrderByDescending(p => p.PRICE).ToList();
                    break;
                default:
                    objProducts = _DataFactory.GetProductByCateId(Id).OrderByDescending(p => p.ID).ToList();
                    break;
            }

            ViewBag.CustomerDetail = objSession.GetSessionCustomer(this);
            ViewBag.OrderDetail = objSession.GetSessionOrder(this);
            List<BannerEntity> Banners = _DataFactory.GetBanner();
            ViewBag.BANNER = Banners.Where(p => p.Type.ToUpper() == "CATEGORY" && p.RefId == Id).FirstOrDefault();
            if ( _DataFactory.GetCategoriesById(Id) != null)
            {
                ViewBag.Title = "SHOP A HORIC By Jiffy | Categories | " + _DataFactory.GetCategoriesById(Id).NAME_EN.ToString();
            }

            ViewBag.objProducts = objProducts;
            return View(objProducts.ToPagedList(page, 20));
        }