public async Task UpdateSettingsAsync([FromBody] Setting newSetting) { using (var db = new CarRentalDatabase()) { var setting = await db.Settings.FirstOrDefaultAsync(); setting.DayPrice = newSetting.DayPrice; setting.KilometerPrice = newSetting.KilometerPrice; await db.SaveChangesAsync(); } }
// PUT: odata/CarTypes(5) public async Task <IHttpActionResult> Put([FromODataUri] byte key, Delta <CarType> patch) { //Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CarType carType = await db.CarTypes.FindAsync(key); if (carType == null) { return(NotFound()); } patch.Put(carType); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarTypeExists(key)) { return(NotFound()); } else { throw; } } return(Updated(carType)); }
// PUT: odata/Rents(5) public async Task <IHttpActionResult> Put([FromODataUri] int key, Delta <Rent> patch) { //Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Rent rent = await db.Rents.FindAsync(key); if (rent == null) { return(NotFound()); } patch.Put(rent); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentExists(key)) { return(NotFound()); } else { throw; } } return(Updated(rent)); }