| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using Abp.Auditing;
- using Abp.Runtime.Caching;
- using Abp.UI;
- using Abp.Web.Mvc.Controllers;
- using WeOnlineApp.CommonManager.Notifications;
- using WeOnlineApp.CommonManager.States;
- using IwbZero;
- using IwbZero.Authorization.Base.Users;
- using IwbZero.IdentityFramework;
- using IwbZero.Runtime.Session;
- using Microsoft.AspNet.Identity;
- using WeOnlineApp.Configuration;
- namespace WeOnlineApp.Controllers
- {
- /// <summary>
- /// Derive all Controllers from this class.
- /// </summary>
- [DisableAuditing]
- public abstract class IwbControllerBase : AbpController
- {
- public INotificationManager NoticeManager { get; set; }
- public IStatesManager StatesManager { get; set; }
- public ICacheManager CacheManager { get; set; }
- public new IIwbSession AbpSession { get; set; }
- protected IwbControllerBase(ICacheManager cacheManager = null)
- {
- LocalizationSourceName = IwbZeroConsts.LocalizationSourceName;
- NoticeManager = NullNotificationManager.Instance;
- StatesManager = NullStatesManager.Instance;
- AbpSession = NullIwbSession.Instance;
- CacheManager = cacheManager;
- }
- public void CheckAccount()
- {
- if (AbpSession.AccountType != AccountTypeDefinition.Student && AbpSession.UserName != UserBase.AdminUserName)
- {
- CheckErrors("您不是学员账号,请联系管理员!");
- }
- }
- protected virtual void CheckModelState()
- {
- if (!ModelState.IsValid)
- {
- throw new UserFriendlyException(L("FormIsNotValidMessage"));
- }
- }
- protected virtual void CheckErrors(string error)
- {
- throw new UserFriendlyException(error);
- }
- protected virtual void CheckErrors(IdentityResult identityResult)
- {
- identityResult.CheckErrors(LocalizationManager);
- }
- /// <summary>
- /// 抛出错误
- /// </summary>
- /// <param name="err"></param>
- /// <param name="isLocalization">是否要本地化</param>
- protected virtual void ThrowError(string err, bool isLocalization = true)
- {
- CheckErrors(isLocalization ? L(err) : err);
- }
- }
- }
|