@@ -55,6 +55,56 @@ public SingleResult<TEntity> Get([FromODataUri] TPrimaryKey key)
5555 return SingleResult . Create ( entity ) ;
5656 }
5757
58+ public async Task < IHttpActionResult > Post ( TEntity entity )
59+ {
60+ if ( ! ModelState . IsValid )
61+ {
62+ return BadRequest ( ModelState ) ;
63+ }
64+ var created = await Repository . InsertAsync ( entity ) ;
65+ return Created ( created ) ;
66+ }
67+
68+ public async Task < IHttpActionResult > Patch ( [ FromODataUri ] TPrimaryKey key , Delta < TEntity > entity )
69+ {
70+ if ( ! ModelState . IsValid )
71+ {
72+ return BadRequest ( ModelState ) ;
73+ }
74+ var dbLookup = await Repository . GetAsync ( key ) ;
75+ if ( entity == null )
76+ {
77+ return NotFound ( ) ;
78+ }
79+ entity . Patch ( dbLookup ) ;
80+ return Updated ( entity ) ;
81+ }
82+
83+ public async Task < IHttpActionResult > Put ( [ FromODataUri ] TPrimaryKey key , TEntity update )
84+ {
85+ if ( ! ModelState . IsValid )
86+ {
87+ return BadRequest ( ModelState ) ;
88+ }
89+ if ( ! Equals ( key , update . Id ) )
90+ {
91+ return BadRequest ( ) ;
92+ }
93+ var updated = await Repository . UpdateAsync ( update ) ;
94+ return Updated ( updated ) ;
95+ }
96+
97+ public async Task < IHttpActionResult > Delete ( [ FromODataUri ] TPrimaryKey key )
98+ {
99+ var product = await Repository . GetAsync ( key ) ;
100+ if ( product == null )
101+ {
102+ return NotFound ( ) ;
103+ }
104+ await Repository . DeleteAsync ( key ) ;
105+ return StatusCode ( HttpStatusCode . NoContent ) ;
106+ }
107+
58108 protected override void Dispose ( bool disposing )
59109 {
60110 if ( ! _disposed )
0 commit comments