public async Task<IHttpActionResult> PostBus(Bus bus) { if (!ModelState.IsValid) { return BadRequest(ModelState); } bus.BusId = Guid.NewGuid(); db.Buses.Add(bus); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = bus.BusId }, bus); }
public async Task<IHttpActionResult> PutBus(Guid id, Bus bus) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != bus.BusId) { return BadRequest(); } //Bus dbBus = await db.Buses.FindAsync(bus.BusId); //bus.CreatedBy = dbBus.CreatedBy; //bus.CreatedUtc = dbBus.CreatedUtc; db.Entry(bus).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BusExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }