IwbControllerBase.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Abp.Auditing;
  2. using Abp.Runtime.Caching;
  3. using Abp.UI;
  4. using Abp.Web.Mvc.Controllers;
  5. using WePlatform.CommonManager.Notifications;
  6. using WePlatform.CommonManager.States;
  7. using IwbZero;
  8. using IwbZero.IdentityFramework;
  9. using IwbZero.Runtime.Session;
  10. using Microsoft.AspNet.Identity;
  11. namespace WePlatform.Controllers
  12. {
  13. /// <summary>
  14. /// Derive all Controllers from this class.
  15. /// </summary>
  16. [DisableAuditing]
  17. public abstract class IwbControllerBase : AbpController
  18. {
  19. public INotificationManager NoticeManager { get; set; }
  20. public IStatesManager StatesManager { get; set; }
  21. public ICacheManager CacheManager { get; set; }
  22. public new IIwbSession AbpSession { get; set; }
  23. protected IwbControllerBase(ICacheManager cacheManager = null)
  24. {
  25. LocalizationSourceName = IwbZeroConsts.LocalizationSourceName;
  26. NoticeManager = NullNotificationManager.Instance;
  27. StatesManager = NullStatesManager.Instance;
  28. AbpSession = NullIwbSession.Instance;
  29. CacheManager = cacheManager;
  30. }
  31. protected virtual void CheckModelState()
  32. {
  33. if (!ModelState.IsValid)
  34. {
  35. throw new UserFriendlyException(L("FormIsNotValidMessage"));
  36. }
  37. }
  38. protected virtual void CheckErrors(string error)
  39. {
  40. throw new UserFriendlyException(error);
  41. }
  42. protected virtual void CheckErrors(IdentityResult identityResult)
  43. {
  44. identityResult.CheckErrors(LocalizationManager);
  45. }
  46. /// <summary>
  47. /// 抛出错误
  48. /// </summary>
  49. /// <param name="err"></param>
  50. /// <param name="isLocalization">是否要本地化</param>
  51. protected virtual void ThrowError(string err, bool isLocalization = true)
  52. {
  53. CheckErrors(isLocalization ? L(err) : err);
  54. }
  55. }
  56. }