public IHttpActionResult Putdetailplaylist(int id, detailplaylist detailplaylist) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != detailplaylist.iddetailPL) { return(BadRequest()); } db.Entry(detailplaylist).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!detailplaylistExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Deleteplaylist(Int32 id) { //playlist playlist = db.playlists.Find(id); //if (playlist == null) //{ // return NotFound(); //} //db.playlists.Remove(playlist); //db.SaveChanges(); //return Ok(playlist); playlist list = db.playlists.Find(id); detailplaylist detail = db.detailplaylists.Where(b => b.idPlaylist == id) .FirstOrDefault(); if (list == null) { return(Ok(400)); } if (detail != null) { db.detailplaylists.RemoveRange(db.detailplaylists.Where(c => c.idPlaylist == id)); db.playlists.Remove(list); db.SaveChanges(); return(Ok(200)); } else { db.playlists.Remove(list); db.SaveChanges(); return(Ok(200)); } }
public IHttpActionResult Getdetailplaylist(int id) { detailplaylist detailplaylist = db.detailplaylists.Find(id); if (detailplaylist == null) { return(NotFound()); } return(Ok(detailplaylist)); }
public IHttpActionResult Postdetailplaylist(detailplaylist detailplaylist) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.detailplaylists.Add(detailplaylist); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = detailplaylist.iddetailPL }, detailplaylist)); }
public IHttpActionResult Deletedetailplaylist(int id) { detailplaylist detailplaylist = db.detailplaylists.Find(id); if (detailplaylist == null) { return(NotFound()); } db.detailplaylists.Remove(detailplaylist); db.SaveChanges(); return(Ok(detailplaylist)); }