CustomerUserPrivilegeLogic.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using CZFW.Framework.Interface;
  2. using CZFW.Framework.Model.Entity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using CZFW.Framework.Model.ViewModel;
  7. using System.Linq;
  8. namespace CZFW.Framework.Logic
  9. {
  10. public class CustomerUserPrivilegeLogic : LogicBase<CustomerUserPrivilegeEntity>, ICustomerUserPrivilege
  11. {
  12. public ResultModel AddCustomerUserPrivileges(IList<CustomerUserPrivilegeEntity> customerUserPrivileges)
  13. {
  14. var res = AddEntities(customerUserPrivileges);
  15. return res;
  16. }
  17. public IList<CustomerUserPrivilegeModel> GetCustomerUserPrivileges(int userId)
  18. {
  19. var res = Queryable.Where(x => x.UserId == userId).Select(x => new CustomerUserPrivilegeModel
  20. {
  21. DataId = x.DataId,
  22. DataLevel = x.DataLevel,
  23. UserId = x.UserId,
  24. EntId = x.EntId,
  25. Id = x.Id,
  26. OriginalId = x.OriginalId,
  27. SortOrder = x.SortOrder ?? 0
  28. }).ToList();
  29. return res;
  30. }
  31. public ResultModel RevokeCustomerUserPrivilegesByIds(IList<int> customerUserPriviligeIds)
  32. {
  33. var res = RemoveEntities(x => customerUserPriviligeIds.Contains(x.Id));
  34. return res;
  35. }
  36. public ResultModel RevokeCustomerUserPrivileges( int userId, int entId, IList<CustomerUserPrivilegeEntity> customerUserPrivileges)
  37. {
  38. var ids = new List<int>();
  39. var tp1 = Queryable.Where(x => x.UserId == userId && x.EntId == entId).ToList();
  40. customerUserPrivileges.ForEach(x=> {
  41. var id = tp1.Where(y => y.DataId == x.DataId && y.DataLevel == x.DataLevel).SingleOrDefault()?.Id;
  42. ids.Add(id??0);
  43. });
  44. var res = RevokeCustomerUserPrivilegesByIds(ids);
  45. return res;
  46. }
  47. public (bool result, string message) Validate(CustomerUserPrivilegeEntity entity)
  48. {
  49. var any = Queryable.Any(x => x.UserId == entity.UserId && x.DataId == entity.DataId && x.DataLevel == entity.DataLevel);
  50. return (!any, any ? "已经存在" : null);
  51. }
  52. }
  53. }