public async Task <CurrentSong> UpdateOrCreateAsync(SongWithVoteCount song)
        {
            var currentSong = await _currentSongRepository.GetOrDefaultAsync();

            if (currentSong == null)
            {
                currentSong = _currentSongRepository.Create();
                _currentSongRepository.Add(currentSong);
            }

            currentSong.Map(song, _clock);

            return(currentSong);
        }
Пример #2
0
        public async Task <SignalRMessage> ExecuteAsync(StartSongCommand command, SignalRMessage previousResult)
        {
            var song = await _songRepository.GetById(command.SongId);

            if (song == null)
            {
                return(null);
            }

            song.Finished = true;
            await _songRepository.Update(song);

            var user = await _userRepository.GetById(song.AddedByUser);

            var currentSong = await _currentSongRepository.FirstOrDefault();

            if (currentSong != null)
            {
                await _currentSongRepository.Remove(currentSong.Id);
            }

            var actualCurrentSong = new CurrentSong
            {
                AddedAt       = song.AddedAt,
                AddedByUser   = song.AddedByUser,
                Author        = song.Author,
                Description   = song.Description,
                Duration      = song.Duration,
                Finished      = false,
                Id            = Guid.NewGuid(),
                NoAuthor      = song.NoAuthor,
                NoDescription = song.NoDescription,
                SongId        = song.Id,
                StartedAt     = DateTimeOffset.UtcNow,
                Thumbnail     = song.Thumbnail,
                Title         = song.Title,
                Url           = song.Url,
                ViewCount     = song.ViewCount,
                UserName      = user.UserName
            };

            await _currentSongRepository.Add(actualCurrentSong);

            return(new SignalRMessage
            {
                Arguments = new object[] { actualCurrentSong },
                GroupName = null,
                Target = "startSongCommandNotification",
            });
        }