public override string[] GetRolesForUser(string login) { string[] role = new string[] { }; using (TPMDocContext db = new TPMDocContext()) { try { // Получаем пользователя аботники user = (from u in db.аботники 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); }
public override bool IsUserInRole(string username, string roleName) { bool outputResult = false; // Находим пользователя using (TPMDocContext _db = new TPMDocContext()) { try { // Получаем пользователя аботники user = (from u in _db.аботники 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); }
private bool ValidateUser(string Login, string password) { bool isValid = false; using (TPMDocContext _db = new TPMDocContext()) { try { аботники user = (from u in _db.аботники where u.Login == Login && u.Password == password select u).FirstOrDefault(); if (user != null && user.Password != null) { isValid = true; } } catch { isValid = false; } } return(isValid); }