public static async Task <HttpStatusCode> AddCommentAsync <T>( ApplicationDbContext dbContext, string userId, CommentItemIds ids, Expression <Func <T, CommentThread> > commentThreadProperty, T commentTargetEntity, CommentRequest comment) { using (var transaction = dbContext.Database.BeginTransaction()) { bool succeeded = false; try { var text = await TextOperations.CreateTextAsync( dbContext, comment.Message); dbContext.UserTexts.Add(text); var commentThreadPropInfo = (PropertyInfo)((MemberExpression)commentThreadProperty.Body).Member; CommentThread commentThread = commentThreadPropInfo.GetValue(commentTargetEntity) as CommentThread; if (commentThread == null) { commentThread = new CommentThread { Comments = new List <Comment>() }; dbContext.CommentThreads.Add(commentThread); commentThreadPropInfo.SetValue(commentTargetEntity, commentThread); } var commentEntity = new Comment { Text = text, Thread = commentThread, UserId = userId }; dbContext.Comments.Add(commentEntity); commentThread.Comments.Add(commentEntity); await dbContext.SaveChangesAsync(); transaction.Commit(); succeeded = true; await UserOperations.NotifyMentionsAsync( dbContext, "Comment", userId, text); await SearchOperations.IndexCommentAsync(commentEntity, ids); return(HttpStatusCode.OK); } finally { if (!succeeded) { transaction.Rollback(); } } } }
public static Task IndexCommentAsync( Comment comment, CommentItemIds ids) { return(IndexItemAsync( new MessageIndexEntry { ItemId = "comment-" + comment.CommentId, Content = comment.Text.Content, TimelineEntryId = ids.TimelineEntryId, MediaAlbumId = ids.AlbumId, UserMediaId = ids.MediaId, CommentThreadId = comment.CommentThreadId })); }
public static Task IndexCommentAsync( Comment comment, CommentItemIds ids) { return IndexItemAsync( new MessageIndexEntry { ItemId = "comment-" + comment.CommentId, Content = comment.Text.Content, TimelineEntryId = ids.TimelineEntryId, MediaAlbumId = ids.AlbumId, UserMediaId = ids.MediaId, CommentThreadId = comment.CommentThreadId }); }