zoukankan      html  css  js  c++  java
  • Mvc4.0 提取 Cookie 里的东西

    /// <summary>
            /// 提取Cookie
            /// </summary>
            /// <returns></returns>
            public static List<ShoppingGoods> TiQuCookies()
            {
                ShoppingMallContext db = new ShoppingMallContext();
                List<ShoppingGoods> listgoods = new List<ShoppingGoods>();
                var allgoods = HttpContext.Current.Request.Cookies["MyShoppingCart"];
                if (allgoods == null)
                {
                    return null;
                }
                else
                {
                    string agoods = allgoods.Value;
                    agoods = agoods.Substring(0, agoods.Length - 1);
                    var agods = agoods.Split(',');
                    for (int i = 0; i < agods.Count(); i++)
                    {
                        var spt = agods[i].Split('-');
                        string skuID = spt[0];
                        int skuid = 0;
                        bool parseSkuIdOK = int.TryParse(skuID, out skuid);
     
                        string skuCount = spt[1];
                        int skuCont = 0;
                        bool parseSkuCountOK = int.TryParse(skuCount, out skuCont);
                        if (parseSkuIdOK == false || parseSkuCountOK == false)
                        {
                            return null;
                        }
                        else
                        {
                            ShoppingGoods sc = new ShoppingGoods();
                            var goods = db.GoodsSKUs
                                    .Where(f => f.GoodsSkuID == skuid)
                                    .Select(f => f.GoodsID).ToArray()[0];
     
                            var goodsSKU = db.GoodsSKUs
                                        .Where(f => f.GoodsSkuID == skuid)
                                        .Single();
                            var gs = db.Goodss
                                        .Where(f => f.GoodsID == goodsSKU.GoodsID)
                                        .Select(f => f.GoodsName);
                            sc.GoodsName = gs.ToArray()[0];
                            sc.Count = skuCont;
                            sc.Goodssku = goodsSKU;
     
                            listgoods.Add(sc);
                        }
                    }
                    return listgoods;
                }
            }
    View Code

        

  • 相关阅读:
    nginx原理及常用配置
    课程作业03-1
    Java动手动脑02
    Java课程作业02
    java课堂测试2
    Java验证码程序
    课程作业02-2
    课程作业02-1
    课程作业01
    《大道至简》第一章伪代码
  • 原文地址:https://www.cnblogs.com/LindaLiu/p/4600468.html
Copyright © 2011-2022 走看看