lihao vor 4 Jahren
Ursprung
Commit
f527d7a70e

+ 2 - 2
gx_api/GxPress/Api/GxPress.Api/AppControllers/NoteController.cs

@@ -38,7 +38,7 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPut("add")]
-        public async Task<bool> InsertNote(NoteInRequest request)
+        public async Task<NoteAddOrModifyResult> InsertNote(NoteInRequest request)
         {
             // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
             // request.Content = StringUtils.RemoveEmoji(request.Content);
@@ -87,7 +87,7 @@ namespace GxPress.Api.AppControllers
         /// <param name="note"></param>
         /// <returns></returns>
         [HttpPut("update")]
-        public async Task<bool> UpdateNote(Entity.Note.Note note)
+        public async Task<NoteAddOrModifyResult> UpdateNote(Entity.Note.Note note)
         {
             // note.HtmlContent = StringUtils.RemoveEmoji(note.HtmlContent);
             // note.Content = StringUtils.RemoveEmoji(note.Content);

+ 2 - 2
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebNoteController.cs

@@ -39,7 +39,7 @@ namespace GxPress.Api.WebControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPut("add")]
-        public async Task<bool> InsertNote(NoteInRequest request)
+        public async Task<NoteAddOrModifyResult> InsertNote(NoteInRequest request)
         {
             // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
             // request.Content = StringUtils.RemoveEmoji(request.Content);
@@ -88,7 +88,7 @@ namespace GxPress.Api.WebControllers
         /// <param name="note"></param>
         /// <returns></returns>
         [HttpPut("update")]
-        public async Task<bool> UpdateNote(Entity.Note.Note note)
+        public async Task<NoteAddOrModifyResult> UpdateNote(Entity.Note.Note note)
         {
             // note.HtmlContent = StringUtils.RemoveEmoji(note.HtmlContent);
             // note.Content = StringUtils.RemoveEmoji(note.Content);

+ 2 - 0
gx_api/GxPress/Model/GxPress.Request/App/Note/NoteInRequest.cs

@@ -63,5 +63,7 @@ namespace GxPress.Request.App.Note
         /// <value></value>
         public bool IsDraft { get; set; }
 
+        public int Id { get; set; }
+
     }
 }

+ 7 - 0
gx_api/GxPress/Model/GxPress.Result/App/Note/NoteResult.cs

@@ -221,4 +221,11 @@ namespace GxPress.Result.App.Note
         /// <value></value>
         public string DepartmentName { get; set; }
     }
+
+    public class NoteAddOrModifyResult
+    {
+        public int Id { get; set; }
+        public int FolderId { get; set; }
+        public string FolderName { get; set; }
+    }
 }

+ 21 - 5
gx_api/GxPress/Service/GxPress.Service.Implement/Note/NoteService.cs

@@ -94,8 +94,9 @@ namespace GxPress.Service.Implement.Note
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public async Task<bool> InsertNoteAsync(NoteInRequest request)
+        public async Task<NoteAddOrModifyResult> InsertNoteAsync(NoteInRequest request)
         {
+            var result = new NoteAddOrModifyResult();
             try
             {
                 using (TransactionScope transactionScope = new TransactionScope())
@@ -123,8 +124,11 @@ namespace GxPress.Service.Implement.Note
                         CatalogId = request.CatalogId,
                         ChapterId = request.ChapterId,
                         //是否草稿
-                        IsDraft = request.IsDraft
+                        IsDraft = request.IsDraft,
+                        Id = request.Id
                     };
+                    if (note.Id > 0)
+                        return await UpdateNoteAsync(note);
                     var noteId = await _noteRepository.InsertAsync(note);
                     if (!request.IsDraft)
                     {
@@ -145,6 +149,10 @@ namespace GxPress.Service.Implement.Note
                     }
                     //添加默认文件夹
                     await recordFolderRepository.AddAsync(request.IsTopic ? AllTypeConst.TopicNote.GetHashCode() : AllTypeConst.Note.GetHashCode(), request.UserId, request.FolderId);
+                    var middle = await _middleRepository.GetMiddleAsync(request.FolderId);
+                    result.Id = noteId;
+                    result.FolderId = request.FolderId;
+                    result.FolderName = middle.FolderName;
                     transactionScope.Complete();
                 }
             }
@@ -153,7 +161,7 @@ namespace GxPress.Service.Implement.Note
                 Console.WriteLine(e);
                 throw;
             }
-            return true;
+            return result;
         }
         /// <summary>
         /// 获取笔记/话题草稿分页
@@ -581,7 +589,7 @@ namespace GxPress.Service.Implement.Note
         /// </summary>
         /// <param name="note"></param>
         /// <returns></returns>
-        public async Task<bool> UpdateNoteAsync(Entity.Note.Note note)
+        public async Task<NoteAddOrModifyResult> UpdateNoteAsync(Entity.Note.Note note)
         {
             var entity = await _noteRepository.GetAsync(note.Id);
             if (string.IsNullOrWhiteSpace(note.Content) && string.IsNullOrWhiteSpace(note.Title))
@@ -634,7 +642,15 @@ namespace GxPress.Service.Implement.Note
             await recordFolderRepository.AddAsync(note.IsTopic ? AllTypeConst.TopicNote.GetHashCode() : AllTypeConst.Note.GetHashCode(), note.UserId, note.FolderId);
             entity.Title = note.Title;
             entity.IsDraft = note.IsDraft;
-            return await _noteRepository.UpdateAsync(entity);
+            await _noteRepository.UpdateAsync(entity);
+            var middleDto = await _middleRepository.GetMiddleAsync(entity.FolderId);
+            var result = new NoteAddOrModifyResult()
+            {
+                Id = entity.Id,
+                FolderId = entity.FolderId,
+                FolderName = middleDto.FolderName
+            };
+            return result;
         }
 
         public async Task<bool> DeleteAsync(int id, int userId)

+ 2 - 5
gx_api/GxPress/Service/GxPress.Service.Interface/Note/INoteService.cs

@@ -1,6 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
 using System.Threading.Tasks;
 using GxPress.Common.Page;
 using GxPress.Request.App.Note;
@@ -12,7 +9,7 @@ namespace GxPress.Service.Interface.Note
 {
     public interface INoteService : IService
     {
-        Task<bool> InsertNoteAsync(NoteInRequest request);
+        Task<NoteAddOrModifyResult> InsertNoteAsync(NoteInRequest request);
 
         Task<PagedList<NotePageListRequest>> NotePageListAsync(NoteSearchPageListRequest request);
 
@@ -28,7 +25,7 @@ namespace GxPress.Service.Interface.Note
         /// </summary>
         /// <param name="note"></param>
         /// <returns></returns>
-        Task<bool> UpdateNoteAsync(Entity.Note.Note note);
+        Task<NoteAddOrModifyResult> UpdateNoteAsync(Entity.Note.Note note);
         /// <summary>
         /// 删除笔记
         /// </summary>