AuthorizeExtensions.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using LeaRun.Util.Extension;
  4. using System.Linq;
  5. using System.Linq.Expressions;
  6. namespace LeaRun.Application.Code
  7. {
  8. /// <summary>
  9. /// 版 本
  10. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  11. /// 创建人:刘晓雷
  12. /// 日 期:2016.03.29 22:35
  13. /// 描 述:授权认证
  14. /// </summary>
  15. public static class AuthorizeExtensions
  16. {
  17. #region 带权限的数据源查询
  18. /// <summary>
  19. /// 获取授权数据
  20. /// </summary>
  21. /// <typeparam name="T"></typeparam>
  22. /// <param name="data"></param>
  23. /// <returns></returns>
  24. public static IEnumerable<T> ToAuthorizeData<T>(this IEnumerable<T> data)
  25. {
  26. if (data != null)
  27. {
  28. if (OperatorProvider.Provider.Current().IsSystem)
  29. return data;
  30. string dataAutor = OperatorProvider.Provider.Current().DataAuthorize.ReadAutorizeUserId;
  31. var parameter = Expression.Parameter(typeof(T), "t");
  32. var authorConditon = Expression.Constant(dataAutor).Call("Contains", parameter.Property("CreateUserId"));
  33. var lambda = authorConditon.ToLambda<Func<T, bool>>(parameter);
  34. return data.Where(lambda.Compile());
  35. }
  36. else
  37. {
  38. return null;
  39. }
  40. }
  41. #endregion
  42. }
  43. }