李昊 4 years ago
parent
commit
c21377bcdf

+ 6 - 3
gx_api/GxPress/Api/GxPress.Api/AppControllers/AddressBookGroupController.cs

@@ -5,6 +5,7 @@ using GxPress.Repository.Interface;
 using GxPress.Request.AddressBookGroup;
 using GxPress.Result.AddressBook;
 using GxPress.Result.AddressBookGroup;
+using GxPress.Service.Interface.AddressBookGroup;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Logging;
@@ -21,13 +22,15 @@ namespace GxPress.Api.AppControllers
     {
         private readonly ILogger<AddressBookGroupController> _logger;
         private readonly IAddressBookGroupRepository _addressBookGroupRepository;
+        private readonly IAddressBookGroupService addressBookGroupService;
         private readonly ILoginContext _loginContext;
 
-        public AddressBookGroupController(ILogger<AddressBookGroupController> logger, IAddressBookGroupRepository addressBookGroupRepository, ILoginContext loginContext)
+        public AddressBookGroupController(ILogger<AddressBookGroupController> logger, IAddressBookGroupRepository addressBookGroupRepository, ILoginContext loginContext, IAddressBookGroupService addressBookGroupService)
         {
             _logger = logger;
             _addressBookGroupRepository = addressBookGroupRepository;
             _loginContext = loginContext;
+            this.addressBookGroupService = addressBookGroupService;
         }
 
         /// <summary>
@@ -69,10 +72,10 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("add")]
-        public async Task<Entity.AddressBookGroup> Insert(AddressBookGroupInRequest request)
+        public async Task<bool> Insert(AddressBookGroupInRequest request)
         {
             request.UserId = _loginContext.AccountId;
-            return await _addressBookGroupRepository.InsertAsync(request);
+            return await addressBookGroupService.InsertAsync(request);
         }
         /// <summary>
         /// 获取用户通讯录组

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

@@ -5,6 +5,7 @@ using GxPress.Repository.Interface;
 using GxPress.Request.AddressBookGroup;
 using GxPress.Result.AddressBook;
 using GxPress.Result.AddressBookGroup;
+using GxPress.Service.Interface.AddressBookGroup;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Logging;
@@ -22,12 +23,14 @@ namespace GxPress.Api.AppControllers
         private readonly ILogger<AddressBookGroupController> _logger;
         private readonly IAddressBookGroupRepository _addressBookGroupRepository;
         private readonly ILoginContext _loginContext;
+        private readonly IAddressBookGroupService addressBookGroupService;
 
-        public WebAddressBookGroupController(ILogger<AddressBookGroupController> logger, IAddressBookGroupRepository addressBookGroupRepository, ILoginContext loginContext)
+        public WebAddressBookGroupController(ILogger<AddressBookGroupController> logger, IAddressBookGroupRepository addressBookGroupRepository, ILoginContext loginContext,IAddressBookGroupService addressBookGroupService)
         {
             _logger = logger;
             _addressBookGroupRepository = addressBookGroupRepository;
             _loginContext = loginContext;
+            this.addressBookGroupService=addressBookGroupService;
         }
 
         /// <summary>
@@ -69,10 +72,10 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("add")]
-        public async Task<Entity.AddressBookGroup> Insert(AddressBookGroupInRequest request)
+        public async Task<bool> Insert(AddressBookGroupInRequest request)
         {
             request.UserId = _loginContext.AccountId;
-            return await _addressBookGroupRepository.InsertAsync(request);
+            return await addressBookGroupService.InsertAsync(request);
         }
         /// <summary>
         /// 获取用户通讯录组

+ 5 - 0
gx_api/GxPress/Model/GxPress.Request/AddressBookGroup/AddressBookGroupInRequest.cs

@@ -22,5 +22,10 @@ namespace GxPress.Request.AddressBookGroup
         /// 父级ID
         /// </summary>
         public int ParentId { get; set; }
+        /// <summary>
+        /// 添加的用户ID
+        /// </summary>
+        /// <value></value>
+        public List<int> UserIds { get; set; }
     }
 }

+ 51 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/AddressBookGroup/AddressBookGroupService.cs

@@ -0,0 +1,51 @@
+using System.Threading.Tasks;
+using GxPress.Repository.Interface;
+using GxPress.Request.AddressBookGroup;
+using GxPress.Service.Interface.AddressBookGroup;
+using System.Transactions;
+using GxPress.Request.AddressBookGroupUser;
+
+namespace GxPress.Service.Implement.AddressBookGroup
+{
+    public class AddressBookGroupService : IAddressBookGroupService
+    {
+        private readonly IAddressBookGroupUserRepository addressBookGroupUserRepository;
+        private readonly IAddressBookGroupRepository addressBookGroupRepository;
+        public AddressBookGroupService(IAddressBookGroupUserRepository addressBookGroupUserRepository, IAddressBookGroupRepository addressBookGroupRepository)
+        {
+            this.addressBookGroupUserRepository = addressBookGroupUserRepository;
+            this.addressBookGroupRepository = addressBookGroupRepository;
+        }
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<bool> InsertAsync(AddressBookGroupInRequest request)
+        {
+            try
+            {
+                using (var transactionScope = new TransactionScope())
+                {
+                    /// <summary>
+                    /// 添加自建
+                    /// </summary>
+                    /// <returns></returns>
+                    var addressBookGroup = await addressBookGroupRepository.InsertAsync(request);
+                    //添加
+                    await addressBookGroupUserRepository.InsertAsync(new AddressBookGroupUserInRequest
+                    {
+                        AddressBookGroupId = addressBookGroup.Id,
+                        UserId = request.UserIds
+                    });
+                    transactionScope.Complete();
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
+    }
+}

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

@@ -0,0 +1,15 @@
+using System.Threading.Tasks;
+using GxPress.Request.AddressBookGroup;
+
+namespace GxPress.Service.Interface.AddressBookGroup
+{
+    public interface IAddressBookGroupService : IService
+    {
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<bool> InsertAsync(AddressBookGroupInRequest request);
+    }
+}