public IList <ExternalLoginProviderViewModel> FindExternalProviderViewModels()
        {
            var externalLoginProviders = m_externalLoginProviderManager.FindAllExternalLoginProviders();

            var enabledExternalLoginProviders = externalLoginProviders.Result.Where(x => x.Enable && !x.HideOnLoginScreen).ToList();

            var externalLoginProviderList = m_mapper.Map <IList <ExternalLoginProviderViewModel> >(enabledExternalLoginProviders);

            foreach (var externalLoginProvider in externalLoginProviderList.ToList())
            {
                externalLoginProvider.LogoFileName = m_fileResourceManager.ResolveFullPath(externalLoginProvider.Logo);
            }

            return(externalLoginProviderList);
        }
        public EditableUserViewModel <T> GetEditableUserViewModel <T>(IList <RoleViewModel> roles, T userViewModel = null,
                                                                      IList <string> validTwoFactorProviders       = null)
            where T : UserViewModel, new()
        {
            var selectableRoles = m_genericViewModelFactory.GetSelectableViewmodelList(roles);

            var enabledExternalLoginProviders = m_externalLoginProviderManager.FindManageableExternalLoginProviders()
                                                .Result.Where(x => x.Enable).ToList();

            var availableExternalLoginProviders = m_mapper.Map <IList <ExternalLoginProviderViewModel> >(
                enabledExternalLoginProviders
                );

            foreach (var externalLoginProvider in availableExternalLoginProviders)
            {
                externalLoginProvider.LogoFileName = m_fileResourceManager.ResolveFullPath(externalLoginProvider.Logo);

                if (userViewModel != null)
                {
                    foreach (var externalUserLogin in userViewModel.ExternalUserLogins.Where(x =>
                                                                                             Equals(x.LoginProvider, externalLoginProvider))
                             )
                    {
                        externalUserLogin.LoginProvider.LogoFileName = externalLoginProvider.LogoFileName;
                    }
                }
            }

            if (userViewModel != null)
            {
                selectableRoles.ForEach(role =>
                                        role.IsSelected = userViewModel.Roles?
                                                          .FirstOrDefault(userRole => userRole.Id == role.Item.Id)
                                                          != null
                                        );

                if (validTwoFactorProviders != null)
                {
                    userViewModel.TwoFactorProviders = validTwoFactorProviders;
                }

                foreach (var externalLogin in userViewModel.ExternalUserLogins.ToList())
                {
                    if (!externalLogin.LoginProvider.Enable)
                    {
                        userViewModel.ExternalUserLogins.Remove(externalLogin);
                    }

                    availableExternalLoginProviders.Remove(externalLogin.LoginProvider);

                    if (string.IsNullOrEmpty(externalLogin.LoginProvider.LogoFileName))
                    {
                        externalLogin.LoginProvider.LogoFileName = m_fileResourceManager.ResolveFullPath(externalLogin.LoginProvider.Logo);
                    }
                }
            }

            return(new EditableUserViewModel <T>
            {
                UserViewModel = userViewModel ?? new T(),

                SelectableRoles = selectableRoles,
                AvailableExternalLoginProviders = availableExternalLoginProviders
            });
        }