public override bool IsUserInRole(string username, string roleName) { DMSContext db = new DMSContext(); bool outputResult = false; try { User user = (from u in db.Users where u.Login == username select u).FirstOrDefault(); if (user != null) { Role userRole = db.Roles.FirstOrDefault(item => item.Id == user.RoleId); if (userRole != null && userRole.Name == roleName) { outputResult = true; } } } catch { outputResult = false; } return(outputResult); }
public override string[] GetRolesForUser(string login) { DMSContext db = new DMSContext(); string[] role = { }; try { User user = (from u in db.Users where u.Login == login select u).FirstOrDefault(); if (user != null) { Role userRole = db.Roles.FirstOrDefault(item => item.Id == user.RoleId); if (userRole != null) { role = new[] { userRole.Name }; } } } catch { role = new string[] { }; } return(role); }