public IHttpActionResult PutFuelEntryModel(int id, FuelEntryModel fuelEntryModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != fuelEntryModel.Id) { return BadRequest(); } db.Entry(fuelEntryModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FuelEntryModelExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostFuelEntryModel(FuelEntryModel fuelEntryModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var defaultCar = db.Cars.Single(i => i.IsSelected); fuelEntryModel.CarId = defaultCar.Id; db.FuelEntries.Add(fuelEntryModel); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = fuelEntryModel.Id }, fuelEntryModel); }