public JsonResult Login(SecUser model, string ValidateCode)
        {
            MyJsonResult mjr = new MyJsonResult();

            try
            {
                var obj = Session["ValidateCode"];
                if (obj == null || obj.ToString() != ValidateCode)
                {
                    mjr.Success = false;
                    mjr.Message = "验证码不正确!";
                    mjr.Data = 1;
                    if (obj == null)
                    {
                        mjr.Data = 11;
                    }
                    return Json(mjr);
                }

                UserService userService = new UserService();

                var user = userService.GetUserByLoginName(model.LoginName);

                if (user == null)
                {
                    mjr.Success = false;
                    mjr.Message = "用户名不正确!";
                    mjr.Data = 2;
                }
                else
                {
                    if (user.Password != model.Password)
                    {
                        mjr.Success = false;
                        mjr.Message = "密码不正确!";
                        mjr.Data = 3;
                    }
                    else
                    {
                        SecurityContext.Current = new SecurityContext()
                        {
                            User = user,
                            PermissionManager = new PermissionManager(user.UserId)
                        };

                        //Session[SSessionIndex.IsAuthorizedForCKEditor] = true;
                        mjr.Success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                mjr.Success = false;
                mjr.Message = ex.Message;
            }

            return Json(mjr);
        }
        public JsonResult Save(SecUser model)
        {
            MyJsonResult mjr = new MyJsonResult();

            using (var dba = DbAccessor.Create())
            {
                try
                {
                    dba.BeginTran();

                    model.ModifiedById = SecurityContext.Current.User.UserId;
                    model.ModifiedDate = DateTime.Now;

                    if (model.UserId == null)
                    {

                        #region 校验数据
                        dynamic count = _dba.ExecuteScalar<dynamic>("SecuritySettings.User.CountByLoginName",
                                           new { LoginName = model.LoginName, Status = (int)StatusType.Enabled });

                        if (count > 0)
                        {
                            mjr.Success = false;
                            mjr.Message = "登录名已存在!";
                            goto End;
                        } 
                        #endregion

                        model.UserId = Guid.NewGuid().ToString();
                        model.Status = (int)StatusType.Enabled;
                        model.CreatedById = SecurityContext.Current.User.UserId;
                        model.CreatedDate = DateTime.Now;
                        dba.Insert<SecUser>(model);
                    }
                    else
                    {
                        dba.UpdateFields(model, "LoginName", "Password", "Name", "Sex", "Birthday",
                            "MobilePhone", "OrganizationId",
                            "ModifiedById", "ModifiedDate");
                    }

                    dba.CommitTran();
                    mjr.Success = true;
                    mjr.Message = "保存成功!";
                }
                catch (Exception ex)
                {
                    dba.RollbackTran();
                    mjr.Success = false;
                    mjr.Message = ex.Message;
                }
            }

            End:

            return Json(mjr);
        }
        /// <summary>
        /// Returns the includeExternal user LinkedData
        /// </summary>
        /// <returns>includeExternal LinkedData</returns>
        public JsonResult GetLinkedDataPredicates( string id)
        {
            var allPredicates = this._LinkedDataService.GetLinkedDataPredicates(id);

            var result = new MyJsonResult()
            {
                data = from predicate in allPredicates
                       select new
                       {
                           predicatename = predicate,
                           included = false
                       },
                isSuccess = true
            };
            return Json(result);
        }
        public JsonResult Save(SecMenu model)
        {
            MyJsonResult mjr = new MyJsonResult();

            using (var dba = DbAccessor.Create())
            {
                try
                {
                    dba.BeginTran();

                    model.ModifiedById = SecurityContext.Current.User.UserId;
                    model.ModifiedDate = DateTime.Now;

                    if (model.MenuId == null)
                    {
                        model.MenuId = Guid.NewGuid().ToString();
                        model.Status = (int)StatusType.Enabled;
                        model.CreatedById = SecurityContext.Current.User.UserId;
                        model.CreatedDate = DateTime.Now;
                        dba.ExecuteNonQuery("Security.Menu.Insert", model);
                    }
                    else
                    {
                        dba.UpdateFields(model, "Name", "Url", "IsExpand",
                            "MobilePhone",
                            "ModifiedById", "ModifiedDate");
                    }

                    dba.CommitTran();
                    mjr.Success = true;
                    mjr.Message = "保存成功!";
                }
                catch (Exception ex)
                {
                    dba.RollbackTran();
                    mjr.Success = false;
                    mjr.Message = ex.Message;
                }
            }

            return Json(mjr);
        }
        public JsonResult GetExternalDatabaseStatus()
        {
            //if (string.IsNullOrEmpty(username))
            //throw new ArgumentException("No user name specified in request");

            var allDatabases = this._settingsService.GetAllExternalDatabases();
            var userDatabases = this._settingsService.GetExternalDatabasesForUser();

            var result = new MyJsonResult()
            {
                data = from database in allDatabases
                       select new
                       {
                           databasename = database,
                           included = userDatabases.Contains(database)
                       },
                isSuccess = true
            };
            return Json(result);
        }
        public JsonResult Delete(string id)
        {
            MyJsonResult mjr = new MyJsonResult();
            using (DbAccessor dba = DbAccessor.Create())
            {
                try
                {
                    dba.BeginTran();

                    _menuService.DeleteRecursive(id, dba);

                    dba.CommitTran();

                    mjr.Success = true;
                }
                catch (Exception ex)
                {
                    dba.RollbackTran();

                    mjr.Success = false;
                    mjr.Message = ex.Message;
                }
            }

            return Json(mjr);
        }
        public JsonResult Delete(string id)
        {
            MyJsonResult mjr = new MyJsonResult();


            try
            {
                var user = new SecUser();
                user.UserId = id;
                user.Status =(int)StatusType.Deleted;
                _dba.UpdateFields(user, "Status");

                mjr.Success = true;
            }
            catch (Exception ex)
            {

                mjr.Success = false;
                mjr.Message = ex.Message;
            }
      
            return Json(mjr);
        }
        public JsonResult Delete(string id)
        {
            MyJsonResult mjr = new MyJsonResult();

            try
            {
                _organizationService.DeleteRecursive(id);

                mjr.Success = true;
            }
            catch (Exception ex)
            {

                mjr.Success = false;
                mjr.Message = ex.Message;
            }

            return Json(mjr);
        }
        /// <summary>
        /// Gets a list of roles including the information wether the user is in that role or not.
        /// </summary>
        /// <param name="username">The user which role information should be gathered.</param>
        /// <returns>A list of roles including the information wether the user is in that role or not.</returns>
        public JsonResult GetUserRoleStatus(string username)
        {
            if (string.IsNullOrEmpty(username))
            throw new ArgumentException("No user name specified in request");

              var allRoles = this._accountService.GetAllRoles();
              var userRoles = this._accountService.GetRolesForUser(username);

              var result = new MyJsonResult()
              {
            data = from role in allRoles
               select new
               {
                 rolename = role,
                 isInRole = userRoles.Contains(role)
               },
            isSuccess = true
              };

              return Json(result);
        }