예제 #1
0
        public void FillSuggestions()
        {
            var config = Database.GetCollection<Configurations>(Configurations).FindOne();

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

            var programRepository = new ProgramsRepository(ConnectionString, DatabaseName);
            var suggestionsRepository = new SuggestionsRepository(ConnectionString, DatabaseName);

            var programs = programRepository.GetAllPrograms().ToList();

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

                foreach (var candidate in programs.Where(candidate => program._id != candidate._id))
                {
                    bool addSuggested;
                    var oneGenre = false;
                    var writers = false;
                    var directors = false;
                    var twoActors = false;

                    if (program.Genres.SequenceEqual(candidate.Genres))
                        addSuggested = true;
                    else
                    {
                        if (program.Genres.Except(candidate.Genres).Count() < program.Genres.Count())
                            oneGenre = true;

                        if (program.Directors.SequenceEqual(candidate.Directors))
                            directors = true;

                        if (program.Writers.SequenceEqual(candidate.Writers))
                            writers = true;

                        if (program.Actors.Except(candidate.Actors).Count() <= program.Actors.Count() - 2)
                            twoActors = true;

                        addSuggested = (oneGenre && writers) || (oneGenre && directors) || (oneGenre && twoActors);
                    }

                    if (addSuggested)
                    {
                        AddSuggestion(suggestionsRepository, program, candidate);
                    }
                }
            }
        }
예제 #2
0
        public void AddSuggestion(SuggestionsRepository suggestionsRepository, Programs program, Programs candidate)
        {
            var suggestion = suggestionsRepository.GetSuggestionByProgramId(program._id);

            if (suggestion != null)
            {
                var updatedSuggestion = (Suggestions) suggestion.Clone();
                updatedSuggestion.SuggestedPrograms.Add(candidate);

                suggestionsRepository.UpdatePerson(updatedSuggestion);
            }
            else
            {
                suggestionsRepository.AddSuggestion(new Suggestions
                {
                    _id = GetNextId("Suggestions"),
                    ProgramId = program._id,
                    SuggestedPrograms = new List<Programs>
                                        {
                                            candidate
                                        }
                });
            }
        }