/// <summary>
        /// 
        /// </summary>
        /// <param name="providerName">Имя поставщика пользователя</param>
        /// <param name="providerPageId">Уникальный идентификатор страницы пользователя в социальной сети</param>
        /// <returns></returns>
        public LoginContract LoginExternal(string providerName, string providerPageId)
        {
            LoginContract result = null;

            try
            {
                result = new LoginContract();
                result.response = new ResponseService();
                result.response.statusCode = 0;
                result.response.statusDescription = "OK";

                var userProvider = userRepository.GetProvidersByName(providerName).FirstOrDefault(i => i.providerPageId == providerPageId);
                var user = userRepository.GetUserById(userProvider.userId);
                if (user == null)
                {
                    result.response.statusCode = 1001;
                    result.response.statusDescription = "A user with this name already exists";
                    return result;
                }
                else
                {
                    result.user = new UserLoginContract { userId = user.userId, userName = user.userName };
                    result.roleName = roleRepository.GetRoleByUserName(user.userName);
                    result.response.statusDescription = "успешный вход в систему";
                    return result;
                }
            }
            catch (System.Exception ex)
            {
                result.response.statusDescription = ex.Message;
                result.response.statusCode = 1002;
            }
            finally
            {
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="username">Псевдоним пользователя</param>
        /// <param name="password">Пароль</param>
        /// <returns></returns>
        public LoginContract Login(string username, string password)
        {
            LoginContract result = null;

            try
            {
                result = new LoginContract();
                result.response = new ResponseService();
                result.response.statusCode = 0;
                result.response.statusDescription = string.Empty;

                User user = userRepository.GetUserByName(username);
                if (user == null)
                {
                    result.response.statusCode = 401;
                    result.response.statusDescription = "Unauthorized";
                    return result;
                }

                if (userRepository.ValidateUser(username, password))
                {
                    result.user = new UserLoginContract { userId = user.userId, userName = user.userName };
                    result.roleName = roleRepository.GetRoleByUserName(username);
                    result.response.statusCode = 202;
                    result.response.statusDescription = "Accepted";
                    return result;
                }
                else
                {
                    result.response.statusCode = 412;
                    result.response.statusDescription = "Precondition Failed";
                    return result;
                }
            }
            catch (System.Exception ex)
            {
                result.response.statusDescription = ex.Message;
                result.response.statusCode = 500;
            }
            finally
            {
            }

            return result;
        }