Example #1
0
        protected override void Update(PersonAppContext db, Person t)
        {
            var existingPerson = db.Persons
                                 .Include(x => x.Wishes).FirstOrDefault(s => s.Id == t.Id);

            if (existingPerson == null)
            {
                return;
            }
            {
                var wishesToRemove = new List <Wish>(existingPerson.Wishes.Where(i => t.Wishes.FirstOrDefault(x => x.Id == i.Id) == null));
                var wishesToAdd    = new List <Wish>(t.Wishes.Where(i => existingPerson.Wishes.FirstOrDefault(x => x.Id == i.Id) == null));

                foreach (var wish in wishesToRemove)
                {
                    existingPerson.Wishes.Remove(wish);
                }

                foreach (var wish in wishesToAdd)
                {
                    db.Wishes.Attach(wish);
                    existingPerson.Wishes.Add(wish);
                }

                existingPerson.Name           = t.Name;
                existingPerson.PersonStatusId = t.PersonStatusId;

                db.Entry(existingPerson).State = EntityState.Modified;
            }
        }
Example #2
0
 protected override Person Create(PersonAppContext db, Person t)
 {
     foreach (var w in t.Wishes)
     {
         db.Entry(w).State = EntityState.Unchanged;
     }
     return(db.Persons.Add(t));
 }
Example #3
0
 public ActionResult Edit([Bind(Include = "Id,Name,Created")] Wish wish)
 {
     if (ModelState.IsValid)
     {
         db.Entry(wish).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(wish));
 }
Example #4
0
        protected override void Delete(PersonAppContext db, int id)
        {
            var foundEntity = Read(db, id);

            db.Entry(foundEntity).State = EntityState.Deleted;
        }
Example #5
0
 protected override void Delete(PersonAppContext db, int id)
 {
     db.Entry(db.Wishes.FirstOrDefault(x => x.Id == id)).State = EntityState.Deleted;
 }
Example #6
0
 protected override void Update(PersonAppContext db, Wish t)
 {
     db.Entry(t).State = EntityState.Modified;
 }
        protected override void Delete(PersonAppContext db, int id)
        {
            var foundEntity = db.PersonStatuses.FirstOrDefault(x => x.Id == id);

            db.Entry(foundEntity).State = System.Data.Entity.EntityState.Deleted;
        }
 protected override void Update(PersonAppContext db, PersonStatus t)
 {
     db.Entry(t).State = System.Data.Entity.EntityState.Modified;
 }