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)); }
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(); }
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(); }
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")); }