Beispiel #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Genre).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GenreExists(Genre.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string[] selectedGenres)
        {
            var newSong = new Song();

            if (selectedGenres != null)
            {
                newSong.SongGenres = new List <SongGenre>();
                foreach (var gen in selectedGenres)
                {
                    var genToAdd = new SongGenre
                    {
                        GenreID = int.Parse(gen)
                    };
                    newSong.SongGenres.Add(genToAdd);
                }
            }
            if (await TryUpdateModelAsync <Song>(
                    newSong,
                    "Song",
                    i => i.Title, i => i.Album,
                    i => i.WeeksInTop40, i => i.FirstRelease, i => i.RecordLabelID, i => i.ArtistID))
            {
                _context.Song.Add(newSong);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedGenreData(_context, newSong);
            return(Page());
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Artist.Add(Artist);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Beispiel #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Genre = await _context.Genre.FindAsync(id);

            if (Genre != null)
            {
                _context.Genre.Remove(Genre);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            RecordLabel = await _context.RecordLabel.FindAsync(id);

            if (RecordLabel != null)
            {
                _context.RecordLabel.Remove(RecordLabel);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Artist = await _context.Artist.FindAsync(id);

            if (Artist != null)
            {
                _context.Artist.Remove(Artist);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedGenres)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var songToUpdate = await _context.Song
                               .Include(i => i.RecordLabel)
                               .Include(i => i.Artist)
                               .Include(i => i.SongGenres)
                               .ThenInclude(i => i.Genre)
                               .FirstOrDefaultAsync(s => s.ID == id);

            if (songToUpdate == null)
            {
                return(NotFound());
            }


            if (await TryUpdateModelAsync <Song>(
                    songToUpdate,
                    "Song",
                    i => i.Title, i => i.Album,
                    i => i.WeeksInTop40, i => i.FirstRelease, i => i.RecordLabel, i => i.ArtistID))
            {
                UpdateSongGenres(_context, selectedGenres, songToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            UpdateSongGenres(_context, selectedGenres, songToUpdate);
            PopulateAssignedGenreData(_context, songToUpdate);

            return(Page());
        }