GroupService.RemoveUser.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using Datory;
  6. using GxPress.Common.Exceptions;
  7. using GxPress.Entity;
  8. using GxPress.Request.App.GroupUser;
  9. namespace GxPress.Service.Implement.Group
  10. {
  11. public partial class GroupService
  12. {
  13. /// <summary>
  14. /// 移除小组成员
  15. /// </summary>
  16. /// <param name="request"></param>
  17. /// <returns></returns>
  18. public async Task<bool> DeleteAsync(GroupUserDeRequest request)
  19. {
  20. var group = await _groupRepository.GetAsync(request.GroupId);
  21. // if (request.GroupUserIds.Contains(group.UserId))
  22. // throw new BusinessException("创建人不能删除");
  23. await _groupUserRepository.DeleteAsync(Q.Where(nameof(GroupUser.GroupId), request.GroupId)
  24. .WhereIn(nameof(GroupUser.UserId), request.GroupUserIds));
  25. //删除小组会话界面
  26. return await _middleRepository.DeleteAsync(Q.Where(nameof(Entity.Middle.Middle.FolderType), 7)
  27. .Where(nameof(Entity.Middle.Middle.MiddleId), request.GroupId)
  28. .WhereIn(nameof(Entity.Middle.Middle.UserId), request.GroupUserIds));
  29. }
  30. /// <summary>
  31. /// 退出小组
  32. /// </summary>
  33. /// <param name="userId"></param>
  34. /// <param name="groupId"></param>
  35. /// <returns></returns>
  36. public async Task<bool> DeleteAsync(int userId, int groupId)
  37. {
  38. var group = await _groupRepository.GetAsync(groupId);
  39. if (group == null)
  40. throw new BusinessException("小组不存在!");
  41. // if (group.UserId == userId)
  42. // throw new BusinessException("创建人不能退出");
  43. await _groupUserRepository.DeleteAsync(Q.Where(nameof(GroupUser.GroupId), groupId)
  44. .Where(nameof(GroupUser.UserId), userId));
  45. return await _middleRepository.DeleteAsync(Q.Where(nameof(Entity.Middle.Middle.FolderType), 7)
  46. .Where(nameof(Entity.Middle.Middle.MiddleId), groupId)
  47. .Where(nameof(Entity.Middle.Middle.UserId), userId));
  48. }
  49. }
  50. }