// GET ALL COMMENTS BY BULLETINID -- not the best way to do this public IEnumerable <CommentListItem> GetCommentsByBulletinId(int id) { using (var ctx = new ApplicationDbContext()) { var query = ctx .Comments .ToList(); List <CommentListItem> commentListItems = new List <CommentListItem>(); foreach (Comment item in query) { if (item.BulletinId == id) { CommentListItem comment = new CommentListItem { CommentId = item.CommentId, BulletinId = item.BulletinId, UserName = item.UserName, CommentText = item.CommentText, CreatedUtc = item.CreatedUtc, ModifiedUtc = item.ModifiedUtc }; commentListItems.Add(comment); } } return(commentListItems); } }
public async Task SendNewCommentNotificationAsync(CommentListItem model, Func <string, string> funcCommentContentFormat) { if (!IsEnabled) { _logger.LogWarning($"Skipped {nameof(SendNewCommentNotificationAsync)} because Email sending is disabled."); await Task.CompletedTask; return; } try { var req = new NewCommentNotificationPayload( model.Username, model.Email, model.IpAddress, model.PostTitle, funcCommentContentFormat(model.CommentContent), model.CreateOnUtc ); await SendNotificationRequest( new NotificationRequest <NewCommentNotificationPayload>(MailMesageTypes.NewCommentNotification, req)); } catch (Exception e) { _logger.LogError(e, e.Message); } }
public IEnumerator refreshCommentList() { ServerCall getCommentsCall = new ServerCall(ServerInteract.INSTANCE.GetCommentsOnGlyph(currentGlyph)); yield return(StartCoroutine(getCommentsCall.call())); if (getCommentsCall.ReturnException != null) { throw getCommentsCall.ReturnException; } else { GlyphComment.GlyphCommentList glyphComments = (GlyphComment.GlyphCommentList)getCommentsCall.ObjectResponse; foreach (GlyphComment comment in glyphComments.comments) { GameObject go = Instantiate(commentListItemPrefab); CommentListItem listItem = go.GetComponent <CommentListItem> (); listItem.SetComment(comment, currentGlyph); commentList.addElement((ScrollableList.ListGameObject)listItem); } } yield return("Done"); }
public CommentListItem GetComment(int id) { using (var ctx = new ApplicationDbContext()) { var comment = ctx.Comments.Single(e => e.CommentID == id); var userProfile = ctx.Profiles.Single(e => e.ID == _userId); var commentItem = new CommentListItem(); bool likedByUser = CommentLikedByUser(comment); var timePosted = GetCommentPostTime(comment); commentItem = new CommentListItem { CommentID = comment.CommentID, ActivityFeedID = comment.FeedID, SenderFullName = comment.SenderFullName, CommentContent = comment.CommentContent, SenderUsername = comment.SenderUsername, Created = comment.Created, AmountOfLikes = comment.AmountOfLikes, AmountOfReplies = comment.AmountOfReplies, Replies = comment.Replies, Likes = comment.Likes, LikedByUser = likedByUser, WhenPosted = timePosted, }; return(commentItem); } }
public Task <Response <CommentListItem> > CreateAsync(NewCommentRequest request) { return(TryExecuteAsync <CommentListItem>(async() => { // 1. Check comment enabled or not if (!_blogConfig.ContentSettings.EnableComments) { return new FailedResponse <CommentListItem>((int)ResponseFailureCode.CommentDisabled); } // 2. Harmonize banned keywords if (_blogConfig.ContentSettings.EnableWordFilter) { var dw = _blogConfig.ContentSettings.DisharmonyWords; var maskWordFilter = new MaskWordFilter(new StringWordSource(dw)); request.Username = maskWordFilter.FilterContent(request.Username); request.Content = maskWordFilter.FilterContent(request.Content); } var model = new CommentEntity { Id = Guid.NewGuid(), Username = request.Username, CommentContent = request.Content, PostId = request.PostId, CreateOnUtc = DateTime.UtcNow, Email = request.Email, IPAddress = request.IpAddress, IsApproved = !_blogConfig.ContentSettings.RequireCommentReview, UserAgent = request.UserAgent }; await _commentRepository.AddAsync(model); var spec = new PostSpec(request.PostId, false); var postTitle = _postRepository.SelectFirstOrDefault(spec, p => p.Title); var item = new CommentListItem { Id = model.Id, CommentContent = model.CommentContent, CreateOnUtc = model.CreateOnUtc, Email = model.Email, IpAddress = model.IPAddress, IsApproved = model.IsApproved, PostTitle = postTitle, Username = model.Username }; return new SuccessResponse <CommentListItem>(item); })); }
private IEnumerable <CommentListItem> CreateListOfComments(IEnumerable <Comment> comments) { List <CommentListItem> commentListItems = new List <CommentListItem>(); foreach (Comment comment in comments) { CommentListItem i = new CommentListItem { CommentId = comment.CommentId, Text = comment.Text, RecipeId = comment.RecipeId, }; commentListItems.Add(i); } return(commentListItems); }
public async Task SendNewCommentNotificationAsync(CommentListItem comment, Func <string, string> funcCommentContentFormat) { if (IsEnabled) { _logger.LogInformation("Sending NewCommentNotification mail"); var pipeline = new TemplatePipeline().Map(nameof(comment.Username), comment.Username) .Map(nameof(comment.Email), comment.Email) .Map(nameof(comment.IpAddress), comment.IpAddress) .Map(nameof(comment.CreateOnUtc), comment.CreateOnUtc.ToString("MM/dd/yyyy HH:mm")) .Map(nameof(comment.PostTitle), comment.PostTitle) .Map(nameof(comment.CommentContent), funcCommentContentFormat(comment.CommentContent)); await EmailHelper.ApplyTemplate(MailMesageTypes.NewCommentNotification.ToString(), pipeline) .SendMailAsync(_blogConfig.EmailSettings.AdminEmail); } }
private CommentListItem GetCommentById(int commentId) { CommentListItem result = new CommentListItem(); using (var ctx = new ApplicationDbContext()) { var entity = ctx .Comments .Single(e => e.Id == commentId); result.AuthorId = _userId; result.Id = entity.Id; result.CommentText = entity.CommentText; } return(result); }
// ADDED METHOD public List <CommentListItem> ConvertDataEntitiesToViewModel(List <Comment> comments) { // instantiate a new List<CommentListItem>** List <CommentListItem> returnList = new List <CommentListItem>(); // foreach through my entity.AllComments foreach (var comment in comments) { //create a new CommentListItem var commentListItem = new CommentListItem(); // assign it the values from the entity.AllComments[i], commentListItem.CommentId = comment.CommentId; commentListItem.CommentText = comment.CommentText; commentListItem.CreatedUtc = comment.CreatedUtc; // add CommentListItem to my List<CommentListItem>** returnList.Add(commentListItem); } // return that List<CommentListItem>** return(returnList); }
// Get --Retrieve comments and in theory should also return list of replies public IEnumerable <CommentListItem> GetComments() { using (var ctx = new ApplicationDbContext()) { var query = ctx .Comments.ToList() .Select( e => { var listItem = new CommentListItem { Id = e.Id, ExchangeId = e.ExchangeId, Text = e.Text, CommenterName = e.Commenter != null ? e.Commenter.FullName : "Unknown", NumberOfReplies = e.Replies.Count() }; return(listItem); }); return(query.ToArray()); } }
public Task <Response <CommentListItem> > AddCommentAsync(NewCommentRequest request) { return(TryExecuteAsync <CommentListItem>(async() => { // 1. Check comment enabled or not if (!_blogConfig.ContentSettings.EnableComments) { return new FailedResponse <CommentListItem>((int)ResponseFailureCode.CommentDisabled); } // 2. Check user email domain var bannedDomains = _blogConfig.EmailSettings.BannedMailDomain?.Split(","); if (null != bannedDomains && bannedDomains.Any()) { var address = new MailAddress(request.Email); if (bannedDomains.Contains(address.Host)) { Logger.LogWarning($"Email host '{address.Host}' is found in ban list, rejecting comments."); return new FailedResponse <CommentListItem>((int)ResponseFailureCode.EmailDomainBlocked); } } // 3. Harmonize banned keywords if (_blogConfig.ContentSettings.EnableWordFilter) { var dw = _blogConfig.ContentSettings.DisharmonyWords; var maskWordFilter = new MaskWordFilter(new StringWordSource(dw)); request.Username = maskWordFilter.FilterContent(request.Username); request.Content = maskWordFilter.FilterContent(request.Content); } var model = new CommentEntity { Id = Guid.NewGuid(), Username = request.Username, CommentContent = request.Content, PostId = request.PostId, CreateOnUtc = DateTime.UtcNow, Email = request.Email, IPAddress = request.IpAddress, IsApproved = !_blogConfig.ContentSettings.RequireCommentReview, UserAgent = request.UserAgent }; await _commentRepository.AddAsync(model); var spec = new PostSpec(request.PostId, false); var postTitle = _postRepository.SelectFirstOrDefault(spec, p => p.Title); var item = new CommentListItem { Id = model.Id, CommentContent = model.CommentContent, CreateOnUtc = model.CreateOnUtc, Email = model.Email, IpAddress = model.IPAddress, IsApproved = model.IsApproved, PostTitle = postTitle, Username = model.Username }; return new SuccessResponse <CommentListItem>(item); })); }