44using Microsoft . EntityFrameworkCore ;
55using WebApi . Hal . Web . Api . Resources ;
66using WebApi . Hal . Web . Data ;
7+ using WebApi . Hal . Web . Models ;
78
89namespace WebApi . Hal . Web . Api
910{
@@ -23,25 +24,26 @@ public BeerRepresentation Get(int id)
2324 {
2425 var beer = beerDbContext . Beers
2526 . Include ( "Brewery" ) // lazy loading isn't on for this query; force loading
26- . Include ( "BeerStyle " )
27+ . Include ( "Style " )
2728 . Single ( br => br . Id == id ) ;
2829
2930 return new BeerRepresentation
30- {
31- Id = beer . Id ,
32- Name = beer . Name ,
33- BreweryId = beer . Brewery == null ? ( int ? ) null : beer . Brewery . Id ,
34- BreweryName = beer . Brewery == null ? null : beer . Brewery . Name ,
35- StyleId = beer . Style == null ? ( int ? ) null : beer . Style . Id ,
36- StyleName = beer . Style == null ? null : beer . Style . Name ,
37- ReviewIds = beerDbContext . Reviews . Where ( r => r . Beer_Id == id ) . Select ( r => r . Id ) . ToList ( )
38- } ;
31+ {
32+ Id = beer . Id ,
33+ Name = beer . Name ,
34+ BreweryId = beer . Brewery == null ? ( int ? ) null : beer . Brewery . Id ,
35+ BreweryName = beer . Brewery == null ? null : beer . Brewery . Name ,
36+ StyleId = beer . Style == null ? ( int ? ) null : beer . Style . Id ,
37+ StyleName = beer . Style == null ? null : beer . Style . Name ,
38+ ReviewIds = beerDbContext . Reviews . Where ( r => r . Beer_Id == id ) . Select ( r => r . Id ) . ToList ( )
39+ } ;
3940 }
4041
41- [ HttpPut ]
42- // PUT beer?id=1&value=foo
43- public void Put ( int id , string value )
42+ [ HttpPut ( "{id}" ) ]
43+ // 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)
44+ public void Put ( int id , [ FromBody ] BeerRepresentation value )
4445 {
46+ Console . WriteLine ( string . Format ( "new beer would be updated if repostory supported it! {0}, {1}" , value . Id , value . Name ) ) ;
4547 }
4648
4749 [ HttpDelete ]
0 commit comments