Esempio n. 1
0
        public IActionResult DeletePost(int id)
        {
            FreeStuffDb db = new FreeStuffDb(_conStr);

            db.DeletePost(id);
            return(Redirect("/Home/Index"));
        }
Esempio n. 2
0
        public IActionResult Index()
        {
            IndexViewModel     vm    = new IndexViewModel();
            FreeStuffDb        db    = new FreeStuffDb(_conStr);
            List <int>         ids   = HttpContext.Session.Get <List <int> >("ListingIds");
            IEnumerable <Post> posts = db.GetAllPosts();

            vm.Posts = posts.Select(p => new PostViewModel
            {
                Post      = p,
                CanDelete = ids != null && ids.Contains(p.Id)
            });
            return(View(vm));
        }
Esempio n. 3
0
        public IActionResult AddPost(Post p)
        {
            FreeStuffDb db = new FreeStuffDb(_conStr);

            db.AddPost(p);

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

            if (ids == null)
            {
                ids = new List <int>();
            }
            ids.Add(p.Id);
            HttpContext.Session.Set("ListingIds", ids);

            return(Redirect("/Home/Index"));
        }