// GET api/<controller>/5 /// <summary> /// Retrieve a dvd item with the specified item_id /// </summary> /// <param name="item_id">ID generated by database upon its creation</param> public DVD Get(int item_id) { DVDPersistence dvdp = new DVDPersistence(); dvdp.addCallField("item_id", item_id, System.Data.SqlDbType.Int, 4); return((DVD)dvdp.Get()); }
// GET api/<controller> /// <summary> /// Retrieve a list of dvd items that match your criteria (All fields are optional. If no fields are given all items will be retrieved) /// </summary> /// <param name="title">The title of the DVD</param> /// <param name="release_year">The year the movie was released on DVD</param> /// <param name="rating">The movies MPAA rating</param> public ArrayList Get(string title = null, int?release_year = null, string rating = null) { DVDPersistence dvdp = new DVDPersistence(); dvdp.addCallField("title", title, System.Data.SqlDbType.VarChar, 50); dvdp.addCallField("release_year", release_year, System.Data.SqlDbType.Int, 4); dvdp.addCallField("rating", rating, System.Data.SqlDbType.VarChar, 50); return(dvdp.GetAll()); }
// POST api/<controller> /// <summary> /// Create a new dvd item /// </summary> public HttpResponseMessage Post([FromBody] DVD value) { DVDPersistence dvdp = new DVDPersistence(); int id = dvdp.Save(value, "item_id"); if (id != -1) { value.item_id = id; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); response.Headers.Location = new Uri(Request.RequestUri, String.Format("dvd?item_id={0}", id)); return(response); } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
// DELETE api/<controller>/5 /// <summary> /// Delete the dvd item with a specified item_id /// </summary> /// <param name="item_id">ID generated by database upon its creation</param> public HttpResponseMessage Delete(int item_id) { DVDPersistence tp = new DVDPersistence(); tp.addCallField("item_id", item_id, System.Data.SqlDbType.Int, 4); bool recordExisted = tp.Delete(); HttpResponseMessage response; if (recordExisted) { response = Request.CreateResponse(HttpStatusCode.NoContent); } else { response = Request.CreateResponse(HttpStatusCode.NotFound); } return(response); }
// PUT api/<controller>/5 /// <summary> /// Update an existing dvd item with a specified item_id /// </summary> /// <param name="item_id">ID generated by database upon its creation</param> public HttpResponseMessage Put(int item_id, [FromBody] DVD value) { DVDPersistence dvdp = new DVDPersistence(); dvdp.addCallField("item_id", item_id, System.Data.SqlDbType.Int, 4); bool recordExisted = dvdp.Update(value); HttpResponseMessage response; if (recordExisted) { response = Request.CreateResponse(HttpStatusCode.NoContent); } else { response = Request.CreateResponse(HttpStatusCode.NotFound); } return(response); }