lihao 4 years ago
parent
commit
ae4dae872a

+ 8 - 7
gx_api/GxPress/Api/GxPress.Api/AppControllers/AddressBookGroupUserController.cs

@@ -7,6 +7,7 @@ using GxPress.Repository.Interface;
 using GxPress.Repository.Interface.Friends;
 using GxPress.Request.AddressBookGroupUser;
 using GxPress.Result.AddressBookGroupUser;
+using GxPress.Service.Interface.AddressBookGroup;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Logging;
@@ -25,12 +26,16 @@ namespace GxPress.Api.AppControllers
         private readonly IAddressBookGroupUserRepository _addressBookGroupUserRepository;
         private readonly ILoginContext _loginContext;
         private readonly IFriendsRepository friendsRepository;
-        public AddressBookGroupUserController(ILogger<AppVersionController> logger, IAddressBookGroupUserRepository addressBookGroupUserRepository, ILoginContext loginContext, IFriendsRepository friendsRepository)
+         private readonly IAddressBookGroupService addressBookGroupService;
+        public AddressBookGroupUserController(ILogger<AppVersionController> logger, 
+        IAddressBookGroupUserRepository addressBookGroupUserRepository, 
+        ILoginContext loginContext, IFriendsRepository friendsRepository,IAddressBookGroupService addressBookGroupService)
         {
             _logger = logger;
             _addressBookGroupUserRepository = addressBookGroupUserRepository;
             _loginContext = loginContext;
             this.friendsRepository = friendsRepository;
+            this.addressBookGroupService=addressBookGroupService;
         }
 
         /// <summary>
@@ -50,12 +55,8 @@ namespace GxPress.Api.AppControllers
         [HttpPost("delete")]
         public async Task<bool> Deletes(AddressBookGroupUserDeleteRequest request)
         {
-            var model = await _addressBookGroupUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.AddressBookGroupUser.Id), request.Ids));
-            if (await _addressBookGroupUserRepository.DeletesAsync(request.Ids))
-            {
-                return await friendsRepository.DeleteAsync(model.Select(n => n.UserId), _loginContext.AccountId);
-            }
-            return false;
+             request.UserId = _loginContext.AccountId;
+            return await addressBookGroupService.DeleteAddressBookGroupUserAsync(request);
         }
         /// <summary>
         /// 获取

+ 3 - 1
gx_api/GxPress/Api/GxPress.Api/WebControllers/AddressBookGroupController.cs

@@ -25,7 +25,9 @@ namespace GxPress.Api.AppControllers
         private readonly ILoginContext _loginContext;
         private readonly IAddressBookGroupService addressBookGroupService;
 
-        public WebAddressBookGroupController(ILogger<AddressBookGroupController> logger, IAddressBookGroupRepository addressBookGroupRepository, ILoginContext loginContext,IAddressBookGroupService addressBookGroupService)
+        public WebAddressBookGroupController(ILogger<AddressBookGroupController> logger, 
+        IAddressBookGroupRepository addressBookGroupRepository, 
+        ILoginContext loginContext,IAddressBookGroupService addressBookGroupService)
         {
             _logger = logger;
             _addressBookGroupRepository = addressBookGroupRepository;

+ 7 - 7
gx_api/GxPress/Api/GxPress.Api/WebControllers/AddressBookGroupUserController.cs

@@ -7,6 +7,7 @@ using GxPress.Repository.Interface;
 using GxPress.Repository.Interface.Friends;
 using GxPress.Request.AddressBookGroupUser;
 using GxPress.Result.AddressBookGroupUser;
+using GxPress.Service.Interface.AddressBookGroup;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Logging;
@@ -25,12 +26,15 @@ namespace GxPress.Api.AppControllers
         private readonly IAddressBookGroupUserRepository _addressBookGroupUserRepository;
         private readonly ILoginContext _loginContext;
         private readonly IFriendsRepository friendsRepository;
-        public WebAddressBookGroupUserController(ILogger<AppVersionController> logger, IAddressBookGroupUserRepository addressBookGroupUserRepository, ILoginContext loginContext, IFriendsRepository friendsRepository)
+        private readonly IAddressBookGroupService addressBookGroupService;
+        public WebAddressBookGroupUserController(ILogger<AppVersionController> logger,
+        IAddressBookGroupUserRepository addressBookGroupUserRepository, ILoginContext loginContext, IFriendsRepository friendsRepository, IAddressBookGroupService addressBookGroupService)
         {
             _logger = logger;
             _addressBookGroupUserRepository = addressBookGroupUserRepository;
             _loginContext = loginContext;
             this.friendsRepository = friendsRepository;
+            this.addressBookGroupService = addressBookGroupService;
         }
 
         /// <summary>
@@ -50,12 +54,8 @@ namespace GxPress.Api.AppControllers
         [HttpPost("delete")]
         public async Task<bool> Deletes(AddressBookGroupUserDeleteRequest request)
         {
-            if (await _addressBookGroupUserRepository.DeletesAsync(request.Ids))
-            {
-                var model = await _addressBookGroupUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.AddressBookGroupUser.Id), request.Ids));
-                return await friendsRepository.DeleteAsync(model.Select(n => n.UserId), _loginContext.AccountId);
-            }
-            return false;
+            request.UserId = _loginContext.AccountId;
+            return await addressBookGroupService.DeleteAddressBookGroupUserAsync(request);
         }
         /// <summary>
         /// 获取

