public async Task<IHttpActionResult> Post( Driver driver ) { if ( ModelState.IsValid == false ) { return BadRequest( ModelState ); } await DriverService.Create( driver ); if ( driver.Id == 0 ) { return BadRequest(); } return Created( driver ); }
public async Task<Driver> Update( Driver updated ) { if ( updated == null ) { return null; } Driver existing = await Db.Drivers.FindAsync( updated.Id ); if ( existing == null ) { return null; } Db.Entry( existing ).CurrentValues.SetValues( updated ); await Db.SaveChangesAsync(); return existing; }
public async Task<IHttpActionResult> Put( [FromODataUri] int key, Driver driver ) { if ( driver == null || ModelState.IsValid == false ) { return BadRequest(); } Driver original = await DriverService.Find( key ); if ( original == null ) { return NotFound(); } await DriverService.Update( driver ); return Updated( driver ); }
public async Task<int> Delete( Driver delete ) { Db.Drivers.Remove( delete ); return await Db.SaveChangesAsync(); }
public async Task<Driver> Create( Driver newDriver ) { Db.Drivers.Add( newDriver ); await Db.SaveChangesAsync(); return newDriver; }