Ejemplo n.º 1
0
        /// <summary>
        /// POST /movies
        /// </summary>
        public override object OnPost(Movie movie)
        {
            var newMovieId = DbFactory.Exec(dbCmd => {
                dbCmd.Insert(movie);
                return(dbCmd.GetLastInsertId());
            });

            var newMovie = new MovieResponse {
                Movie = DbFactory.Exec(dbCmd => dbCmd.GetById <Movie>(newMovieId))
            };

            return(new HttpResult(newMovie)
            {
                StatusCode = HttpStatusCode.Created,
                Headers =
                {
                    { HttpHeaders.Location, this.RequestContext.AbsoluteUri.WithTrailingSlash() + newMovieId }
                }
            });
        }
        /// <summary>
        /// POST /movies
        /// </summary>
        public object Post(Movie movie)
        {
            using (var db = DbFactory.Open())
            {
                db.Save(movie);

                var newMovie = new MovieResponse
                {
                    Movie = db.SingleById <Movie>(movie.Id)
                };

                return(new HttpResult(newMovie)
                {
                    StatusCode = HttpStatusCode.Created,
                    Headers =
                    {
                        { HttpHeaders.Location, this.Request.AbsoluteUri.WithTrailingSlash() + movie.Id }
                    }
                });
            }
        }
		/// <summary>
		/// POST /movies
		/// </summary>
		public object Post(Movie movie)
		{
		    using (var db = DbFactory.Open())
		    {
                db.Insert(movie);
                var newMovieId = db.GetLastInsertId();

                var newMovie = new MovieResponse
                {
                    Movie = db.GetById<Movie>(newMovieId)
                };

                return new HttpResult(newMovie)
                {
                    StatusCode = HttpStatusCode.Created,
                    Headers = {
					    { HttpHeaders.Location, this.RequestContext.AbsoluteUri.WithTrailingSlash() + newMovieId }
				    }
                };
            }
		}