Ejemplo n.º 1
0
        public Task <bool> SaveChangesAsync()
        {
            return(Task.Run(() =>
            {
                if (FilmsToAdd.Count() <= 0 && ActorsToAdd.Count() <= 0 &&
                    DirectorsToAdd.Count() <= 0 && FilmsToDelete.Count() <= 0 &&
                    ActorsToDelete.Count() <= 0 && DirectorsToDelete.Count() <= 0)
                {
                    return false;
                }

                foreach (var film in FilmsToAdd)
                {
                    film.Id = Films.Count() + 1;
                    Films.Add(film);
                }
                foreach (var actor in ActorsToAdd)
                {
                    actor.Id = Actors.Count() + 1;
                    Actors.Add(actor);
                }
                foreach (var director in DirectorsToAdd)
                {
                    director.Id = Directors.Count() + 1;
                    Directors.Add(director);
                }

                foreach (var film in FilmsToDelete)
                {
                    var filmInList = Films.Where(f => f.Id == film.Id).FirstOrDefault();
                    Films.Remove(filmInList);
                }
                foreach (var actor in ActorsToDelete)
                {
                    var actorInList = Actors.Where(f => f.Id == actor.Id).FirstOrDefault();
                    Actors.Remove(actorInList);
                }
                foreach (var director in DirectorsToDelete)
                {
                    var directorInList = Directors.Where(f => f.Id == director.Id).FirstOrDefault();
                    Directors.Remove(directorInList);
                }

                Initialize();
                return true;
            }));
        }
Ejemplo n.º 2
0
        public void Add <T>(T entity) where T : class
        {
            switch (entity.GetType().ToString())
            {
            case ("Films.Core.Director"):
                DirectorsToAdd.Add(entity as Director);
                break;

            case ("Films.Core.Film"):
                FilmsToAdd.Add(entity as Film);
                break;

            case ("Films.Core.Actor"):
                ActorsToAdd.Add(entity as Actor);
                break;

            default:
                break;
            }
        }