Esempio n. 1
0
        /// <summary>
        /// Makes a new instance of photo and write it in the database.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        // POST: api/Photos
        public HttpResponseMessage Post([FromBody] Photos value)
        {
            int id;
            PhotosPersistence photoPersistance = new PhotosPersistence();

            id = photoPersistance.SavePhoto(value);

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);

            response.Headers.Location = new Uri(Request.RequestUri, String.Format("Photos/{0}", id));
            return(response);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a photo by its id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        // GET: api/Photos/5
        public Photos Get(int id)
        {
            PhotosPersistence photosPersistance = new PhotosPersistence();
            Photos            photo             = photosPersistance.GetPhoto(id);

            if (photo.Id != 0)
            {
                return(photo);
            }
            else
            {
                Request.CreateResponse(HttpStatusCode.NotFound);
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Delete an instance of photos.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        // DELETE: api/Photos/5
        public HttpResponseMessage Delete(int id)
        {
            bool request = false;
            PhotosPersistence photosPersistance = new PhotosPersistence();

            request = photosPersistance.DeletePhoto(id);

            HttpResponseMessage response;

            if (request)
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(response);
        }
Esempio n. 4
0
        /// <summary>
        /// Updates values in photo database by photo id.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        // PUT: api/Photos/5
        public HttpResponseMessage Put(int id, [FromBody] Photos value)
        {
            bool request = false;
            PhotosPersistence photosPersistance = new PhotosPersistence();

            request = photosPersistance.UpdatePhoto(id, value);

            HttpResponseMessage response;

            if (request)
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(response);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets all the photos.
        /// </summary>
        /// <returns></returns>
        // GET: api/Photos
        public List <Photos> Get()
        {
            PhotosPersistence photosPersistance = new PhotosPersistence();

            return(photosPersistance.GetPhotos());
        }