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()); } }
public IEnumerable <GoodCartView> GetGoodCartLocalStorage() { HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; HttpRequestBase request = context.Request; 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 = GoodCartViewList.Find(o => o.goodChildID == goodChildID); if (t != null) { t.num += num; } else { GoodCartViewList.Add(new GoodCartView() { img = ConfigurationManager.AppSettings["UploadUrl"] + goodChild.Image, title = goodChild.Good.Title, guige = goodChild.Specification, num = num, price = goodChild.AddPrice + goodChild.Good.RealPrice, goodChildID = goodChild.GoodChildID, goodID = goodChild.Good.GoodID }); } } } return(GoodCartViewList); } }
public GoodOrderView GetGoodOrderView() { HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; HttpRequestBase request = context.Request; string cache_shopcar = request["cache_shopcar"]; GoodCartLocalStorage goodCartLocalStorage = JsonConvert.DeserializeObject <GoodCartLocalStorage>(cache_shopcar); List <GoodCartView> GoodCartViewList = new List <GoodCartView>(); GoodOrderView goodOrderView = new GoodOrderView(); goodOrderView.GoodCartViewList = GoodCartViewList; using (Entity entity = new Entity()) { 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 = GoodCartViewList.Find(o => o.goodChildID == goodChildID); if (t != null) { t.num += num; } else { GoodCartViewList.Add(new GoodCartView() { img = ConfigurationManager.AppSettings["UploadUrl"] + goodChild.Image, title = goodChild.Good.Title, guige = goodChild.Specification, num = num, price = goodChild.AddPrice + goodChild.Good.RealPrice, goodChildID = goodChild.GoodChildID, }); } if (goodOrderView.baoyou == false) { goodOrderView.baoyou = (goodChild.Good.State & 32) > 0; } } } goodOrderView.shangpinzhongji = goodOrderView.GoodCartViewList.Sum(o => o.price * o.num); goodOrderView.zhifuzongfeiyong = goodOrderView.shangpinzhongji; WholeFieldActivity wholeFieldActivity = entity.WholeFieldActivity.Where(o => o.Type == 0).FirstOrDefault(); if (wholeFieldActivity != null) { if (goodOrderView.zhifuzongfeiyong >= wholeFieldActivity.FillPrice) { if (wholeFieldActivity.DiscountPrice != null) { goodOrderView.zhifuzongfeiyong -= wholeFieldActivity.DiscountPrice.Value; goodOrderView.huodong += wholeFieldActivity.Title + " "; } } } if (!goodOrderView.baoyou) { wholeFieldActivity = entity.WholeFieldActivity.Where(o => o.Type == 1).FirstOrDefault(); if (wholeFieldActivity != null) { if (goodOrderView.zhifuzongfeiyong >= wholeFieldActivity.FillPrice) { goodOrderView.baoyou = true; goodOrderView.huodong += wholeFieldActivity.Title; } } if (!goodOrderView.baoyou) { goodOrderView.zhifuzongfeiyong += Convert.ToInt32(ConfigurationManager.AppSettings["LogisticsPrice"]); } } else { goodOrderView.huodong += "包邮"; } } //Authentication authentication = new Authentication(request); //if (string.IsNullOrEmpty(authentication.state)) //{ // goodOrderView.integralMoney = entity.UserExtend.Find(authentication.userID).Integral / 100; // if (goodOrderView.integralMoney > goodOrderView.zhifuzongfeiyong) // { // goodOrderView.integralMoney = goodOrderView.zhifuzongfeiyong; // } // goodOrderView.integral =Convert.ToInt32( goodOrderView.integralMoney * 100); //} return(goodOrderView); }