public bool IsNewReplyBindingModelValid(HttpSession session, NewReplyBindingModel nrbm, int id) { if (this.Context.Topics.Any(tid => tid.Id == id)) { return(true); } return(false); }
public void Details(HttpResponse response, HttpSession session, NewReplyBindingModel nrbm, int id) { if (this.signInManagerService.IsAuthenticated(session)) { if (this.topicsService.IsNewReplyBindingModelValid(session, nrbm, id)) { this.topicsService.AddNewReplyToTopic(session, nrbm, id); } } this.Redirect(response, $"/topics/details?id={id}"); }
public void AddNewReply(int topicId, User user, NewReplyBindingModel model) { var reply = new Reply() { Content = model.Content, PublishDate = DateTime.Now, ImageUrl = model.ImageUrl, TopicId = topicId, Author = user }; this.Context.Replies.Add(reply); this.Context.SaveChanges(); }
public IActionResult Details(int id, HttpResponse response, HttpSession session, NewReplyBindingModel npbm) { if (!AuthenticationManager.IsAuthenticated(session)) { this.Redirect(response, "/forum/login"); return(null); } var user = AuthenticationManager.GetAuthenticatedUser(session.Id); this.service.AddNewReply(id, user, npbm); this.Redirect(response, $"/topics/details?id={id}"); return(null); }
public IHttpActionResult PostAddNewReply(int postId, NewReplyBindingModel model) { var post = this.Data.Posts.GetById(postId); if (post == null) { return(this.BadRequest(Messege.NoSuchPostError)); } if (model == null) { return(this.BadRequest("Empty reply is not allowed!")); } if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var user = this.Data.ApplicationUsers.GetById(this.User.Identity.GetUserId()); var reply = new Reply() { Author = user, Comment = model.Comment, Post = post }; var replyView = new ReplyViewModel() { AuthorName = user.UserName, Comment = model.Comment, CreateAt = reply.CreatedAt, RepliedPostId = postId }; post.Replies.Add(reply); this.Data.SaveChanges(); return(this.Ok(replyView)); }
public void AddNewReplyToTopic(HttpSession session, NewReplyBindingModel nrbm, int id) { User user = this.signInManagerService.GetAuthenticatedUser(session); Reply reply = new Reply(); reply.Author = user; reply.Content = nrbm.Content; reply.PublishDate = DateTime.Now; if (nrbm.ImgUrl != "") { reply.ImgUrl = nrbm.ImgUrl; } reply.Topic = this.Context.Topics.Where(tid => tid.Id == id).FirstOrDefault(); this.Context.Replies.Add(reply); this.Context.SaveChanges(); }
public IHttpActionResult PostAddNewReply(int postId, NewReplyBindingModel model) { var post = this.Data.Posts.GetById(postId); if (post == null) { return this.BadRequest(Messege.NoSuchPostError); } if (model == null) { return this.BadRequest("Empty reply is not allowed!"); } if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var user = this.Data.ApplicationUsers.GetById(this.User.Identity.GetUserId()); var reply = new Reply() { Author = user, Comment = model.Comment, Post = post }; var replyView = new ReplyViewModel() { AuthorName = user.UserName, Comment = model.Comment, CreateAt = reply.CreatedAt, RepliedPostId = postId }; post.Replies.Add(reply); this.Data.SaveChanges(); return this.Ok(replyView); }