public override string[] GetRolesForUser(string email)
        {
            string[] role = new string[] { };
            using (EnterpriseContext _db = new EnterpriseContext())
            {
                try
                {
                    // Получаем пользователя
                    User user = (from u in _db.Users
                                 where u.Email == email
                                 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 void CreateRole(string roleName)
 {
     Role newRole = new Role() { Name = roleName };
     EnterpriseContext db = new EnterpriseContext();
     db.Roles.Add(newRole);
     db.SaveChanges();
 }
        public override bool IsUserInRole(string username, string roleName)
        {
            bool outputResult = false;
            // Находим пользователя
            using (EnterpriseContext _db = new EnterpriseContext())
            {
                try
                {
                    // Получаем пользователя
                    User user = (from u in _db.Users
                                 where u.Email == 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;
        }
        public MembershipUser CreateUser(string email, string password)
        {
            MembershipUser membershipUser = GetUser(email, false);

            if (membershipUser == null)
            {
                try
                {
                    using (EnterpriseContext _db = new EnterpriseContext())
                    {
                        User user = new User();
                        user.Email = email;
                        user.Password = Crypto.HashPassword(password);
                        user.CreationDate = DateTime.Now;

                        if (_db.Roles.Find(2) != null)
                        {
                            user.RoleId = 2;
                        }

                        _db.Users.Add(user);
                        _db.SaveChanges();
                        membershipUser = GetUser(email, false);
                        return membershipUser;
                    }
                }
                catch
                {
                    return null;
                }
            }
            return null;
        }
        public override bool ValidateUser(string username, string password)
        {
            bool isValid = false;

            using (EnterpriseContext _db = new EnterpriseContext())
            {
                try
                {
                    User user = (from u in _db.Users
                                 where u.Email == username
                                 select u).FirstOrDefault();

                    if (user != null && Crypto.VerifyHashedPassword(user.Password, password))
                    {
                        isValid = true;

                    }
                }
                catch
                {
                    isValid = false;
                }
            }

            return isValid;
        }
 public override MembershipUser GetUser(string email, bool userIsOnline)
 {
     try
     {
         using (EnterpriseContext _db = new EnterpriseContext())
         {
             var users = from u in _db.Users
                         where u.Email == email
                         select u;
             if (users.Count() > 0)
             {
                 User user = users.First();
                 MembershipUser memberUser = new MembershipUser("MyMembershipProvider", user.Email, null, null, null, null,
                     false, false, user.CreationDate, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue);
                 return memberUser;
             }
         }
     }
     catch
     {
         return null;
     }
     return null;
 }