public IHttpActionResult PutVocalist(int id, Vocalist vocalist) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != vocalist.Id) { return(BadRequest()); } db.Entry(vocalist).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VocalistExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetVocalist(int id) { Vocalist vocalist = db.Vocalists.Where(v => v.Id == id && v.UserId == User.Identity.GetUserId()).FirstOrDefault(); if (vocalist == null) { return(NotFound()); } return(Ok(vocalist)); }
public IHttpActionResult PostVocalist(Vocalist vocalist) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } vocalist.UserId = User.Identity.GetUserId(); db.Vocalists.Add(vocalist); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = vocalist.Id }, vocalist)); }
public IHttpActionResult DeleteVocalist(int id) { Vocalist vocalist = db.Vocalists.Find(id); if (vocalist == null) { return(NotFound()); } if (vocalist.UserId != User.Identity.GetUserId()) { return(StatusCode(HttpStatusCode.Forbidden)); } db.Vocalists.Remove(vocalist); db.SaveChanges(); return(Ok(vocalist)); }