lihao 4 years ago
parent
commit
7fa8b964af

+ 1 - 1
gx_api/GxPress/Api/GxPress.Api/AppControllers/TopicController.cs

@@ -122,7 +122,7 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPut("add-group")]
-        public async Task<bool> InsertTopicGroup(TopicGroupInRequest request)
+        public async Task<AppResultJson<TopicGroup>> InsertTopicGroup(TopicGroupInRequest request)
         {
             var topicGroup = new TopicGroup { Name = request.Name, UserId = _loginContext.AccountId };
             return await _topicGroupRepository.InsertAsync(topicGroup);

+ 1 - 1
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebTopicController.cs

@@ -147,7 +147,7 @@ namespace GxPress.Api.WebControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPut("add-group")]
-        public async Task<bool> InsertTopicGroup(TopicGroupInRequest request)
+        public async Task<AppResultJson<TopicGroup>> InsertTopicGroup(TopicGroupInRequest request)
         {
             var topicGroup = new TopicGroup { Name = request.Name, UserId = _loginContext.AccountId };
             return await _topicGroupRepository.InsertAsync(topicGroup);

+ 10 - 0
gx_api/GxPress/Model/GxPress.EnumConst/AllTypeConst.cs

@@ -132,4 +132,14 @@ namespace GxPress.EnumConst
         [Description("其他")]
         Other = 4
     }
+    /// <summary>
+    /// 状态码
+    /// </summary>
+    public enum StatusCodeConst
+    {
+        [Description("成功")]
+        SucceedCode = 200,
+        [Description("失败")]
+        ErrorCode = 100,
+    }
 }

+ 25 - 5
gx_api/GxPress/Repository/GxPress.Repository.Implement/Topic/TopicGroupRepository.cs

@@ -6,11 +6,13 @@ using Datory;
 using GxPress.Common.AppOptions;
 using GxPress.Common.Tools;
 using GxPress.Entity.Topic;
+using GxPress.EnumConst;
 using GxPress.Repository.Interface.Topic;
 using GxPress.Request.App.Topic;
+using GxPress.Result;
 using Microsoft.Extensions.Options;
 using SqlKata;
-
+using System.Transactions;
 namespace GxPress.Repository.Implement.Topic
 {
     public class TopicGroupRepository : ITopicGroupRepository
@@ -51,11 +53,29 @@ namespace GxPress.Repository.Implement.Topic
         /// </summary>
         /// <param name="topicGroup"></param>
         /// <returns></returns>
-        public async Task<bool> InsertAsync(TopicGroup topicGroup)
+        public async Task<AppResultJson<Entity.Topic.TopicGroup>> InsertAsync(TopicGroup topicGroup)
         {
-            var id = await _repository.InsertAsync(topicGroup) > 0;
-            return await _repository.UpdateAsync(Q.Set(nameof(TopicGroup.Sort), id).Where(nameof(TopicGroup.Id), id)) >
-                   0;
+            var result = new AppResultJson<Entity.Topic.TopicGroup>()
+            {
+                Code = StatusCodeConst.SucceedCode.GetHashCode(),
+                Success = true
+            };
+            try
+            {
+                using (var transactionScope = new TransactionScope())
+                {
+                    var id = await _repository.InsertAsync(topicGroup);
+                    await _repository.UpdateAsync(Q.Set(nameof(TopicGroup.Sort), id).Where(nameof(TopicGroup.Id), id));
+                    transactionScope.Complete();
+                    result.Data = await _repository.GetAsync(id);
+                }
+            }
+            catch
+            {
+                result.Success = false;
+                result.Code = StatusCodeConst.ErrorCode.GetHashCode();
+            }
+            return result;
         }
 
         /// <summary>

+ 6 - 5
gx_api/GxPress/Repository/GxPress.Repository.Interface/Topic/ITopicGroupRepository.cs

@@ -5,17 +5,18 @@ using System.Threading.Tasks;
 using Datory;
 using GxPress.Entity.Topic;
 using GxPress.Request.App.Topic;
+using GxPress.Result;
 
 namespace GxPress.Repository.Interface.Topic
 {
-   public interface ITopicGroupRepository:IRepository
+    public interface ITopicGroupRepository : IRepository
     {
 
         Task<TopicGroup> GetAsync(int id);
 
         Task<bool> DeleteAsync(List<int> ids);
 
-        Task<bool> InsertAsync(TopicGroup topicGroup);
+        Task<AppResultJson<Entity.Topic.TopicGroup>> InsertAsync(TopicGroup topicGroup);
 
         Task<IEnumerable<TopicGroup>> GetTopicGroupsAsync(int userId);
 
@@ -24,7 +25,7 @@ namespace GxPress.Repository.Interface.Topic
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-         Task<bool> UpdateAsync(TopicGroupInRequest request);
+        Task<bool> UpdateAsync(TopicGroupInRequest request);
 
         /// <summary>
         /// 排序
@@ -33,10 +34,10 @@ namespace GxPress.Repository.Interface.Topic
         /// <param name="secondId"></param>
         /// <param name="userId"></param>
         /// <returns></returns>
-        Task<bool> MoveSortAsync(int firstId, int secondId,int userId);
+        Task<bool> MoveSortAsync(int firstId, int secondId, int userId);
 
         Task<bool> UpdateAsync(SqlKata.Query query);
 
-        
+
     }
 }