Ejemplo n.º 1
0
        public IHttpActionResult PatchCar(Car car)
        {
            if (context.Cars.ToList().Where(x=>x.CarId == car.CarId).FirstOrDefault() == null)
                return this.NotFound();
            else
            {
                context.Cars.ToList().Remove(car);
                context.Cars.Add(car);
                context.SaveChanges();

                return this.Ok<Car>(car);
            }
        }
Ejemplo n.º 2
0
 public IHttpActionResult PutCar(Car car)
 {
     if (car == null)
         return this.BadRequest("Car cannot be null");
     try {
         context.Cars.Add(car);
         context.SaveChanges();
         return this.Ok<Car>(car);
     }
     catch(DbUpdateConcurrencyException ex)
     {
         var entry = ex.Entries.Single();
         entry.OriginalValues.SetValues(entry.GetDatabaseValues());
         return this.BadRequest("A concurrency exception was raised "+ ex.Message);
     }
     catch(Exception ex)
     {
         return this.BadRequest("An exception was raised." + ex.Message);
     }
 }