• 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

        

  • 相关阅读:
    [LeetCode] Walls and Gates
    [LeetCode] Expression Add Operators
    [LeetCode] Inorder Successor in BST
    [LeetCode] Peeking Iterator
    [CTCI] 最小调整有序
    [LeetCode] Single Number III
    [LeetCode] Zigzag Iterator
    [LeetCode] Wiggle Sort
    android 设颜色透明值
    android android BitmapFactory报错OOM
  • 原文地址:https://www.cnblogs.com/LindaLiu/p/4600468.html
Copyright © 2020-2023  润新知