Пример #1
0
        public async Task Handle(HistoryUpdatedIntegrationEvent @event)
        {
            var userStatistics = await _recommendationRepository.GetUserStatistics(@event.UserId, @event.ProfileId);

            if (userStatistics == null)
            {
                var newUserStatistics = new UserStatisticsEntity()
                {
                    PartitionKey          = @event.UserId,
                    RowKey                = @event.ProfileId,
                    GenresPreferences     = $"{@event.Genres}:1",
                    RelaseYearPreferences = $"{@event.ReleaseYear}:1",
                    VideoIdPreferences    = @event.WatchingItemId
                };
                await _recommendationRepository.AddUserStatistics(newUserStatistics);
            }
            else
            {
                var genreDictionary       = userStatistics.GenresPreferences.ConvertToDictionary();
                var releaseYearDictionary = userStatistics.RelaseYearPreferences.ConvertToDictionary();
                IncrementValue(genreDictionary, @event.Genres);
                IncrementValue(releaseYearDictionary, @event.ReleaseYear);
                userStatistics.GenresPreferences     = genreDictionary.ConvertToString();
                userStatistics.RelaseYearPreferences = releaseYearDictionary.ConvertToString();
                userStatistics.VideoIdPreferences    = userStatistics.VideoIdPreferences + "," + @event.WatchingItemId;
                await _recommendationRepository.UpdateUserStatistics(userStatistics);
            }
        }