private async Task InsertInLatestComments(ObjectId commentId, AddCommentCommand command) { var post = await _db.Posts.Find(p => p.InternalId == ObjectId.Parse(command.PostId)).FirstOrDefaultAsync(); if (post == null) { return; } var preview = new CommentPreview() { Created = DateTime.UtcNow, PostId = command.PostId, PostTitle = post.Title, UserPhotoUrl = command.UserPhotoUrl, PostUrl = post.Url, Text = command.Text, UserId = command.UserId, UserName = command.UserName, CommentId = commentId.ToString() }; var comments = await _db.LatestComments.Find(_ => true).ToListAsync(); comments.Add(preview); var sortedComments = comments.OrderByDescending(c => c.Created).Take(15); _db.LatestComments.DeleteMany(_ => true); await _db.LatestComments.InsertManyAsync(sortedComments); }
protected override void OnInit(EventArgs e) { base.OnInit(e); doComment = this.DataObject as DataObjectComment; Control ctrl = this.LoadControl("/UserControls/Templates/SmallOutputUser2.ascx"); SmallOutputUser2 userOutput = ctrl as SmallOutputUser2; SetUserOutput(userOutput, doComment.UserID.Value, doComment.Nickname); phUserOutput.Controls.Add(userOutput); if (doComment.CommentStatus == 0) { CommentPreview commentPreview = (CommentPreview)LoadControl("/UserControls/Dashboard/CommentPreview.ascx"); commentPreview.Comment = doComment; commentPreview.StripHtml = false; commentPreview.Type = "Comment"; phCommentOuput.Controls.Add(commentPreview); LbtnDel.Visible = false; if (UserDataContext.GetUserDataContext().IsAdmin&& doComment.CommentStatus != 1) { LbtnDel.Visible = true; LbtnDel.ID = "del_" + doComment.ObjectID.ToString().Replace("-", ""); LbtnDel.CommandArgument = doComment.ObjectID.ToString(); } } else { phCommentOuput.Controls.Add(new LiteralControl(languageShared.GetString("MessageCommentDeletedByAdmin"))); LbtnDel.Visible = false; } }