Пример #1
0
 private async Task UpdateInSongTable(Song song, AdminAddEditSongVM vm)
 {
     song.SpotifyId = vm.SpotifyId;
     song.Artist    = vm.Artist;
     song.SongName  = vm.SongName;
     song.Year      = vm.Year;
     await context.SaveChangesAsync();
 }
Пример #2
0
        private async Task UpdateInQuestionTable(Question question, AdminAddEditSongVM vm)
        {
            question.CorrectAnswer = $"{vm.Artist} - {vm.SongName}";
            question.Answer1       = vm.Answer1;
            question.Answer2       = vm.Answer2;
            question.Answer3       = vm.Answer3;

            await context.SaveChangesAsync();
        }
Пример #3
0
        internal async Task UpdateSong(AdminAddEditSongVM vm)
        {
            var song = await context.Song.SingleAsync(s => s.Id == vm.SongId);

            var question = await context.Question.SingleAsync(q => q.SongId == vm.SongId);

            await UpdateInSongTable(song, vm);
            await UpdateInQuestionTable(question, vm);
        }
Пример #4
0
        public async Task <IActionResult> UpdateSong(AdminAddEditSongVM vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            await service.UpdateSong(vm);

            return(RedirectToAction(nameof(Index)));
        }
Пример #5
0
        private async Task AddToSongTable(AdminAddEditSongVM vm)
        {
            await context.Song.AddAsync(new Song
            {
                SpotifyId = vm.SpotifyId,
                Artist    = vm.Artist,
                SongName  = vm.SongName,
                Year      = vm.Year
            });

            await context.SaveChangesAsync();
        }
Пример #6
0
        private async Task AddToQuestionTable(AdminAddEditSongVM vm)
        {
            var newSong = await context.Song.AsNoTracking().SingleAsync(s => s.SpotifyId == vm.SpotifyId);

            await context.Question.AddAsync(new Question
            {
                CorrectAnswer = $"{vm.Artist} - {vm.SongName}",
                Answer1       = vm.Answer1,
                Answer2       = vm.Answer2,
                Answer3       = vm.Answer3,
                QuestionType  = 1, // remove hard-coding if alternatives added
                SongId        = newSong.Id
            });

            await context.SaveChangesAsync();
        }
Пример #7
0
 internal async Task AddSong(AdminAddEditSongVM vm)
 {
     await AddToSongTable(vm);
     await AddToQuestionTable(vm);
 }