Exemple #1
0
        public IHttpActionResult PutCar(int id, Car car)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != car.CarId)
            {
                return(BadRequest());
            }

            db.Entry(car).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        public void Update(T item, Func <T, bool> findByIDPredecate)
        {
            var local = Context.Set <T>()
                        .Local
                        .FirstOrDefault(findByIDPredecate);

            if (local != null)
            {
                Context.Entry(local).State = EntityState.Detached;
            }
            Context.Entry(item).State = EntityState.Modified;

            //    Context.Entry(category).State = EntityState.Modified;
            //var entry = Context.Entry(category);
            //Context.Categories.Attach(category);
            //entry.State = EntityState.Modified;
            Context.SaveChanges();
        }
Exemple #3
0
 public ActionResult Edit([Bind(Include = "id,year,make,model,type,horsepower,cylinders")] Car car)
 {
     if (ModelState.IsValid)
     {
         db.Entry(car).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(car));
 }
        public void EditCar(Car editCar)
        {
            CarsEntities ORM = new CarsEntities();

            Car found = ORM.Cars.Find(editCar.CarID);

            found.Color = editCar.Color;
            found.Make  = editCar.Model;
            found.Model = editCar.Model;

            ORM.Entry(found).State = System.Data.Entity.EntityState.Modified; //let them know it changed
            ORM.SaveChanges();
        }
Exemple #5
0
        public ActionResult SaveCarUpdate(Car updateCar)
        {
            Car editedCar = database.Cars.Find(updateCar.Id);

            editedCar.Make  = updateCar.Make;
            editedCar.Model = updateCar.Model;
            editedCar.Year  = updateCar.Year;
            editedCar.Color = updateCar.Color;

            database.Entry(editedCar).State = System.Data.Entity.EntityState.Modified;
            database.SaveChanges();

            return(RedirectToAction("Index"));
        }