public async Task AddPost(PostViewModel model) { var newPost = new Posts { ThreadId = model.ThreadId, Message = model.Message, AuthorName = model.AuthorName, ForumId = model.ForumId, ParentId = model.ParentId, PostedOn = DateTime.Now, UserId = model.UserId, Children = 0 }; // Find the parent post and increment the child count if (model.ParentId != null) { var parentPost = forumDbContext.Posts .Where(p => p.PostId == model.ParentId).FirstOrDefault(); parentPost.Children++; } await forumDbContext.AddAsync(newPost); await forumDbContext.SaveChangesAsync(); }