Ejemplo n.º 1
0
        public ActionResult <IEnumerable <Park> > Put(int id, [FromBody] Park park)
        {
            park.ParkId = id;
            var currentChange = _db.Entry(park).CurrentValues.Clone();
            var original      = _db.Entry(park).GetDatabaseValues();

            _db.Entry(park).CurrentValues.SetValues(currentChange);
            _db.Entry(park).State = EntityState.Modified;
            _db.SaveChanges();

            State old = _db.States.FirstOrDefault(x => x.StateId == original.GetValue <int>("StateId"));

            old.NumberParks--;

            State current = _db.States.FirstOrDefault(x => x.StateId == currentChange.GetValue <int>("StateId"));

            current.NumberParks++;
            _db.SaveChanges();

            return(_db.Parks.Include(entry => entry.State).ToList());
        }
Ejemplo n.º 2
0
 public void Put(int id, [FromBody] State state)
 {
     state.StateId          = id;
     _db.Entry(state).State = EntityState.Modified;
     _db.SaveChanges();
 }