コード例 #1
0
        public IActionResult NewAd(Post post)
        {
            FreebayDb db = new FreebayDb(_connectionString);

            if (post.Name != null)
            {
                db.AddPost(post, true);
            }
            else
            {
                db.AddPost(post, false);
            }


            var ids = HttpContext.Session.Get <List <int> >("Ids");

            if (ids == null)
            {
                ids = new List <int>();
            }

            ids.Add(post.Id);
            HttpContext.Session.Set("Ids", ids);
            return(Redirect("/Home/Index"));
        }
コード例 #2
0
        public IActionResult Delete(int id)
        {
            var db = new FreebayDb(_connectionString);

            db.Delete(id);
            return(Redirect("/Home/Index"));
        }
コード例 #3
0
        public IActionResult Index()
        {
            var        db   = new FreebayDb(_connectionString);
            List <int> list = HttpContext.Session.Get <List <int> >("Ids");

            if (list == null)
            {
                list = new List <int>();
            }
            HttpContext.Session.Set("Ids", list);
            var vm = new GetAllViewModel
            {
                Ids   = list,
                Posts = db.GetAllPosts()
            };

            return(View(vm));
        }