Exemple #1
0
        public IActionResult NewAd(Post post)
        {                                                    //post came with a name, a phone number, and text
            SimpleAdDb db = new SimpleAdDb();

            db.AddPost(post);                                //now my post has the id, too
            List <int> adIds = HttpContext.Session.Get <List <int> >("adIds");

            if (adIds == null)
            {
                adIds = new List <int>();
            }
            adIds.Add(post.Id);
            HttpContext.Session.Set("adIds", adIds);
            return(Redirect("/home/index"));
        }
        public IActionResult NewAd(Post post)
        {
            SimpleAdDb db = new SimpleAdDb();

            db.AddPost(post);
            string postIds = "";

            if (Request.Cookies["postIds"] != null)
            {
                postIds += Request.Cookies["postIds"];              //getting the previous cookie
                postIds += ",";                                     //adding a comma to the end of it (not to the new one after)
            }
            postIds += $"{post.Id}";                                //adding the newest id to the string
            Response.Cookies.Append("postIds", postIds);            //overriding the cookie with the new string
            return(Redirect("/cookies/index"));
        }