Exemplo n.º 1
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.SaveChanges();
        }
Exemplo n.º 2
0
        public ActionResult Edit(Car carToEdit)
        {
            var originalCar = (from m in _db.Cars
                               where m.Id == carToEdit.Id
                               select m).First();

            if (!ModelState.IsValid)
            {
                return(View(originalCar));
            }

            _db.Entry(originalCar).CurrentValues.SetValues(carToEdit);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }