Пример #1
0
        public async Task <Score> ExecuteAsync(SetScoreCommand command, Score previousResult)
        {
            var currentSong = await _currentSongRepository.FirstOrDefault();

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

            var actualScore = (await _scoreRepository.GetAll($"select * from c where c.judgeUserId = '{command.JudgeUserId}' and c.songId = '{command.SongId}'")).FirstOrDefault();

            if (actualScore != null)
            {
                actualScore.ScoreNumber = command.ScoreNumber;
                actualScore.ScoredAt    = DateTime.UtcNow;

                await _scoreRepository.Update(actualScore);

                return(actualScore);
            }

            var score = new Score()
            {
                Id           = Guid.NewGuid(),
                JudgeUserId  = command.JudgeUserId,
                ScoredAt     = DateTimeOffset.UtcNow,
                ScoreNumber  = command.ScoreNumber,
                SingerUserId = currentSong.AddedByUser,
                SongId       = currentSong.SongId
            };

            await _scoreRepository.Add(score);

            return(score);
        }
Пример #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",
            });
        }
Пример #3
0
        public async Task <State> ExecuteAsync(GetStateQuery command, State previousResult)
        {
            var currentSong = await _currentSongRepository.FirstOrDefault();

            var queue = await _songRepository.GetAll("SELECT * FROM c where c.finished = false");

            if (currentSong != null)
            {
                queue = queue.Where(x => x.Id != currentSong.SongId);
            }

            var state = new State()
            {
                CurrentSong = currentSong,
                Queue       = queue.ToList()
            };

            return(state);
        }
Пример #4
0
        public async Task <SignalRMessage> ExecuteAsync(FinishSongCommand command, SignalRMessage previousResult)
        {
            var currentSong = await _currentSongRepository.FirstOrDefault();

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

            var song = await _songRepository.GetById(currentSong.SongId);

            song.Finished = true;

            await _songRepository.Update(song);

            await _currentSongRepository.Remove(currentSong.Id);

            return(new SignalRMessage
            {
                Arguments = new object[] { currentSong },
                GroupName = null,
                Target = "finishSongCommandNotification",
            });
        }
Пример #5
0
        public async Task <CurrentSong> ExecuteAsync(GetCurrentSongQuery command, CurrentSong previousResult)
        {
            var currentSong = await _currentSongRepository.FirstOrDefault();

            return(currentSong);
        }