Ejemplo n.º 1
0
        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"));
        }
        public async Task <IActionResult> OnPostAsync(string[] selectedGenres)
        {
            var newAlbum = new Album();

            if (selectedGenres != null)
            {
                newAlbum.AlbumGenres = new List <AlbumGenre>();
                foreach (var gen in selectedGenres)
                {
                    var genToAdd = new AlbumGenre
                    {
                        GenreID = int.Parse(gen)
                    };
                    newAlbum.AlbumGenres.Add(genToAdd);
                }
            }

            if (await TryUpdateModelAsync <Album>(
                    newAlbum,
                    "Album",
                    i => i.Title, i => i.Singer,
                    i => i.Price, i => i.ReleaseDate, i => i.RecordLabelID))
            {
                _context.Album.Add(newAlbum);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedGenreData(_context, newAlbum);
            return(Page());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedGenres)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var albumToUpdate = await _context.Album
                                .Include(i => i.RecordLabel)
                                .Include(i => i.AlbumGenres)
                                .ThenInclude(i => i.Genre)
                                .FirstOrDefaultAsync(s => s.ID == id);

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

            if (await TryUpdateModelAsync <Album>(albumToUpdate,
                                                  "Album",
                                                  i => i.Title, i => i.Singer,
                                                  i => i.Price, i => i.ReleaseDate, i => i.RecordLabel))
            {
                UpdateAlbumGenres(_context, selectedGenres, albumToUpdate);
                await _context.SaveChangesAsync();

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


            UpdateAlbumGenres(_context, selectedGenres, albumToUpdate);
            PopulateAssignedGenreData(_context, albumToUpdate);
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

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

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

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 6
0
        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"));
        }