예제 #1
0
 public void UpdateDirector(Director director)
 {
     using (WatchDb db = new WatchDb())
     {
         //kanonikos tropos
         db.Directors.Attach(director);                   //kane mou attach ton actor sto db set
         db.Entry(director).State = EntityState.Modified; //dld allakse tou to entity framework state. edw to entity ksekinaei na parakolouthei th metavlhth kai tou lew ti allagh egine
         db.SaveChanges();
     }
 }
예제 #2
0
 public void UpdateMovie(Movie movie, List <int> actorIds)
 {
     using (WatchDb db = new WatchDb())
     {
         db.Movies.Attach(movie);
         db.Entry(movie).Collection("Actors").Load();
         movie.Actors.Clear();
         db.SaveChanges();
         foreach (int id in actorIds)
         {
             Actor actor = db.Actors.Find(id);
             if (actor != null)
             {
                 movie.Actors.Add(actor);
             }
         }
         db.Entry(movie).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
예제 #3
0
 public void UpdateActor(Actor actor)
 {
     using (WatchDb db = new WatchDb())
     {
         #region First way example, not used
         ////aploikos tropos skepshs kai mh fysiologikos/apodotikos
         //Actor db_actor = db.Actors.Find(actor.Id); // vres mou apo th vash ton actor me to id pou psaxnw (to entity framework to kanei track afou proilthe apo th vash
         //db_actor.Name = actor.Name; // update first property
         //db_actor.Age = actor.Age; // update second property
         //db.SaveChanges();
         #endregion
         //kanonikos tropos
         db.Actors.Attach(actor);                      //kane mou attach ton actor sto db set
         db.Entry(actor).State = EntityState.Modified; //dld allakse tou to entity framework state. edw to entity ksekinaei na parakolouthei th metavlhth kai tou lew ti allagh egine
         db.SaveChanges();
     }
 }