12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System.Threading.Tasks;
- using GxPress.Repository.Interface;
- 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
- {
- public class AddressBookGroupService : IAddressBookGroupService
- {
- private readonly IAddressBookGroupUserRepository addressBookGroupUserRepository;
- private readonly IAddressBookGroupRepository addressBookGroupRepository;
- private readonly IFriendsRepository friendsRepository;
- public AddressBookGroupService(IAddressBookGroupUserRepository addressBookGroupUserRepository, IAddressBookGroupRepository addressBookGroupRepository, IFriendsRepository friendsRepository)
- {
- this.addressBookGroupUserRepository = addressBookGroupUserRepository;
- this.addressBookGroupRepository = addressBookGroupRepository;
- this.friendsRepository = friendsRepository;
- }
- /// <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();
- }
- }
- /// <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;
- }
- }
- }
|