// GET: Card public ActionResult Index() { ViewBag.setting = context.Settings.FirstOrDefault(); vmCard card = new vmCard(); card.Tags = context.Tags.ToList(); card.Blogs = context.Blogs.ToList(); card.InstaFeeds = context.InstaFeeds.ToList(); if (Request.Cookies["Card"] != null) { List <string> Card = Request.Cookies["Card"].Value.Split(',').ToList(); Card.RemoveAt(Card.Count - 1); ViewBag.CardCount = Card.Count; card.Menu = context.Menus.Where(c => Card.Contains(c.Id.ToString()) == true).ToList(); } return(View(card)); }
public JsonResult AddToCard(int?id) { vmCard vmCard = new vmCard(); HttpCookie cookie2 = Request.Cookies["Card"]; List <string> Card = new List <string>(); if (Request.Cookies["Card"] != null) { Card = cookie2.Value.Split(',').ToList(); Card.RemoveAt(Card.Count - 1); } if (id != null) { if (Request.Cookies["Card"] != null) { string oldList = Request.Cookies["Card"].Value; List <string> oldListArr = oldList.Split(',').ToList(); HttpCookie cookie = new HttpCookie("Card"); cookie.Value = oldList; if (!oldListArr.Any(c => c == id.ToString())) { cookie.Value += id + ","; Card.Add(id.ToString()); Request.Cookies["Card"].Expires = DateTime.Now.AddYears(1); Response.Cookies.Add(cookie); vmCard.Response = "success-true"; } else { oldListArr.Remove(id.ToString()); Card.Remove(id.ToString()); oldList = string.Join(",", oldListArr); cookie.Value = oldList; Request.Cookies["Card"].Expires = DateTime.Now.AddYears(1); Response.Cookies.Add(cookie); vmCard.Response = "success-false"; } } else { HttpCookie cookie = new HttpCookie("Card"); cookie.Expires = DateTime.Now.AddYears(1); cookie.Value += id + ","; Card.Add(id.ToString()); Response.Cookies.Add(cookie); vmCard.Response = "success-true"; } } else { vmCard.Response = "error"; } #region Card if (Request.Cookies["Card"] != null) { vmCard.Menu = context.Menus.ToList().Where(m => Card.Any(c => Convert.ToInt32(c) == m.Id)).ToList(); } #endregion return(Json(vmCard, JsonRequestBehavior.AllowGet)); }