protected override void OnException(ExceptionContext filterContext)
 {
     filterContext.ExceptionHandled = true;
     string error;
     if (filterContext.Exception is KnownException)
     {
         error = filterContext.Exception.Message;
     }
     else
     {
         if (Request.QueryString["debug"] == SettingContext.Instance.DebugKey)
         {
             error = filterContext.Exception.GetAllMessages();
         }
         else
         {
             error = "服务器未知错误,请重试。如果该问题一直存在,请联系管理员。感谢您的支持。";
         }
     }
     if (Request.QueryString["ajax"] == "true")
     {
         var result = new StandardJsonResult();
         result.Fail(error);
         filterContext.Result = result;
     }
     else
     {
         var model = new LayoutViewModel();
         model.Error = error;
         filterContext.Result = this.View(this.GetErrorViewPath(), model);
     }
 }
 public StandardJsonResult Update(string key, string value)
 {
     var result = new StandardJsonResult();
     result.Try(() =>
     {
         var service = Ioc.GetService<Services.Admin.ISettingService>();
         service.Update(key, value);
     });
     return result;
 }
 public StandardJsonResult Login(string username, string password)
 {
     var result = new StandardJsonResult();
     result.Try(() =>
     {
         var service = Ioc.GetService<IUserService>();
         if (!service.CanLogin(username, password))
         {
             throw new Exception("invalid username/password.");
         }
     });
     return result;
 }
 public StandardJsonResult Register(User user)
 {
     var result = new StandardJsonResult();
     result.Try(() => Ioc.GetService<Services.Public.IUserService>().Register(user));
     return result;
 }
 public StandardJsonResult Register(User model)
 {
     var result = new StandardJsonResult();
     result.Try(() => Ioc.GetService<IUserService>().Register(model));
     return result;
 }