Ejemplo n.º 1
0
        private MovieDto CheckPeopleAndStudios(MovieDto movieDto)
        {
            foreach (StudioDto studio in movieDto.Studios.Where(x => x.Id == 0))
            {
                int id = movieRepository.AddStudio(parser.ToStudio(studio));

                if (id > 0)
                {
                    studio.Id = id;
                }
                else
                {
                    Log.Warning("Unable to add studio!");
                }
            }

            List <PersonDto> addedPeople = new List <PersonDto>();

            foreach (PersonDto person in movieDto.Actors.Where(x => x.Id == 0))
            {
                int id = movieRepository.AddPerson(parser.ToPerson(person));

                if (id > 0)
                {
                    person.Id = id;
                    addedPeople.Add(person);
                }
                else
                {
                    Log.Warning("Unable to add actor!");
                }
            }

            foreach (PersonDto person in movieDto.Directors.Where(x => x.Id == 0))
            {
                PersonDto existingPerson = addedPeople.FirstOrDefault(x => x.UniqueAddId == person.UniqueAddId);
                if (existingPerson != null)
                {
                    person.Id = existingPerson.Id;
                }
                else
                {
                    int id = movieRepository.AddPerson(parser.ToPerson(person));

                    if (id > 0)
                    {
                        person.Id = id;
                    }
                    else
                    {
                        Log.Warning("Unable to add director!");
                    }
                }
            }

            return(movieDto);
        }