IwbZeroAppServiceBase.cs 2.6 KB

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