예제 #1
0
        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);
        }
예제 #2
0
        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);
        }