Ejemplo n.º 1
0
        // 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());
        }
Ejemplo n.º 2
0
        // 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());
        }
Ejemplo n.º 3
0
        // 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));
        }
Ejemplo n.º 4
0
        // 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);
        }
Ejemplo n.º 5
0
        // 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);
        }