public async Task <IActionResult> Edit(long id, [Bind("Id,Author,Title,Genre,MediaUrl,MediaName,MediaFileId")] ChangeAlbumViewModel model) { if (id != model.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var album = await GetAlbumAsync(id, await GetUserIdAsync()); if (album != null) { album.Author = model.Author; album.Title = model.Title; album.Genre = model.Genre; album.MediaUrl = model.MediaUrl; album.DateModified = DateTime.Now; await CreateOrUpdateCoverAsync(album, model.MediaName); Database.Update(album); await Database.SaveChangesAsync(); } else { return(NotFound()); } } catch (DbUpdateConcurrencyException) { if (!CurrentAlbumExists(model.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } await RetrieveExistingImages(model.MediaFileId); return(View(model)); }
public async Task <IActionResult> Create([Bind("Id,Author,Title,Genre,MediaUrl,MediaName,MediaFileId")] ChangeAlbumViewModel model) { if (ModelState.IsValid) { var album = new MediaAlbum { Author = model.Author, Title = model.Title, Genre = model.Genre, UserId = await GetUserIdAsync(), MediaFileId = model.MediaFileId, }; await CreateOrUpdateCoverAsync(album, model.MediaName); Database.Add(album); await Database.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = album.Id })); } await RetrieveExistingImages(model.MediaFileId); return(View(model)); }