李昊 4 years ago
parent
commit
d04ab7c4dc

+ 1 - 0
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminArticleGroupController.cs

@@ -36,6 +36,7 @@ namespace GxPress.Api.AdminControllers
         {
             return await _processGroupRepository.AddAsync(request);
         }
+        
         /// <summary>
         /// 获取详情
         /// </summary>

+ 14 - 3
gx_api/GxPress/Api/GxPress.Api/AppControllers/ArticleGroupUserController.cs

@@ -19,7 +19,7 @@ namespace GxPress.Api.AppControllers
     {
         private readonly IArticleGroupUserRepository _articleGroupUserRepository;
         private readonly ILoginContext _loginContext;
-        public ArticleGroupUserController(IArticleGroupUserRepository articleGroupUserRepository,ILoginContext loginContext)
+        public ArticleGroupUserController(IArticleGroupUserRepository articleGroupUserRepository, ILoginContext loginContext)
         {
             _articleGroupUserRepository = articleGroupUserRepository;
             _loginContext = loginContext;
@@ -41,10 +41,21 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("add")]
-        public async Task<bool> Add([FromBody]ArticleGroupUserInRequest request)
+        public async Task<bool> Add([FromBody] ArticleGroupUserInRequest request)
         {
             request.UserId = _loginContext.AccountId;
-            return await _articleGroupUserRepository.InsertAsync(request)>0;
+            return await _articleGroupUserRepository.InsertAsync(request) > 0;
+        }
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<bool> InsertAsync(ArticleGroupUserInNewRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _articleGroupUserRepository.InsertAsync(request);
         }
         /// <summary>
         /// 获取用户的频道

+ 15 - 0
gx_api/GxPress/Model/GxPress.Request/ArticleGroupUser/ArticleGroupUserInRequest.cs

@@ -19,4 +19,19 @@ namespace GxPress.Request.ArticleGroupUser
         /// </summary>
         public int ArticleGroupId { get; set; }
     }
+    /// <summary>
+    /// 新版添加
+    /// </summary>
+    public class ArticleGroupUserInNewRequest
+    {
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        public int UserId { get; set; }
+
+        /// <summary>
+        /// 文章组ID
+        /// </summary>
+        public List<int> ArticleGroupId { get; set; }
+    }
 }

+ 35 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/ArticleGroupUserRepository.cs

@@ -1,6 +1,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
+using System.Transactions;
 using AutoMapper;
 using GxPress.Common.AppOptions;
 using GxPress.Common.Exceptions;
@@ -59,7 +60,39 @@ namespace GxPress.Repository.Implement
             };
             return await _repository.InsertAsync(articleGroupUserEntity);
         }
-
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<bool> InsertAsync(ArticleGroupUserInNewRequest request)
+        {
+            var user = await _userRepository.GetAsync(request.UserId);
+            if (user == null)
+                throw new BusinessException("用户不存在");
+            try
+            {
+                using (var transactionScope = new TransactionScope())
+                {
+                    //删除
+                    await _repository.DeleteAsync(Q.Where(nameof(ArticleGroupUser.UserId), request.UserId));
+                    foreach (var item in request.ArticleGroupId)
+                    {
+                        var articleGroupUserEntity = new ArticleGroupUser
+                        {
+                            ArticleGroupId = item,
+                            UserId = request.UserId
+                        };
+                        await _repository.InsertAsync(articleGroupUserEntity);
+                    }
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
         /// <summary>
         /// 删除用户频道
         /// </summary>
@@ -86,7 +119,7 @@ namespace GxPress.Repository.Implement
             {
                 listArray.Add(new ArticleGroupUserListResult() { Id = 0, UserId = request.UserId, ArticleGroupId = item.Id, ArticleGroupName = item.Name, StyleCss = item.StyleCss, IsSystemDefault = item.IsSystemDefault });
             }
-            var list = await _repository.GetAllAsync(Q.Where(nameof(ArticleGroupUser.UserId), request.UserId));
+            var list = await _repository.GetAllAsync(Q.Where(nameof(ArticleGroupUser.UserId), request.UserId).OrderBy(nameof(ArticleGroup.CreatedDate)));
             listArray.AddRange(list.Select(n => _mapper.Map<ArticleGroupUserListResult>(n)).ToList());
             foreach (var item in listArray)
             {

+ 7 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/IArticleGroupUserRepository.cs

@@ -9,12 +9,18 @@ using Datory;
 
 namespace GxPress.Repository.Interface
 {
-   public interface IArticleGroupUserRepository:IRepository
+    public interface IArticleGroupUserRepository : IRepository
     {
         Task<int> InsertAsync(ArticleGroupUserInRequest request);
 
         Task<bool> DeleteAsync(int id);
 
         Task<IEnumerable<ArticleGroupUserListResult>> GetListAsync(ArticleGroupUserSearchRequest request);
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<bool> InsertAsync(ArticleGroupUserInNewRequest request);
     }
 }