public async Task AddNewCommentAsync(Comment cmt) { if (cmt.UserCommentId != 0) { CategoryComment comment; int cmnt = 0; var user = _users.Find(cmt.UserCommentId); var comments = new Comment { Body = cmt.Body, TypeId = 1, IsPublished = cmt.UserCommentId == 1 ? true : false, CreatedDateTime = DateTime.Now, Name = user.FirstName, Tell = user.PhoneNumber, Email = user.Email, UserCommentId = (int)cmt.UserCommentId, ParentId = cmt.ParentId ?? null }; await _comments.AddAsync(comments); if (cmt.ParentId != null) { cmnt = _commentCategory.Where(x => x.CommentId == cmt.ParentId).First().CategoryId; } comment = new CategoryComment { CategoryId = cmt.ParentId == null ? cmt.TypeId : cmnt, CommentId = comments.Id }; await _commentCategory.AddAsync(comment); await _uow.SaveChangesAsync(); } }
public async Task <IActionResult> PostCategoryComment([FromBody] CategoryComment comment) { var userIdStr = User.Claims?.FirstOrDefault(x => x.Type == "OryxUser")?.Value; var userId = Guid.Parse(userIdStr); comment.UserAccountId = userId; var apiMsg = await ApiMessage.Wrap(async() => { await contentBusiness.CreateCategoryCommentExtPostEntry(comment); }); return(Json(apiMsg)); }
public async Task CreateCategoryCommentExtPostEntry(CategoryComment comment) { var categoryModel = await ContentAccessor.OneAsync <Categories>(x => x.Status != ContentStatus.Close && x.Id == comment.CategoryId); //设置话题为漫画名 var topic = new PostEntryTopic() { CreateTime = DateTime.Now, Id = Guid.NewGuid(), Text = categoryModel.Name, PosterId = comment.UserAccountId }; var topicExt = new ContentExtPostEntryTopic() { Id = Guid.NewGuid(), TopicText = categoryModel.Name, LinkId = categoryModel.Id, LinkType = "category" }; //评论 var postentryModel = new PostEntry() { Id = Guid.NewGuid(), CreateTime = DateTime.Now, PostEntryTopic = categoryModel.Name, UserId = comment.UserAccountId, TimeStamp = TimeStamp.Get(), TextContent = comment.Content, }; //目前是一条漫画评论对应一个话题, 为防止以后出现多话题, 保留此表 var categoryPostentryMapping = new CategoryPostEntryMapping() { Id = Guid.NewGuid(), CategoryId = categoryModel.Id, PostEntryId = postentryModel.Id, CreateTime = DateTime.Now }; await ContentAccessor.Add(topic); await ContentAccessor.Add(topicExt); await ContentAccessor.Add(postentryModel); await ContentAccessor.Add(categoryPostentryMapping); var sandBoxMsg = new SandBoxMessage() { Content = $"您在漫画{topic}的回复,收到了新的评论.", CreateTime = DateTime.Now, FromUserAccountId = comment.UserAccountId, ToUserAccountId = postentryModel.UserId, Id = Guid.NewGuid(), IsRead = false, MessageType = SandBoxMessageType.PostEntryComment, TimeStamp = TimeStamp.Get(), RecieveToken = "" }; await sandBoxBusiness.SendAlertTo(sandBoxMsg); }
public async Task CreateCategoryComment(CategoryComment comment) { await ContentAccessor.Add(comment); await ContentAccessor.SaveAsync(); }