IwbZeroAppServiceBase.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Linq.Dynamic.Core;
  4. using Abp.Application.Services;
  5. using Abp.Runtime.Caching;
  6. using Abp.UI;
  7. using IwbZero.Helper;
  8. using IwbZero.Session;
  9. namespace IwbZero.AppServiceBase
  10. {
  11. public abstract class IwbZeroAppServiceBase : ApplicationService
  12. {
  13. public ICacheManager CacheManager { get; set; }
  14. public new IIwbSession AbpSession{ get; set; }
  15. protected IwbZeroAppServiceBase()
  16. {
  17. LocalizationSourceName = IwbZeroConsts.IwbZeroLocalizationSourceName;
  18. }
  19. protected virtual IQueryable<T> ApplyFilter<T>(IQueryable<T> query, IIwbPagedRequest input)
  20. {
  21. if (!string.IsNullOrEmpty(input.KeyWords))
  22. {
  23. object keyWords = input.KeyWords;
  24. LambdaObject obj = new LambdaObject()
  25. {
  26. FieldType = (LambdaFieldType)input.FieldType,
  27. FieldName = input.KeyField,
  28. FieldValue = keyWords,
  29. ExpType = (LambdaExpType)input.ExpType
  30. };
  31. var exp = obj.GetExp<T>();
  32. query = query.Where(exp);
  33. }
  34. if (input.SearchList != null && input.SearchList.Count > 0)
  35. {
  36. List<LambdaObject> objList = new List<LambdaObject>();
  37. foreach (var o in input.SearchList)
  38. {
  39. if (string.IsNullOrEmpty(o.KeyWords))
  40. continue;
  41. object keyWords = o.KeyWords;
  42. objList.Add(new LambdaObject
  43. {
  44. FieldType = (LambdaFieldType)o.FieldType,
  45. FieldName = o.KeyField,
  46. FieldValue = keyWords,
  47. ExpType = (LambdaExpType)o.ExpType
  48. });
  49. }
  50. var exp = objList.GetExp<T>();
  51. query = query.Where(exp);
  52. }
  53. return query;
  54. }
  55. //protected virtual void CheckErrors(IdentityResult identityResult)
  56. //{
  57. // identityResult.CheckErrors(LocalizationManager);
  58. //}
  59. protected virtual void CheckErrors(string error)
  60. {
  61. throw new UserFriendlyException(error);
  62. }
  63. /// <summary>
  64. /// 抛出错误
  65. /// </summary>
  66. /// <param name="err"></param>
  67. /// <param name="isLocalization">是否要本地化</param>
  68. protected virtual void ThrowError(string err, bool isLocalization = true)
  69. {
  70. CheckErrors(isLocalization ? L(err) : err);
  71. }
  72. }
  73. }