public async Task<IHttpActionResult> Post( Race race ) { if ( ModelState.IsValid == false ) { return BadRequest( ModelState ); } await RaceService.Create( race ); if ( race.Id == 0 ) { return BadRequest(); } return Created( race ); }
public async Task<Race> Update( Race updated ) { if ( updated == null ) { return null; } Race existing = await Db.Races.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, Race race ) { if ( race == null || ModelState.IsValid == false ) { return BadRequest(); } Race original = await RaceService.Find( key ); if ( original == null ) { return NotFound(); } await RaceService.Update( race ); return Updated( race ); }
public async Task<int> Delete( Race delete ) { Db.Races.Remove( delete ); return await Db.SaveChangesAsync(); }
public async Task<Race> Create( Race newRace ) { Db.Races.Add( newRace ); await Db.SaveChangesAsync(); return newRace; }