public static TopicInfo GetTopic(int topicid) { ITopic dal = Factory <ITopic> .Create("Topic"); TopicInfo topic = dal.GetById(topicid); if (topic != null) { topic.Forum = Forums.GetForum(topic.ForumId); topic.PollId = GetTopicPollId(topicid); topic.IsArchived = false; } else { //let's check archives IArchiveForum archDal = Factory <IArchiveForum> .Create("ArchiveForums"); topic = archDal.GetTopic(topicid); if (topic != null) { topic.Forum = Forums.GetForum(topic.ForumId); topic.IsArchived = true; } } return(topic); }
public async Task <IActionResult> Post([FromBody] NewPost post) { try { if (ModelState.IsValid) { var topic = _topicService.GetById(post.TopicId); var user = _userManager.FindByIdAsync(post.User.Id).Result; post.User = user; post.Topic = topic; if (_context.Posts.Any(p => p.Content == post.Content)) { return(BadRequest("Post with this content already exist")); } await _postService.Add(post); await _context.SaveChangesAsync(); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. return(BadRequest("Unable to save changes. Try again...")); } return(CreatedAtAction(nameof(Get), new { id = post.Id }, post)); }
public static bool IsTopicAuthor(int memberid, int topicid) { ITopic dal = Factory <ITopic> .Create("Topic"); TopicInfo topic = dal.GetById(topicid); return(topic.AuthorId == memberid); }
public static void MoveReplies(int newtopicid, List <int> replyIDs) { ITopic topicdal = Factory <ITopic> .Create("Topic"); TopicInfo topic = topicdal.GetById(newtopicid); IReply dal = Factory <IReply> .Create("Reply"); dal.MoveReplies(topic, replyIDs); Admin.UpdateForumCounts(); }
public IActionResult Edit(int id) { var topic = _topicService.GetById(id); var model = new NewTopic { CategoryId = topic.Category.Id, Title = topic.Title, }; if (topic.User.UserName != User.Identity.Name) { return(NotFound()); } if (topic == null) { return(NotFound()); } return(View(model)); }
public TopicPage CreatePostsByTopic(int id) { var topic = _topicService.GetById(id); var posts = topic.Posts; var postListing = posts.Select(post => new PostListing { AuthorName = post.User.UserName, Content = post.Content, DatePosted = post.Created.ToString(), PostId = post.Id, AuthorImageURL = post.User.ProfileImageUrl, AuthorId = post.User.Id }); return(new TopicPage() { Posts = postListing, TopicTitle = topic.Title, CategoryTitle = topic.Category.Title, CategoryId = topic.Category.Id, TopicId = topic.Id }); }
public Topic Get(int id) { return(_topicService.GetById(id)); }