AddressBookGroupService.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Threading.Tasks;
  2. using GxPress.Repository.Interface;
  3. using GxPress.Request.AddressBookGroup;
  4. using GxPress.Service.Interface.AddressBookGroup;
  5. using System.Transactions;
  6. using GxPress.Request.AddressBookGroupUser;
  7. namespace GxPress.Service.Implement.AddressBookGroup
  8. {
  9. public class AddressBookGroupService : IAddressBookGroupService
  10. {
  11. private readonly IAddressBookGroupUserRepository addressBookGroupUserRepository;
  12. private readonly IAddressBookGroupRepository addressBookGroupRepository;
  13. public AddressBookGroupService(IAddressBookGroupUserRepository addressBookGroupUserRepository, IAddressBookGroupRepository addressBookGroupRepository)
  14. {
  15. this.addressBookGroupUserRepository = addressBookGroupUserRepository;
  16. this.addressBookGroupRepository = addressBookGroupRepository;
  17. }
  18. /// <summary>
  19. /// 添加
  20. /// </summary>
  21. /// <param name="request"></param>
  22. /// <returns></returns>
  23. public async Task<Entity.AddressBookGroup> InsertAsync(AddressBookGroupInRequest request)
  24. {
  25. try
  26. {
  27. using (var transactionScope = new TransactionScope())
  28. {
  29. /// <summary>
  30. /// 添加自建
  31. /// </summary>
  32. /// <returns></returns>
  33. var addressBookGroup = await addressBookGroupRepository.InsertAsync(request);
  34. if (request.UserIds != null)
  35. {
  36. //添加
  37. await addressBookGroupUserRepository.InsertAsync(new AddressBookGroupUserInRequest
  38. {
  39. AddressBookGroupId = addressBookGroup.Id,
  40. UserId = request.UserIds
  41. });
  42. }
  43. transactionScope.Complete();
  44. return addressBookGroup;
  45. }
  46. }
  47. catch
  48. {
  49. return new Entity.AddressBookGroup();
  50. }
  51. }
  52. }
  53. }