public Album(string name, AlbumCategory category) { this.Name = name; this.Category = category; AudioFile = $"/Assets/Audio/{category}/{name}.mp3"; ImageFile = $"/Assets/Images/{category}/{name}.png"; }
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()); }
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")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } AlbumCategory = await _context.AlbumCategory .Include(a => a.Album) .Include(a => a.Category).FirstOrDefaultAsync(m => m.ID == id); if (AlbumCategory == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } AlbumCategory = await _context.AlbumCategory .Include(a => a.Album) .Include(a => a.Category).FirstOrDefaultAsync(m => m.ID == id); if (AlbumCategory == null) { return(NotFound()); } ViewData["AlbumID"] = new SelectList(_context.Album, "ID", "ID"); ViewData["CategoryID"] = new SelectList(_context.Set <Category>(), "ID", "ID"); return(Page()); }
public void TestDeserialization() { JsonRepository <TestEntity> repo = new JsonRepository <TestEntity>(); int id = 3; TestEntity te = new TestEntity(id); string testTitle = "Test Title"; te.Title = testTitle; double testPrice = 7.15; te.UnitPrice = testPrice; AlbumCategory testCat = AlbumCategory.Pop; te.Category = testCat; int testQty = 7; te.Quantity = testQty; DateTime testDate = DateTime.Now.Date; te.ReleaseDate = testDate; repo.Save(te); Album a3 = repo.GetById(id); Assert.IsTrue(a3.Title == testTitle); Assert.IsTrue(a3.UnitPrice == testPrice); Assert.IsTrue(a3.Category == testCat); Assert.IsTrue(a3.Quantity == testQty); Assert.IsTrue(a3.ReleaseDate == testDate); Directory.Delete(repo.FolderPath, true); }