예제 #1
0
        public ActionResult GetPostsByDiscussion(int id)
        {
            var discussion = _discussionService.GetDiscussionID(id);

            var posts = discussion.Posts;


            //Map values given in new model to respective values in raw entities
            var listofPosts = posts.Select(post => new ListPostsModel
            {
                Id                    = post.Id,
                AuthorId              = post.ApplicationUser.Id,
                AuthorName            = post.ApplicationUser.UserName,
                AuthorRating          = post.ApplicationUser.Rating,
                Title                 = post.Title,
                DatePosted            = post.Created.ToString(),
                RepliesCount          = post.Replies.Count(),
                DiscussionId          = post.Discussion.Id,
                DiscussionName        = post.Discussion.Title,
                DiscussionDescription = post.Discussion.Description,
            });


            //Use custom model to grab a collection of the "ListofPosts" model & use NewDiscussion model from earlier to map values
            var model = new DiscussionPostViewModel
            {
                //Map values given in custom models
                Posts      = listofPosts,
                Discussion = BuildNewDiscussion(discussion),
            };

            //return the model to be accessed in viewpage
            //return View(model);
            return(View(model));
        }
예제 #2
0
        public ActionResult AddPost(int id)
        {
            //Find the id of discussion to be posted in
            var discussion = _discussionService.GetDiscussionID(id);

            //Call on new model and get values outside of raw Post entity
            AddPostViewModel addPost = new AddPostViewModel();

            addPost.DicussionName = discussion.Title;
            addPost.DiscussionId  = discussion.Id;

            return(View(addPost));
        }
예제 #3
0
        public ActionResult UpdateDiscussion(int id)
        {
            Discussion discussion = _discussionService.GetDiscussionID(id);

            return(View(discussion));
        }
예제 #4
0
 public Discussion GetDiscussionID(int id)
 {
     return(_dao.GetDiscussionID(id));
 }