public async Task <IActionResult> PutAlbum([FromRoute] int id, [FromBody] Album album) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != album.AlbumId) { return(BadRequest()); } _context.Entry(album).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AlbumExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album) { if (ModelState.IsValid) { // save new album cover if there is one if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file.FileName != null && file.ContentLength > 0) { string path = Server.MapPath("/Content/Images/") + file.FileName; file.SaveAs(path); album.AlbumArtUrl = "/Content/Images/" + file.FileName; } } db.Entry(album).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId); ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId); return(View(album)); }
public ActionResult Edit([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album) { if (ModelState.IsValid) { //Save album cover if there is one if (Request.Files.Count > 0) { var file = Request.Files[0]; //If this is a legit file, save it if (file.FileName != null && file.ContentLength > 0) { //This is the dynamic path that we want to save the image file string path = Server.MapPath("/Content/Images/") + file.FileName; //Save file into directory on server file.SaveAs(path); //Add new path to the database album.AlbumArtUrl = "/Content/Images/" + file.FileName; } } db.Entry(album).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId); ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId); return(View(album)); }
public ActionResult Edit([Bind(Include = "GenreId,Name,Description")] Genre genre) { if (ModelState.IsValid) { db.Entry(genre).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(genre)); }
public ActionResult Edit([Bind(Include = "OrderId,OrderDate,Username,FirstName,LastName,Address,City,State,PostalCode,Country,Phone,Email,Total")] Order order) { if (ModelState.IsValid) { db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(order)); }
public ActionResult Edit([Bind(Include = "ArtistId,Name")] Artist artist) { if (ModelState.IsValid) { db.Entry(artist).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(artist)); }
public ActionResult Put(int id, [FromBody] Album album) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Entry(album).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); return(NoContent()); }
public ActionResult Edit([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album) { if (ModelState.IsValid) { db.Entry(album).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId); ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId); return(View(album)); }
public async Task <IActionResult> Put(int id, [FromBody] Album album) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Entry(album).State = EntityState.Modified; await db.SaveChangesAsync(); return(AcceptedAtAction("Put", new { id = album.AlbumId }, album)); }