public static int SetSessionValue(int ID, int Type) { string Name = "CartPicks"; //string sessionVal = String.Empty; List<CartItems> cartItems = new List<CartItems>(); if (HttpContext.Current.Session[Name] != null) { try { cartItems = (List<CartItems>)HttpContext.Current.Session[Name]; CartItems newItem = new CartItems(); bool hasItem = cartItems.Any(c => c.ItemId == ID); if (!hasItem) { newItem.ItemId = ID; if (Type == 1) { newItem.CatId = 3; newItem.GrpChk = true; } else { if (Type == 3) { newItem.CatId = 3; } else { newItem.CatId = 5; } newItem.GrpChk = false; } newItem.Qty = 1; cartItems.Add(newItem); HttpContext.Current.Session[Name] = cartItems; return 1; } else { var cartItems2 = (List<CartItems>)HttpContext.Current.Session["CartPicks"]; if (cartItems2 != null) { var cartItem = cartItems2.First(p => p.ItemId == ID); int qty = cartItem.Qty + 1; cartItem.Qty = qty; HttpContext.Current.Session["CartPicks"] = cartItems; } return 2; } } catch { return 0; throw; } } else { return 0; } }
public static bool SetSessionValue(string ID, int Type, string Size) { string Name = "CartPicks"; //string sessionVal = String.Empty; List<CartItems> cartItems = new List<CartItems>(); if (HttpContext.Current.Session[Name] != null) { try { cartItems = (List<CartItems>)HttpContext.Current.Session[Name]; CartItems newItem = new CartItems(); bool hasItem = cartItems.Any(c => c.ItemId == int.Parse(ID) && c.TypeCheck == Size); if (!hasItem) { newItem.ItemId = int.Parse(ID); if (Type == 0) { newItem.CatId = 1; newItem.GrpChk = true; } else { //if (Type == 3) //{ // newItem.CatId = 3; //} //else //{ // newItem.CatId = 5; //} newItem.CatId = Type; newItem.GrpChk = false; } newItem.Qty = 1; newItem.TypeCheck = Size; cartItems.Add(newItem); HttpContext.Current.Session[Name] = cartItems; return true; } else { return false; } } catch { return false; throw; } } else { return false; } }