Beispiel #1
0
        public void AddPerson(PeopleRepository peopleRepository, string name, Programs program, string role)
        {
            var person = peopleRepository.GetPersonByName(name);

            // if "actor" exisit, then simply append current program to
            // its enrollment array
            if (person != null)
            {
                var updatedPerson = (People) person.Clone();
                updatedPerson.Enrollments.Add(new Enrollment
                {
                    ProgramId = program._id,
                    Role = role
                });

                peopleRepository.UpdatePerson(updatedPerson);
            }
            // else, add this person with this enrollment
            else
            {
                peopleRepository.AddPerson(new People
                {
                    _id = GetNextId("People"),
                    Name = name,
                    Enrollments = new List<Enrollment>
                                {
                                    new Enrollment
                                    {
                                        ProgramId = program._id,
                                        Role = role
                                    }
                                }
                });
            }
        }
Beispiel #2
0
        public void FillPeople()
        {
            var config = Database.GetCollection<Configurations>(Configurations).FindOne();

            if (!config.NeedUpdate["PeopleUpdate"])
                return;

            var programRepository = new ProgramsRepository(ConnectionString, DatabaseName);
            var programs = programRepository.GetAllPrograms();

            foreach (var program in programs)
            {
                if (program.PeopleAdded)
                    continue;

                var peopleRepository = new PeopleRepository(ConnectionString, DatabaseName);

                //Log
                Trace.TraceInformation("People: Started Processing Actors...");
                foreach (var actor in program.Actors)
                {
                    AddPerson(peopleRepository, actor, program, "Actor");
                }
                Trace.TraceInformation("People: Finished Processing Actors...");

                Trace.TraceInformation("People: Started Processing Directors...");
                foreach (var director in program.Directors)
                {
                    AddPerson(peopleRepository, director, program, "Director");
                }
                Trace.TraceInformation("People: Started Processing Directors...");

                Trace.TraceInformation("People: Started Processing Writers...");
                foreach (var writer in program.Writers)
                {
                    AddPerson(peopleRepository, writer, program, "Writer");
                }
                Trace.TraceInformation("People: Started Processing Writers...");

                // TODO: REMOVE COMMENT
                //var updatedProgram = (Programs)program.Clone();
                //updatedProgram.PeopleAdded = true;

                //programRepository.UpdateProgram(updatedProgram);
            }

            var updatedConfig = (Configurations) config.Clone();
            updatedConfig.NeedUpdate["PeopleUpdate"] = false;

            var query = Query<Configurations>.EQ(e => e._id, updatedConfig._id);
            var update = Update<Configurations>.Replace(updatedConfig); // update modifiers
            Database.GetCollection<Configurations>(Configurations).Update(query, update);
        }