public LoginInfo GetLoginInfo(Guid token) { return CacheHelper.Get<LoginInfo>(string.Format(_LoginInfoKeyFormat, token), () => { using (var dbContext = new AccountDbContext()) { //如果有超时的,启动超时处理 var timeoutList = dbContext.FindAll<LoginInfo>(p => DbFunctions.DiffMinutes(DateTime.Now, p.LastAccessTime) > _UserLoginTimeoutMinutes); if (timeoutList.Count > 0) { foreach (var li in timeoutList) dbContext.LoginInfos.Remove(li); } dbContext.SaveChanges(); var loginInfo = dbContext.FindAll<LoginInfo>(l => l.LoginToken == token).FirstOrDefault(); if (loginInfo != null) { loginInfo.LastAccessTime = DateTime.Now; dbContext.Update<LoginInfo>(loginInfo); } return loginInfo; } }); }
public void ModifyPwd(User user) { user.Password = Encrypt.MD5(user.Password); using (var dbContext = new AccountDbContext()) { if (dbContext.Users.Any(l => l.ID == user.ID && user.Password == l.Password)) { if (!string.IsNullOrEmpty(user.NewPassword)) user.Password = Encrypt.MD5(user.NewPassword); dbContext.Update<User>(user); } else { throw new BusinessException("Password", "原密码不正确!"); } } }
/// <summary> /// 编辑保存 /// </summary> public void SaveMenu(Menu model) { string cachingKey = "ConfigFile_AdminMenuConfig"; using (var dbContext = new AccountDbContext()) { model.ParentId = model.ParentId ?? 0; if (model.ID > 0) { dbContext.Update<Menu>(model); } else { dbContext.Insert<Menu>(model); } Caching.Remove(cachingKey); //删除菜单缓存 } }
public void SaveRole(Role model) { using (var dbContext = new AccountDbContext()) { if (model.ID > 0) { dbContext.Update<Role>(model); } else { dbContext.Insert<Role>(model); } } }
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(); } } } }