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)); }
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)); }
public ActionResult UpdateDiscussion(int id) { Discussion discussion = _discussionService.GetDiscussionID(id); return(View(discussion)); }
public Discussion GetDiscussionID(int id) { return(_dao.GetDiscussionID(id)); }