IwbControllerBase.cs 2.3 KB

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