using Abp.Auditing; using Abp.Runtime.Caching; using Abp.UI; using Abp.Web.Mvc.Controllers; using WePlatform.CommonManager.Notifications; using WePlatform.CommonManager.States; using IwbZero; using IwbZero.IdentityFramework; using IwbZero.Runtime.Session; using Microsoft.AspNet.Identity; namespace WePlatform.Controllers { /// /// Derive all Controllers from this class. /// [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; } 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); } /// /// 抛出错误 /// /// /// 是否要本地化 protected virtual void ThrowError(string err, bool isLocalization = true) { CheckErrors(isLocalization ? L(err) : err); } } }