/// <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()) } } }; }
/// <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()) } } }; }
/// <summary> /// GET /movies/{Id} /// </summary> public MovieResponse Get(Movie movie) { return new MovieResponse { Movie = Db.Id<Movie>(movie.Id), }; }
/// <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()) } } }; }