public IActionResult DeletePost(int id) { FreeStuffDb db = new FreeStuffDb(_conStr); db.DeletePost(id); return(Redirect("/Home/Index")); }
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)); }
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")); }