+ 6 - 1
gx_api/GxPress/Model/GxPress.Request/AddressBookGroupUser/AddressBookGroupUserDeleteRequest.cs

@@ -11,6 +11,11 @@ namespace GxPress.Request.AddressBookGroupUser
         /// 自增ID
         /// </summary>
         /// <value></value>
-        public List<int> Ids{get;set;}
+        public List<int> Ids { get; set; }
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        /// <value></value>
+        public int UserId { get; set; }
     }
 }

+ 31 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/AddressBookGroup/AddressBookGroupService.cs

@@ -4,6 +4,9 @@ using GxPress.Request.AddressBookGroup;
 using GxPress.Service.Interface.AddressBookGroup;
 using System.Transactions;
 using GxPress.Request.AddressBookGroupUser;
+using Datory;
+using System.Linq;
+using GxPress.Repository.Interface.Friends;
 
 namespace GxPress.Service.Implement.AddressBookGroup
 {
@@ -11,10 +14,12 @@ namespace GxPress.Service.Implement.AddressBookGroup
     {
         private readonly IAddressBookGroupUserRepository addressBookGroupUserRepository;
         private readonly IAddressBookGroupRepository addressBookGroupRepository;
-        public AddressBookGroupService(IAddressBookGroupUserRepository addressBookGroupUserRepository, IAddressBookGroupRepository addressBookGroupRepository)
+        private readonly IFriendsRepository friendsRepository;
+        public AddressBookGroupService(IAddressBookGroupUserRepository addressBookGroupUserRepository, IAddressBookGroupRepository addressBookGroupRepository, IFriendsRepository friendsRepository)
         {
             this.addressBookGroupUserRepository = addressBookGroupUserRepository;
             this.addressBookGroupRepository = addressBookGroupRepository;
+            this.friendsRepository = friendsRepository;
         }
         /// <summary>
         /// 添加
@@ -51,5 +56,30 @@ namespace GxPress.Service.Implement.AddressBookGroup
             }
 
         }
+        /// <summary>
+        /// 删除自建小组用户
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<bool> DeleteAddressBookGroupUserAsync(AddressBookGroupUserDeleteRequest request)
+        {
+            try
+            {
+                var model = await addressBookGroupUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.AddressBookGroupUser.Id), request.Ids));
+                if (model == null || model.Count() == 0)
+                    return false;
+                using (var transactionScope = new TransactionScope())
+                {
+                    await addressBookGroupUserRepository.DeletesAsync(request.Ids);
+                    await friendsRepository.DeleteAsync(model.Select(n => n.UserId), request.UserId);
+                    transactionScope.Complete();
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
     }
 }

+ 7 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/AddressBookGroup/IAddressBookGroupService.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using GxPress.Request.AddressBookGroup;
+using GxPress.Request.AddressBookGroupUser;
 
 namespace GxPress.Service.Interface.AddressBookGroup
 {
@@ -11,5 +12,11 @@ namespace GxPress.Service.Interface.AddressBookGroup
         /// <param name="request"></param>
         /// <returns></returns>
         Task<Entity.AddressBookGroup> InsertAsync(AddressBookGroupInRequest request);
+        /// <summary>
+        /// 删除自建小组用户
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<bool> DeleteAddressBookGroupUserAsync(AddressBookGroupUserDeleteRequest request);
     }
 }