Example #1
0
        public int SetGoodCartLocalStorage()
        {
            HttpContextBase context        = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request        = context.Request;
            Authentication  authentication = new Authentication(request);

            if (!string.IsNullOrEmpty(authentication.state))
            {
                return(0);
            }
            string cache_shopcar = request["cache_shopcar"];
            GoodCartLocalStorage goodCartLocalStorage = JsonConvert.DeserializeObject <GoodCartLocalStorage>(cache_shopcar);

            using (Entity entity = new Entity())
            {
                List <GoodCartView> GoodCartViewList = new List <GoodCartView>();
                foreach (var v in goodCartLocalStorage.cache_shopcar)
                {
                    int goodChildID = v.goodchildid;
                    int num         = v.num;
                    var goodChild   = entity.GoodChild.Include("Good").Where(o => o.GoodChildID == goodChildID && o.State == 1).FirstOrDefault();
                    if (goodChild != null)
                    {
                        if ((goodChild.Good.State & 2) == 0)
                        {
                            continue;
                        }

                        var t = entity.GoodCart.Where(o => o.UserID == authentication.userID && o.GoodChildID == goodChild.GoodChildID).FirstOrDefault();
                        if (t == null)
                        {
                            GoodCart goodCart = new GoodCart();
                            goodCart.UserID      = authentication.userID;
                            goodCart.GoodChildID = goodChildID;
                            goodCart.GoodID      = goodChild.GoodId;
                            goodCart.CreateTime  = DateTime.Now;
                            goodCart.Num         = num;
                            entity.GoodCart.Add(goodCart);
                        }
                        else
                        {
                            t.Num += num;
                        }
                    }
                }
                return(entity.SaveChanges());
            }
        }
Example #2
0
        public int SetGoodCart()
        {
            HttpContextBase context        = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request        = context.Request;
            Authentication  authentication = new Authentication(request);

            if (!string.IsNullOrEmpty(authentication.state))
            {
                return(0);
            }

            using (Entity entity = new Entity())
            {
                int goodchildid = Convert.ToInt32(request["goodchildid"]);
                var goodChild   = entity.GoodChild.Find(goodchildid);
                if (goodChild == null || goodChild.State == 0 || (goodChild.Good.State & 2) == 0)
                {
                    return(0);
                }
                var t = entity.GoodCart.Where(o => o.UserID == authentication.userID && o.GoodChildID == goodChild.GoodChildID).FirstOrDefault();
                if (t == null)
                {
                    GoodCart goodCart = new GoodCart();
                    goodCart.UserID      = authentication.userID;
                    goodCart.GoodChildID = goodchildid;
                    goodCart.GoodID      = goodChild.GoodId;
                    goodCart.CreateTime  = DateTime.Now;
                    goodCart.Num         = Convert.ToInt32(request["num"]);
                    entity.GoodCart.Add(goodCart);
                }
                else
                {
                    t.Num += Convert.ToInt32(request["num"]);
                }

                return(entity.SaveChanges());
            }
        }