12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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<Entity.AddressBookGroup> InsertAsync(AddressBookGroupInRequest request)
- {
- try
- {
- using (var transactionScope = new TransactionScope())
- {
- /// <summary>
- /// 添加自建
- /// </summary>
- /// <returns></returns>
- var addressBookGroup = await addressBookGroupRepository.InsertAsync(request);
- if (request.UserIds != null)
- {
- //添加
- await addressBookGroupUserRepository.InsertAsync(new AddressBookGroupUserInRequest
- {
- AddressBookGroupId = addressBookGroup.Id,
- UserId = request.UserIds
- });
- }
- transactionScope.Complete();
- return addressBookGroup;
- }
- }
- catch
- {
- return new Entity.AddressBookGroup();
- }
- }
- }
- }
|