예제 #1
0
        /// <summary>
        /// POST /movies
        /// 
        /// returns HTTP Response => 
        /// 	201 Created
        ///     Location: http://localhost/ServiceStack.MovieRest/movies/{newMovieId}
        /// 	
        /// 	{newMovie DTO in [xml|json|jsv|etc]}
        /// 
        /// </summary>
        public object Post(Movie movie)
        {
            Db.Insert(movie);
            var newMovieId = Db.GetLastInsertId();

            var newMovie = new MovieResponse {
                Movie = Db.Id<Movie>(newMovieId),
            };

            return new HttpResult(newMovie) {
                StatusCode = HttpStatusCode.Created,
                Headers = {
                    { HttpHeaders.Location, base.Request.AbsoluteUri.CombineWith(newMovieId.ToString()) }
                }
            };
        }
예제 #2
0
        /// <summary>
        /// PUT /movies/{id}
        /// </summary>
        public object Put(Movie movie)
        {
            Db.Update(movie);

            return new HttpResult {
                StatusCode = HttpStatusCode.NoContent,
                Headers = {
                    { HttpHeaders.Location, this.RequestContext.AbsoluteUri.CombineWith(movie.Id.ToString()) }
                }
            };
        }
예제 #3
0
 /// <summary>
 /// GET /movies/{Id} 
 /// </summary>
 public MovieResponse Get(Movie movie)
 {
     return new MovieResponse {
         Movie = Db.Id<Movie>(movie.Id),
     };
 }
예제 #4
0
        /// <summary>
        /// DELETE /movies/{Id}
        /// </summary>
        public object Delete(Movie request)
        {
            Db.DeleteById<Movie>(request.Id);

            return new HttpResult {
                StatusCode = HttpStatusCode.NoContent,
                Headers = {
                    { HttpHeaders.Location, this.RequestContext.AbsoluteUri.CombineWith(request.Id.ToString()) }
                }
            };
        }