public override string[] GetRolesForUser(string login) { string[] role = new string[] { }; using (HelpdeskContext _db = new HelpdeskContext()) { try { // Получаем пользователя User user = (from u in _db.Users where u.Login == login select u).FirstOrDefault(); if (user != null) { // получаем роль 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 (HelpdeskContext _db = new HelpdeskContext()) { 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; // Находим пользователя using (HelpdeskContext _db = new HelpdeskContext()) { try { // Получаем пользователя User user = (from u in _db.Users where u.Login == username select u).FirstOrDefault(); if (user != null) { // получаем роль Role userRole = _db.Roles.Find(user.RoleId); //сравниваем if (userRole != null && userRole.Name == roleName) { outputResult = true; } } } catch { outputResult = false; } } return outputResult; }