// POST beers public ActionResult Post(BeerRepresentation value) { var newBeer = new Beer(value.Name); repository.Add(newBeer); return(new CreatedResult(LinkTemplates.Beers.Beer.CreateUri(new { id = newBeer.Id }), newBeer.Id)); }
// POST beers public IActionResult Post([FromBody] BeerRepresentation value) { var newBeer = new Beer(value.Name) { Style_Id = value.StyleId.Value, Brewery_Id = value.BreweryId.Value }; repository.Add(newBeer); return(Created(LinkTemplates.Beers.Beer.CreateUri(new { id = newBeer.Id }), newBeer)); }
// POST beers public HttpResponseMessage Post(BeerRepresentation value) { var newBeer = new Beer(value.Name); repository.Add(newBeer); return(new HttpResponseMessage(HttpStatusCode.Created) { Headers = { Location = LinkTemplates.Beers.Beer.CreateUri(new { id = newBeer.Id }) } }); }
// POST api/beers public HttpResponseMessage Post(BeerRepresentation value) { var newBeer = new Beer(value.Name); beerDbContext.Beers.Add(newBeer); beerDbContext.SaveChanges(); return(new HttpResponseMessage(HttpStatusCode.Created) { Headers = { Location = LinkTemplates.Beers.Beer.CreateUri(id => newBeer.Id) } }); }
// PUT beer/5 with a hal representation in the body as json. Be sure to set content-type: application/hal+json (and accept: application/hal+json for the response) public void Put(int id, [FromBody] BeerRepresentation value) { Console.WriteLine(string.Format("new beer would be updated if repostory supported it! {0}, {1}", value.Id, value.Name)); }
public void Put(int id, [FromBody] BeerRepresentation value) { Console.WriteLine($"new beer would be updated if repostory supported it! {value.Id}, {value.Name}"); }