/// <summary> /// 回复 /// </summary> public async Task AdminReplyAsync(long dialogueId, string content, long adminUserId) { using (var dapper = DapperFactory.CreateWithTrans()) { //取得对话记录 var dialogue = await dapper.QueryOneAsync <UserDialogue>(new { Id = dialogueId, IsDeleted = false }); if (dialogue == null) { throw new KuException("无法取得对话信息!"); } //新增对话消息 var model = new UserDialogueMessage { Id = ID.NewID(), DialogueId = dialogue.Id, UserId = adminUserId, CreateTime = DateTime.Now, IsDeleted = false, Message = content, IsAdmin = true, }; await dapper.InsertAsync <UserDialogueMessage>(model); dapper.Commit(); } }
/// <summary> /// 保存数据 /// </summary> public async Task AddAsync(long userId, string message) { using (var dapper = DapperFactory.CreateWithTrans()) { //取得对话记录 var dialogue = await dapper.QueryOneAsync <UserDialogue>(new { UserId = userId, IsDeleted = false }); if (dialogue != null && dialogue.IsForbidden) { //已禁言 throw new KuException("您暂时无法留言!"); } if (dialogue == null) { //新增对话 dialogue = new UserDialogue { Id = ID.NewID(), UserId = userId, CreateTime = DateTime.Now, IsDeleted = false, LastMessageSummary = message.Substr(0, 120, "..."), LastMessageTime = DateTime.Now, IsForbidden = false, IsSolved = false }; await dapper.InsertAsync <UserDialogue>(dialogue); } else { //更新对话信息 var item = new { LastMessageSummary = message.Substring(0, 128), LastMessageTime = DateTime.Now, IsSolved = false, SolveTime = null as DateTime?, SolveUserId = null as long? }; await dapper.UpdateAsync <UserDialogue>(item, new { dialogue.Id }); } //新增对话消息 var model = new UserDialogueMessage { Id = ID.NewID(), DialogueId = dialogue.Id, UserId = userId, CreateTime = DateTime.Now, IsDeleted = false, Message = message, IsAdmin = false, }; await dapper.InsertAsync <UserDialogueMessage>(model); dapper.Commit(); } }