public async Task <bool> CheckKey(ParameterApiKey checkKeyParameters)
 {
     return((await BricksetHttpPostUrlEncodeAsync <ResultCheckKey, ParameterApiKey>(checkKeyParameters).ConfigureAwait(false)).Status == ResultStatus.Success);
 }
        public async Task <IEnumerable <Theme> > Synchronize(string apiKey)
        {
            _messageHub.Publish(new ThemeSynchronizerStart());

            var themeList = new List <Theme>();

            try
            {
                var getThemesParameters = new ParameterApiKey
                {
                    ApiKey = apiKey
                };

                var bricksetThemes = (await _bricksetApiService.GetThemes(getThemesParameters).ConfigureAwait(false)).ToList();

                _messageHub.Publish(new ThemesAcquired {
                    Count = bricksetThemes.Count
                });

                foreach (var bricksetTheme in bricksetThemes)
                {
                    _messageHub.Publish(new SynchronizingThemeStart {
                        Theme = bricksetTheme.Theme
                    });

                    try
                    {
                        var theme = bricksetTheme.ToTheme();

                        var getYearsParameters = new ParameterTheme
                        {
                            ApiKey = apiKey,
                            Theme  = bricksetTheme.Theme
                        };

                        theme.SetCountPerYear = (await _bricksetApiService.GetYears(getYearsParameters).ConfigureAwait(false))
                                                .ToYearSetCountEnumerable()
                                                .ToList();

                        var persistedTheme = _themeRepository.Get(theme.Name);

                        if (persistedTheme != null)
                        {
                            theme.Id = persistedTheme.Id;
                        }

                        _themeRepository.AddOrUpdate(theme);

                        themeList.Add(theme);
                    }
                    catch (Exception ex)
                    {
                        _messageHub.Publish(new SynchronizingThemeException {
                            Theme = bricksetTheme.Theme, Exception = ex
                        });
                    }

                    _messageHub.Publish(new SynchronizingThemeEnd {
                        Theme = bricksetTheme.Theme
                    });
                }
            }
            catch (Exception ex)
            {
                _messageHub.Publish(new ThemeSynchronizerException {
                    Exception = ex
                });
            }

            _messageHub.Publish(new ThemeSynchronizerEnd());

            return(themeList);
        }