public async Task <IActionResult> AddComment([Bind("CommentID, CommentTitle, CommentText, PostID")] Comment comment, int?id) { // Set name of comment author to the name of current user. var user = await GetCurrentUserAsync(); comment.AuthorName = _userManager.GetUserName(User); // Adds comment to the database. _context.Comment.Add(comment); _context.SaveChanges(); // Selects post with the given id from the database. var post = await _context.Post.FirstOrDefaultAsync(m => m.PostId == id); // Selects all of the comments for the post with the given id. var comments = _context.Comment.Where(x => x.PostID == id).ToArray(); // Selects all of the likes for the post with the given id var likes = _context.Likes.Where(x => x.PostId == id).ToList(); // Packs everything to the view specific model that has post // And a list of comments and likes for this post. PostComments pc = new PostComments { Post = post, Comments = comments, Likes = likes }; return(RedirectToAction("Details", new { id = post.PostId })); }
public void WhenQueryingWillGoToTheRightServer_UsingQueryById() { store.Conventions.AllowQueriesOnId = true; using (var session = store.OpenAsyncSession()) { var p1 = new Post(); session.Store(p1); session.SaveChangesAsync().Wait(); var pc1 = new PostComments { PostId = p1.Id }; session.Store(pc1); session.SaveChangesAsync().Wait(); } foreach (var ravenDbServer in servers) { ravenDbServer.Value.Server.ResetNumberOfRequests(); } using (var session = store.OpenAsyncSession()) { var posts = session.Query <Post>().Where(x => x.Id == "tri/posts/1").ToListAsync().Result; Assert.NotEmpty(posts); } Assert.Equal(0, servers["one"].Server.NumberOfRequests); Assert.Equal(0, servers["two"].Server.NumberOfRequests); Assert.Equal(1, servers["tri"].Server.NumberOfRequests); }
public void WhenQueryingWillGoToTheRightServer_Loading() { using (var session = store.OpenSession()) { var p1 = new Post(); session.Store(p1); var pc1 = new PostComments { PostId = p1.Id }; session.Store(pc1); session.SaveChanges(); } foreach (var ravenDbServer in servers) { ravenDbServer.Value.Server.ResetNumberOfRequests(); } using (var session = store.OpenSession()) { Assert.NotNull(session.Load <Post>("tri/posts/1")); Assert.NotNull(session.Load <PostComments>("tri/PostComments/1")); } Assert.Equal(0, servers["one"].Server.NumberOfRequests); Assert.Equal(0, servers["two"].Server.NumberOfRequests); Assert.Equal(2, servers["tri"].Server.NumberOfRequests); }
public async Task <IActionResult> PutPostComments(Guid id, PostComments postComments) { if (id != postComments.Id) { return(BadRequest()); } _context.Entry(postComments).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostCommentsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,PostId,CommentId")] PostComments postComments) { if (id != postComments.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(postComments); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostCommentsExists(postComments.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CommentId"] = new SelectList(_context.Comments, "Id", "Id", postComments.CommentId); ViewData["PostId"] = new SelectList(_context.Post, "Id", "Id", postComments.PostId); return(View(postComments)); }
public PostComments ReadAllById(int postId, int offset) { int cmtsCount = 0; PostComments data = new PostComments(); List <NewsFeedCommentProfile> comments = new List <NewsFeedCommentProfile>(); DataProvider.ExecuteCmd("dbo.NewsFeedComment_SelectAllByPostId", inputParamMapper: (SqlParameterCollection inputs) => { inputs.Add(SqlDbParameter.Instance.BuildParameter("@PostId", postId, SqlDbType.Int)); inputs.Add(SqlDbParameter.Instance.BuildParameter("@Offset", offset, SqlDbType.Int)); inputs.Add(SqlDbParameter.Instance.BuildParameter("@TotalCmts", 0, SqlDbType.Int, paramDirection: ParameterDirection.Output)); }, singleRecordMapper: (IDataReader reader, short resultSet) => { if (resultSet == 0) { comments.Add(DataMapper <NewsFeedCommentProfile> .Instance.MapToObject(reader)); } }, returnParameters: (SqlParameterCollection inputs) => { int.TryParse(inputs["@TotalCmts"].Value.ToString(), out cmtsCount); }); data.TotalCmts = cmtsCount; data.Comments = comments; return(data); }
string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish) { var user = ValidateUser(username, password); var comments = new PostComments(); session.Store(comments); var publishDate = post.dateCreated == null ? postScheduleringStrategy.Schedule() : postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value)); var newPost = new Models.Post { AuthorId = user.Id, Body = post.description, CommentsId = comments.Id, CreatedAt = DateTimeOffset.Now, SkipAutoReschedule = post.dateCreated != null, PublishAt = publishDate, Tags = post.categories, Title = post.title, CommentsCount = 0, }; session.Store(newPost); session.SaveChanges(); return(newPost.Id); }
public void WillGetGoodLocalityOfReference() { using (var session = store.OpenSession()) { var p1 = new Post(); session.Store(p1); var p2 = new Post(); session.Store(p2); var pc1 = new PostComments { PostId = p1.Id }; session.Store(pc1); var pc2 = new PostComments { PostId = p2.Id }; session.Store(pc2); session.SaveChanges(); Assert.Equal("tri/posts/1", p1.Id); Assert.Equal("two/posts/2", p2.Id); Assert.Equal("tri/PostComments/1", pc1.Id); Assert.Equal("two/PostComments/2", pc2.Id); } }
// GET: Comments public ActionResult Index(string postSlug) { if (string.IsNullOrWhiteSpace(postSlug)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostComments postComments = db.Posts .Include(p => p.Comments.Select(c => c.Author)) .Where(p => p.Slug == postSlug) .Select(p => new PostComments { Title = p.Title, Slug = p.Slug, Comments = p.Comments .OrderByDescending(c => c.Id) .ToList() }) .FirstOrDefault(); if (postComments == null) { return(HttpNotFound()); } return(View(postComments)); }
public void WhenQueryingWillGoToTheRightServer() { using (var session = store.OpenSession()) { var p1 = new Post(); session.Store(p1); var pc1 = new PostComments { PostId = p1.Id }; session.Store(pc1); session.SaveChanges(); } foreach (var ravenDbServer in servers) { ravenDbServer.Value.Server.ResetNumberOfRequests(); } using (var session = store.OpenSession()) { var posts = session.Query <PostComments>().Where(x => x.PostId == "tri/posts/1").ToList(); Assert.NotEmpty(posts); } Assert.Equal(0, servers["one"].Server.NumberOfRequests); Assert.Equal(0, servers["two"].Server.NumberOfRequests); Assert.Equal(1, servers["tri"].Server.NumberOfRequests); }
public async Task <PostComments> GetPostCommentsAsync(string id) { var postComments = new PostComments(); var response = await httpClient.GetStringAsync("http://www.reddit.com/r/comments/" + id + "/.json"); var jArray = JArray.Parse(response); var post = new Post(); post.Id = jArray[0]["data"]["children"][0]["data"]["id"].ToString(); post.Title = jArray[0]["data"]["children"][0]["data"]["title"].ToString(); post.Author = jArray[0]["data"]["children"][0]["data"]["author"].ToString(); post.Score = jArray[0]["data"]["children"][0]["data"]["score"].Value <int>(); post.Thumbnail = jArray[0]["data"]["children"][0]["data"]["thumbnail"].ToString(); post.Url = jArray[0]["data"]["children"][0]["data"]["url"].ToString(); post.NumberOfComments = jArray[0]["data"]["children"][0]["data"]["num_comments"].Value <int>(); postComments.Post = post; if (jArray.Count > 1) { var comments = ParseComments(jArray[1] as JObject); postComments.Comments = comments; } return(postComments); }
public ActionResult CreatePost(Posts posts, PostComments postscom) { int BoardID = Convert.ToInt32(Session["BoardID"]); int userid = Convert.ToInt32(Session["UserID"]); string timer = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); DateTime PubTime = DateTime.Parse(timer); string SectionName = Request.Form["selectdetailtype"]; if (posts.PostContent == null) { return(Content("<script>alert('帖子内容不能为空');window.open('" + Url.Action("CreatePost", "Tribune") + "', '_self'</script>")); } else { int SectionID = PostM.SelectSectionID(SectionName); posts.SectionID = SectionID; posts.UserID = userid; posts.PublishTime = PubTime; posts.PostFlag = 1; db.Posts.Add(posts); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); db.Configuration.ValidateOnSaveEnabled = true; int Lev = PostM.GetUserPotLev(Convert.ToInt32(Session["UserID"])); if (Lev != 0) { potsmanager.UpdateExperience(userid, 5); } return(RedirectToAction("BoardIndex", "Tribune", new { BoardID = BoardID })); } }
public ActionResult PostsDetails(PostComments postcom) { int userid = Convert.ToInt32(Session["UserID"]); int PostID = int.Parse(Session["PostID"].ToString()); postcom.PostCommentContent = Request.Form["PostCommentContent"]; if (postcom.PostCommentContent == "") { return(Content("<script>alert('评论内容不能为空');window.open('" + Url.Action("PostsDetails", "Tribune", new { PostID = PostID }) + "', '_self'</script>")); } else { postcom.UserID = Convert.ToInt32(Session["UserID"]); postcom.PostID = PostID; postcom.PostCommentTime = DateTime.Now; db.PostComments.Add(postcom); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); db.Configuration.ValidateOnSaveEnabled = true; int Lev = PostM.GetUserPotLev(Convert.ToInt32(Session["UserID"])); if (Lev != 0) { potsmanager.UpdateExperience(userid, 2); } return(RedirectToAction("PostsDetails", "Tribune", new { PostID = PostID })); } }
public async Task <IActionResult> Details(int?id) { // 404 if id isn't valid. if (id == null) { return(NotFound()); } // Returns first post with matching Id, or if is not found returns null. var post = await _context.Post .FirstOrDefaultAsync(m => m.PostId == id); var comments = _context.Comment.Where(x => x.PostID == id).ToList(); var likes = _context.Likes.Where(x => x.PostId == id).ToList(); PostComments pc = new PostComments { Post = post, Comments = comments, Likes = likes }; // 404 if post isn't valid. if (post == null) { return(NotFound()); } return(View(pc)); }
public ActionResult DeleteConfirmed(int id) { PostComments postComments = db.PostComments.Find(id); db.PostComments.Remove(postComments); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: CommentController public ActionResult Index(int id) { var vm = new PostComments(); vm.Comment = _commentRepo.GetCommentsByPostId(id); vm.Post = _postRepo.GetPublisedPostById(id); return(View(vm)); }
public ActionResult Update(PostInput input) { if (!ModelState.IsValid) { return(View("Edit", input)); } var post = RavenSession.Load <Post>(input.Id) ?? new Post { CreatedAt = DateTimeOffset.Now }; input.MapPropertiesToInstance(post); // Be able to record the user making the actual post var user = RavenSession.GetCurrentUser(); if (string.IsNullOrEmpty(post.AuthorId)) { post.AuthorId = user.Id; } else { post.LastEditedByUserId = user.Id; post.LastEditedAt = DateTimeOffset.Now; } if (post.PublishAt == DateTimeOffset.MinValue) { var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now); post.PublishAt = postScheduleringStrategy.Schedule(); } // Actually save the post now RavenSession.Store(post); if (input.IsNewPost()) { // Create the post comments object and link between it and the post var comments = new PostComments { Comments = new List <PostComments.Comment>(), Spam = new List <PostComments.Comment>(), Post = new PostComments.PostReference { Id = post.Id, PublishAt = post.PublishAt, } }; RavenSession.Store(comments); // Once the Comments have been saved, update and save the post post.CommentsId = comments.Id; RavenSession.Store(post); } return(RedirectToAction("Details", new { Id = post.MapTo <PostReference>().DomainId })); }
private void CommentRemove(PostComments coment, PaintStoreContext db) { db.PostComments.Remove(db.PostComments.First(x => x.Id == coment.Id)); ImagesManager.ImageCommentCountMinus(db, coment.PostId); foreach (var like in db.CommentLikes.Where(x => x.CommentId == coment.Id)) { db.CommentLikes.Remove(db.CommentLikes.First(x => x.Id == like.Id)); } }
public ActionResult CommentEdite(PostComments Model) { if (ModelState.IsValid) { db.Entry(Model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("PostCommentManage")); } return(RedirectToAction("PostCommentManage")); }
public ActionResult CommentEdite(int id) { PostComments model = db.PostCommentses.Find(id); if (model.ParentID != null) { ViewBag.parenttext = db.PostCommentses.Find(model.ParentID).Comment; } return(PartialView(model)); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { _navigationHelper.OnNavigatedTo(e); string id = (string)e.Parameter; PostComments postComments = await RedditService.Instance.GetPostCommentsAsync(id); Post = postComments.Post; Comments = postComments.Comments; }
private void ValidateCommentsAllowed(Post post, PostComments comments) { if (comments.AreCommentsClosed(post)) { ModelState.AddModelError("CommentsClosed", "This post is closed for new comments."); } if (post.AllowComments == false) { ModelState.AddModelError("CommentsClosed", "This post does not allow comments."); } }
public async Task <IActionResult> Create(PostComments postComments) { if (!ModelState.IsValid) { return(BadRequest()); } var isCreated = await _postRepository.Create(postComments); return(Ok(new { isCreated })); }
public ActionResult Edit([Bind(Include = "PostCommentID,UserID,PostID,PostCommentContent,PostCommentTime")] PostComments postComments) { if (ModelState.IsValid) { db.Entry(postComments).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PostID = new SelectList(db.Posts, "PostID", "PostTitle", postComments.PostID); ViewBag.UserID = new SelectList(db.Users, "UserID", "UserName", postComments.UserID); return(View(postComments)); }
protected void grdPosts_RowCommand(object sender, GridViewCommandEventArgs e) { divAlbums.Visible = false; int rowIndex = Convert.ToInt32(e.CommandArgument); int index = Convert.ToInt32(grdPosts.DataKeys[rowIndex].Value); if (e.CommandName == "Comment") { grdComments.DataSource = PostComments.FirstOrDefault(p => p.Id == index).Comments.ToList(); grdComments.DataBind(); } }
public async Task <IActionResult> AddLike(int?id) { // Selects post from the database with the given id. var post = await _context.Post.FindAsync(id); // Gets username of the current user. var username = HttpContext.User.Identity.Name; // Selects all of the comments for the post with the given id. var comments = _context.Comment.Where(x => x.PostID == id).ToArray(); // Selects all of the likes for current post that user that is currently logged in left (can only be one). var likes = _context.Likes.Where(x => x.PostId == id && x.UserName == username).ToList(); bool likeExists = likes.Count() != 0; // If there is one then remove it from the database, add to it otherwise. if (likeExists) { _context.RemoveRange(likes); } else { // Creates like entity and adds it to the database. Like like = new Like { PostId = post.PostId, UserName = username }; _context.Add(like); } var _likes = _context.Likes.Where(x => x.PostId == id).ToList(); // Packs updated likes to the view specific model. PostComments pc = new PostComments { Post = post, Comments = comments, Likes = _likes }; await _context.SaveChangesAsync(); // 404 if post isn't valid. if (post == null) { return(NotFound()); } return(RedirectToAction("Details", new { id = post.PostId })); }
public async Task <ActionResult <PostsDTO> > Comment(PostComments comment) { if (!ModelState.IsValid) { return(BadRequest("Model state invalid")); } var post = _context.Comments.Add(comment); var success = await _context.SaveChangesAsync(); return(Ok("Comment Successfully added")); }
public ActionResult Add(PostInput input) { if (!ModelState.IsValid) { return(View("Edit", input)); } // Be able to record the user making the actual post var user = RavenSession.GetCurrentUser(); // Create the post comments object and link between it and the post var comments = new PostComments { Comments = new List <PostComments.Comment>(), Spam = new List <PostComments.Comment>() }; RavenSession.Store(comments); // Create new post object var post = new Post { Tags = TagsResolver.ResolveTagsInput(input.Tags), PublishAt = input.PublishAt, AllowComments = input.AllowComments, AuthorId = user.Id, LastEditedByUserId = user.Id, LastEditedAt = DateTimeOffset.Now, CommentsId = comments.Id, ContentType = input.ContentType, Body = input.Body, CreatedAt = DateTimeOffset.Now, Title = input.Title, }; if (post.PublishAt == DateTimeOffset.MinValue) { var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now); post.PublishAt = postScheduleringStrategy.Schedule(); } // Actually save the post now RavenSession.Store(post); comments.Post = new PostComments.PostReference { Id = post.Id, PublishAt = post.PublishAt, }; return(RedirectToAction("Details", new { id = post.Id.ToIntId() })); }
public PostComment AddComment(int authorId, int postId, string comment) { var author = GetUserById(authorId); var post = GetPostById(postId); var post_comment = new PostComment(); post_comment.AuthorObj = author; post_comment.Post = post; post_comment.Comment = comment; post_comment.Published = Post.GetPublished(); PostComments.Add(post_comment); SaveChanges(); return(post_comment); }
// GET: PostComManagement/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostComments postComments = db.PostComments.Find(id); if (postComments == null) { return(HttpNotFound()); } return(View(postComments)); }
public void WhenQueryingWillGoToTheRightServer_Loading() { using (var session = store.OpenSession()) { var p1 = new Post(); session.Store(p1); var pc1 = new PostComments { PostId = p1.Id }; session.Store(pc1); session.SaveChanges(); } foreach (var ravenDbServer in servers) { ravenDbServer.Value.Server.ResetNumberOfRequests(); } using (var session = store.OpenSession()) { Assert.NotNull(session.Load<Post>("tri/posts/1")); Assert.NotNull(session.Load<PostComments>("tri/PostComments/1")); } Assert.Equal(0, servers["one"].Server.NumberOfRequests); Assert.Equal(0, servers["two"].Server.NumberOfRequests); Assert.Equal(2, servers["tri"].Server.NumberOfRequests); }
public void WhenQueryingWillGoToTheRightServer() { using (var session = store.OpenSession()) { var p1 = new Post(); session.Store(p1); var pc1 = new PostComments {PostId = p1.Id}; session.Store(pc1); session.SaveChanges(); } foreach (var ravenDbServer in servers) { ravenDbServer.Value.Server.ResetNumberOfRequests(); } using (var session = store.OpenSession()) { var posts = session.Query<PostComments>().Where(x => x.PostId == "tri/posts/1").ToList(); Assert.NotEmpty(posts); } Assert.Equal(0, servers["one"].Server.NumberOfRequests); Assert.Equal(0, servers["two"].Server.NumberOfRequests); Assert.Equal(1, servers["tri"].Server.NumberOfRequests); }
public async Task WhenQueryingWillGoToTheRightServer_UsingQueryById() { store.Conventions.AllowQueriesOnId = true; using (var session = store.OpenAsyncSession()) { var p1 = new Post(); await session.StoreAsync(p1); await session.SaveChangesAsync(); var pc1 = new PostComments { PostId = p1.Id }; await session.StoreAsync(pc1); await session.SaveChangesAsync(); } foreach (var ravenDbServer in servers) { ravenDbServer.Value.Server.ResetNumberOfRequests(); } using (var session = store.OpenAsyncSession()) { var posts = await session.Query<Post>() .Where(x => x.Id == "tri/posts/1") .ToListAsync(); Assert.NotEmpty(posts); } Assert.Equal(0, servers["one"].Server.NumberOfRequests); Assert.Equal(0, servers["two"].Server.NumberOfRequests); Assert.Equal(1, servers["tri"].Server.NumberOfRequests); }