Esempio n. 1
0
        public async Task <IHttpActionResult> Put([FromODataUri] int key, Car update)
        {
            WebApiConfig.Logger.info("enter CarsController->Put car where id = " + key.ToString());

            if (!ModelState.IsValid)
            {
                WebApiConfig.Logger.warning("return from CarsController->Put car where id = " + key.ToString() + " BAD REQUEST");

                return(BadRequest(ModelState));
            }
            if (key != update.Id)
            {
                WebApiConfig.Logger.warning("return from CarsController->Put car where id = " + key.ToString() + " key != update.Id");

                return(BadRequest());
            }
            //db.Entry(update).State = EntityState.Modified;
            db.Update(update);
            try
            {
                //await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!db.CarExists(key))
                {
                    WebApiConfig.Logger.warning("return from CarsController->Put where car doesn't exist");

                    return(NotFound());
                }
                else
                {
                    WebApiConfig.Logger.error("exception thrown in CarsController->Put car where id = " + key.ToString());

                    throw;
                }
            }
            WebApiConfig.Logger.info("return from CarsController->Put car where id = " + key.ToString());

            return(Updated(update));
        }