BusinessFieldHelper.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Dynamic.Core;
  5. using System.Text;
  6. using System.Collections;
  7. using System.Collections.Specialized;
  8. using System.Reflection;
  9. using System.Security.Claims;
  10. using FMSAdmin.Data;
  11. namespace FMSAdmin.Helpers {
  12. public static class BusinessFieldHelper {
  13. public static IQueryable<T> Apply<T>(FMSContext context, ClaimsPrincipal user, bool businessAuth, IQueryable query, string prefix = "") {
  14. if (!businessAuth) return (IQueryable<T>)query;
  15. var usr = context.CmUser.FirstOrDefault(x => x.UserId == user.Identity.Name);
  16. if (usr == null) return (IQueryable<T>)query;
  17. string fieldName = "BusinessFieldId";
  18. if (!string.IsNullOrEmpty(prefix)) {
  19. fieldName = prefix + "." + fieldName;
  20. }
  21. var businessCommon = context.CmBusinessField.FirstOrDefault(x => x.Name == "공통");
  22. var businessCommonQuery = "";
  23. if (businessCommon != null) {
  24. businessCommonQuery = " OR " + fieldName + " == " + businessCommon.BusinessFieldId;
  25. }
  26. return (IQueryable<T>)query.Where("(" + fieldName + " == @0 " + businessCommonQuery + ")", usr.BusinessFieldId);
  27. }
  28. }
  29. }