public LoginInfo Login(string loginName, string password) { LoginInfo loginInfo = null; password = Encrypt.MD5(password); loginName = loginName.Trim(); using (var dbContext = new AccountDbContext()) { var user = dbContext.Users.Include("Roles").Where(u => u.LoginName == loginName && u.Password == password && u.IsActive).FirstOrDefault(); if (user != null) { var ip = Fetch.UserIp; loginInfo = dbContext.FindAll<LoginInfo>(p => p.LoginName == loginName && p.ClientIP == ip).FirstOrDefault(); if (loginInfo != null) { loginInfo.LastAccessTime = DateTime.Now; } else { loginInfo = new LoginInfo(user.ID, user.LoginName); if (user.Roles != null && user.Roles.Count > 0 && user.Roles.Exists(u => u.Name == "系统管理员")) //判断是否系统管理员 loginInfo.EnumLoginAccountType = (int)EnumLoginAccountType.Administrator; loginInfo.ClientIP = ip; loginInfo.BusinessPermissionList = user.BusinessPermissionList; dbContext.Insert<LoginInfo>(loginInfo); } } } return loginInfo; }
/// <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 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 SaveRole(Role model) { using (var dbContext = new AccountDbContext()) { if (model.ID > 0) { dbContext.Update<Role>(model); } else { dbContext.Insert<Role>(model); } } }
public Guid SaveVerifyCode(string verifyCodeText) { if (string.IsNullOrWhiteSpace(verifyCodeText)) throw new BusinessException("verifyCode", "输入的验证码不能为空!"); using (var dbContext = new AccountDbContext()) { var verifyCode = new VerifyCode() { VerifyText = verifyCodeText, Guid = Guid.NewGuid() }; dbContext.Insert<VerifyCode>(verifyCode); return verifyCode.Guid; } }