public HttpResponseMessage PostMovie(Movie entity) { entity = facade.MovieRepository.Add(entity); var response = Request.CreateResponse<Movie>(HttpStatusCode.Created, entity); string uri = Url.Link("DefaultApi", new { id = entity.Id }); response.Headers.Location = new Uri(uri); return response; }
public ActionResult Create(Movie movie, string[] idGenre) { if (ModelState.IsValid) { if (idGenre != null) { movie.genres = new List<Genres>(); foreach (String genreId in idGenre) { int id = int.Parse(genreId); Genres genre = new Genres() { id = id }; movie.genres.Add(genre); } } Facade.GetMovieGateway().Create(movie); return RedirectToAction("Index"); } MovieViewModel movieViewModel = new MovieViewModel(); movieViewModel.genreList = Facade.GetGenreGateway().ReadAll().ToList(); movieViewModel.movie = movie; return View(movieViewModel); }
// PUT /api/products/id // The id parameter is taken from the URI path, and the product parameter is deserialized // from the request body. By default, the ASP.NET Web API framework takes simple parameter // types from the route and complex types from the request body. /// <summary> /// Replaces a product with a new product /// </summary> /// <param name="id">Product Id of the product to replace</param> /// <param name="movie">The new product</param> public void PutProduct(int id, Movie movie) { movie.Id = id; if (!facade.MovieRepository.Update(movie)) { throw new HttpResponseException(HttpStatusCode.NotFound); } }