using System; using System.Collections.Generic; using System.Linq; using eegscreening.Models.ViewModels; using eegscreening.Models.DB; using System.Web.Security; namespace test.Models.ObjectManager { public class RoleManager : RoleProvider { public override string[] GetRolesForUser(string username) { if (username != null) { using (EEGScreeningEntities db = new EEGScreeningEntities()) { var user = db.aspnet_Users.FirstOrDefault(u => u.UserName.Equals(username, StringComparison.CurrentCultureIgnoreCase) || u.Email.Equals(username, StringComparison.CurrentCultureIgnoreCase)); var roles = from ur in user.aspnet_Roles from r in db.User_In_Roles where ur.RoleId == r.RoleId select ur.RoleName; if (roles != null) return roles.ToArray(); else return new string[] { }; } } return new string[] { }; } public override bool IsUserInRole(string username, string roleName) { using (EEGScreeningEntities db = new EEGScreeningEntities()) { var user = db.aspnet_Users.FirstOrDefault(u => u.UserName.Equals(username, StringComparison.CurrentCultureIgnoreCase) || u.Email.Equals(username, StringComparison.CurrentCultureIgnoreCase)); var roles = from ur in user.aspnet_Roles from r in db.aspnet_Roles where ur.RoleId == r.RoleId select r.RoleName; if (user != null) return roles.Any(r => r.Equals(roleName, StringComparison.CurrentCultureIgnoreCase)); else return false; } } public override void AddUsersToRoles(string[] usernames, string[] roleNames) { throw new NotImplementedException(); } public override string ApplicationName { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } public override void CreateRole(string roleName) { throw new NotImplementedException(); } public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { throw new NotImplementedException(); } public override string[] FindUsersInRole(string roleName, string usernameToMatch) { throw new NotImplementedException(); } public override string[] GetAllRoles() { throw new NotImplementedException(); } public override string[] GetUsersInRole(string roleName) { throw new NotImplementedException(); } public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { throw new NotImplementedException(); } public override bool RoleExists(string roleName) { throw new NotImplementedException(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)