// 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(RecordLabel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecordLabelExists(RecordLabel.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string[] selectedCategories) { var newAlbum = new Album(); if (selectedCategories != null) { newAlbum.AlbumCategories = new List <AlbumCategory>(); foreach (var cat in selectedCategories) { var catToAdd = new AlbumCategory { CategoryID = int.Parse(cat) }; newAlbum.AlbumCategories.Add(catToAdd); } } if (await TryUpdateModelAsync <Album>( newAlbum, "Album", i => i.Name, i => i.Singer, i => i.NumberOfSongs, i => i.Price, i => i.ReleaseDate, i => i.RecordLabel, i => i.RecordLabelID)) { _context.Album.Add(newAlbum); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newAlbum); 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(int?id, string[] selectedCategories) { if (id == null) { return(NotFound()); } var albumToUpdate = await _context.Album .Include(i => i.RecordLabel) .Include(i => i.AlbumCategories) .ThenInclude(i => i.Category) .FirstOrDefaultAsync(s => s.ID == id); if (albumToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Album>( albumToUpdate, "Album", i => i.Name, i => i.Singer, i => i.NumberOfSongs, i => i.Price, i => i.ReleaseDate, i => i.RecordLabel)) { UpdateAlbumCategories(_context, selectedCategories, albumToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } UpdateAlbumCategories(_context, selectedCategories, albumToUpdate); PopulateAssignedCategoryData(_context, albumToUpdate); 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.Category.Add(Category); 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")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } AlbumCategory = await _context.AlbumCategory.FindAsync(id); if (AlbumCategory != null) { _context.AlbumCategory.Remove(AlbumCategory); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }