Exemple #1
0
        private async Task AddCategoryToPerson(Serie serie)
        {
            foreach (var director in serie.Directors)
            {
                var directorDb = await _dbContext.People.Include(x => x.Categories).FirstOrDefaultAsync(x => x.Id == director.Id);

                if (!directorDb.Categories.Any(x => x.Id == 2))
                {
                    await _peopleService.AddCategoryToPersonAsync(directorDb, 2);
                }
            }

            foreach (var castId in serie.Casts.Select(x => x.PersonId))
            {
                var cast = await _dbContext.People.Include(x => x.Categories).FirstOrDefaultAsync(x => x.Id == castId);

                if (!cast.Categories.Any(x => x.Id == 1))
                {
                    await _peopleService.AddCategoryToPersonAsync(cast, 1);
                }
            }
        }