Пример #1
0
        public override string[] GetRolesForUser(string login)
        {
            string[] role = new string[] { };
            using (EFDbContext _db = new EFDbContext())
            {
                try
                {
                    // Получаем пользователя
                    /*Users user = (from u in _db.Users
                                 where u.login == login
                                 select u).FirstOrDefault();*/
                    Users user = _db.Users.FirstOrDefault(x => x.login == login);
                    if (user != null)
                    {
                        // получаем роль
                        Role userRole = _db.Roles.Find(user.role_id);

                        if (userRole != null)
                        {
                            role = new string[] { userRole.name };
                        }
                    }
                }
                catch
                {
                    role = new string[] { };
                }
            }
            return role;
        }
Пример #2
0
        public override bool IsUserInRole(string username, string roleName)
        {
            bool outputResult = false;
            // Находим пользователя
            using (EFDbContext _db = new EFDbContext())
            {
                try
                {
                    // Получаем пользователя
                    Users user = (from u in _db.Users
                                 where u.login == username
                                 select u).FirstOrDefault();
                    if (user != null)
                    {
                        // получаем роль
                        Role userRole = _db.Roles.Find(user.role_id);

                        //сравниваем
                        if (userRole != null && userRole.name == roleName)
                        {
                            outputResult = true;
                        }
                    }
                }
                catch
                {
                    outputResult = false;
                }
            }
            return outputResult;
        }
Пример #3
0
        private bool ValidateUser(string login, string password)
        {
            bool isValid = false;

            using (EFDbContext _db = new EFDbContext())
            {
                try
                {
                    
                    Users 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;
        }