public ViewResult ShowThread(int threadId, MessageModel mmodel = null) { ViewThreadModel model = new ViewThreadModel() { ThreadId = threadId }; if (mmodel != null) { mmodel.ThreadId = threadId; model.MessageModel = mmodel; } else { model.MessageModel = new MessageModel(); } DatabaseAccess client = DatabaseAccess.Instance; var TitleAndTags = client.GetThreadTitleAndTags(threadId); model.ThreadTopic = TitleAndTags.Item1; model.Tags = TitleAndTags.Item2; var messages = client.GetThreadContent(threadId); model.Messages = messages.Select(s => new ViewThreadModel.SingleMessage() { Content = s.Item1, Author = s.Item4, Score = s.Item3, PostDate = s.Item2, OrdNum = s.Item5 }).ToList(); return(View("ViewThread", model)); }
public IActionResult ViewThread(int id, int page = 1) { var model = new ViewThreadModel(lightThreadManager, id, page, lightSessionManager.GetCurrent().User.Id); var invisibleReplys = lightThreadManager.GetInvisibleReplys(model.Thread.Id, model.ReplysInfo); return(View(model)); }
public ActionResult ViewThread(ForumThreadRequestModel requestModel) { ViewThreadModel viewThreadModel = new ViewThreadModel() { Replies = new List <ForumReplyModel>() }; using (CGWebEntities entities = new CGWebEntities()) { ForumThread currentThread = entities.ForumThreads.Where(FT => FT.ThreadId.Equals(requestModel.ThreadId)).Single(); viewThreadModel.ParentTopic = currentThread.ParentForumTopic.ConvertToForumTopicModel(); if (!currentThread.ParentForumTopic.IsPublic && !Request.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } int currentPagingLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ForumReplyPagingLimit"]); viewThreadModel.CurrentPage = requestModel.CurrentPage; viewThreadModel.MaxPages = (int)Math.Ceiling((double)currentThread.ForumReplies.Count / (double)currentPagingLimit); viewThreadModel.CurrentThread = currentThread.ConvertToForumThreadModel(true); foreach (ForumReply reply in currentThread.ForumReplies.OrderBy(FR => FR.CreatedOn).Skip(requestModel.CurrentPage * currentPagingLimit).Take(currentPagingLimit)) { viewThreadModel.Replies.Add(reply.ConvertToThreadReplyModel(true)); } } return(View(viewThreadModel)); }
public ActionResult ViewThread(ForumReplyModel model) { ViewThreadModel viewThreadModel = new ViewThreadModel() { Replies = new List <ForumReplyModel>() }; using (CGWebEntities entities = new CGWebEntities()) { UserProfile currentUserProfile = entities.UserProfiles.Where(P => P.UserName.Equals(User.Identity.Name)).Single(); ForumReply newReply = new ForumReply() { CreatedBy = currentUserProfile.UserId, CreatedOn = DateTime.UtcNow, ModifiedOn = null, ParentThreadId = model.ThreadId, ReplyContent = model.ReplyContent, ReplyId = Guid.NewGuid() }; entities.ForumReplies.Add(newReply); entities.SaveChanges(); ModelState.Clear(); ForumThread currentThread = entities.ForumThreads.Where(FT => FT.ThreadId.Equals(model.ThreadId)).Single(); viewThreadModel.ParentTopic = currentThread.ParentForumTopic.ConvertToForumTopicModel(); if (!currentThread.ParentForumTopic.IsPublic && !Request.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } int currentPagingLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ForumReplyPagingLimit"]); viewThreadModel.MaxPages = (int)Math.Ceiling((double)currentThread.ForumReplies.Count / (double)currentPagingLimit); viewThreadModel.CurrentPage = viewThreadModel.MaxPages - 1; viewThreadModel.CurrentThread = currentThread.ConvertToForumThreadModel(true); foreach (ForumReply reply in currentThread.ForumReplies.OrderBy(FR => FR.CreatedOn).Skip(viewThreadModel.CurrentPage * currentPagingLimit).Take(currentPagingLimit)) { viewThreadModel.Replies.Add(reply.ConvertToThreadReplyModel(true)); } } return(View(viewThreadModel)); }