public LoginInfo GetLoginInfo(Guid Token)
 {
     return CacheHelper.Get<LoginInfo>(string.Format(_LoginInfoKeyFormat, Token), () =>
     {
         using (AccountDBContext db = new AccountDBContext())
         {
             //超时处理
             var timeOutList = db.FindAll<LoginInfo>(p => DbFunctions.DiffMinutes(DateTime.Now, p.LastAccessTime) > _UserLoginTimeoutMinutes);
             if (timeOutList.Count() > 0)
             {
                 foreach (var item in timeOutList)
                 {
                     db.LoginInfos.Remove(item);
                 }
                 db.SaveChanges();
             }
             var loginInfo = db.FindAll<LoginInfo>(s => s.LoginToken == Token).FirstOrDefault();
             if (loginInfo != null)
             {
                 loginInfo.LastAccessTime = DateTime.Now;
                 db.Update<LoginInfo>(loginInfo);
             }
             return loginInfo;
         }
     });
 }
 public void SaveRole(Role role)
 {
     using (var dbContext = new AccountDBContext())
     {
         if (role.id > 0)
         {
             dbContext.Update<Role>(role);
         }
         else
         {
             dbContext.Insert<Role>(role);
         }
     }
 }
        public void SaveUser(User user)
        {
            using (var dbContext = new AccountDBContext())
            {
                if (user.id > 0)
                {
                    dbContext.Update<User>(user);

                    var roles = dbContext.Roles.Where(r => user.RoleIds.Contains(r.id)).ToList();
                    user.Roles = roles;
                    dbContext.SaveChanges();
                }
                else
                {
                    var existUser = dbContext.FindAll<User>(u => u.LoginName == user.LoginName);
                    if (existUser.Count > 0)
                    {
                        throw new BusinessException("LoginName", "此登录名已存在!");
                    }
                    else
                    {
                        dbContext.Insert<User>(user);

                        var roles = dbContext.Roles.Where(r => user.RoleIds.Contains(r.id)).ToList();
                        user.Roles = roles;
                        dbContext.SaveChanges();
                    }
                }
            }
        }
 public void ModifyPwd(Contract.Model.User user)
 {
     using (var dbContext = new AccountDBContext())
     {
         if (dbContext.Users.Any(t => t.id == user.id && t.Password == user.Password))
         {
             if (!string.IsNullOrEmpty(user.NewPassword))
             {
                 user.Password = Encrypt.Encode(user.NewPassword);
                 dbContext.Update(user);
             }
         }
         else
         {
             throw new BusinessException("输入的原始密码不正确");
         }
     }
 }