public override string[] GetRolesForUser(string login) { string[] role = new string[] { }; using (SalesContext _db = new SalesContext()) { try { // Get User User user = (from u in _db.Users where u.Login == login select u).FirstOrDefault(); if (user != null) { // Get role Role userRole = _db.Roles.Find(user.RoleId); if (userRole != null) { role = new string[] { userRole.Name }; } } } catch { role = new string[] { }; } } return role; }
private bool ValidateUser(string login, string password) { bool isValid = false; using (SalesContext _db = new SalesContext()) { try { User user = (from u in _db.Users where u.Login == login && u.Password==password select u).FirstOrDefault(); if (user != null) { isValid = true; } } catch { isValid = false; } } return isValid; }
public override bool IsUserInRole(string username, string roleName) { bool outputResult = false; // Find user using (SalesContext _db = new SalesContext()) { try { // get user User user = (from u in _db.Users where u.Login == username select u).FirstOrDefault(); if (user != null) { // get role Role userRole = _db.Roles.Find(user.RoleId); //compare if (userRole != null && userRole.Name == roleName) { outputResult = true; } } } catch { outputResult = false; } } return outputResult; }