Ejemplo n.º 1
0
        public async Task <ActionResult> Index()
        {
            /*IEnumerable<ForumListingModel> forums = _forum.GetAll()
             *  .Select(forum => new ForumListingModel {
             *  Id = forum.Id,
             *  Title = forum.Title,
             *  Description = forum.Description
             * });*/
            var s = await _forum.GetAll();

            //var model = new ForumListingModel();
            var model = new ForumListingModel(s);

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeleteForum(ForumListingModel model, ApplicationUser user, int id)
        {
            var forum = _forumService.GetById(model.Id);
            //await _postService.Delete(id);
            var posts = _context.Posts.Where(p => p.Forum.Id == id).ToList();

            posts.ForEach(p =>
            {
                var replies = _context.PostReplies.Where(r => r.Post.Id == p.Id).ToList();
                replies.ForEach(r => _context.PostReplies.Remove(r));
                _context.Posts.Remove(p);
            });
            _context.Forums.Remove(forum);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Forum"));
        }