Пример #1
0
 protected override Role UpdateEntity(MovieDbContext entityContext, Role entity)
 {
     return((from e in entityContext.RoleSet
             where e.Id == entity.Id
             select e).FirstOrDefault());
 }
Пример #2
0
 protected override State AddEntity(MovieDbContext entityContext, State entity)
 {
     return(entityContext.StateSet.Add(entity));
 }
Пример #3
0
 protected override State GetEntity(MovieDbContext entityContext, int id)
 {
     return((from s in entityContext.StateSet where s.Id == id select s).FirstOrDefault());
 }
Пример #4
0
 protected override Country AddEntity(MovieDbContext entityContext, Country entity)
 {
     return(entityContext.CountrySet.Add(entity));
 }
Пример #5
0
 protected override Country GetEntity(MovieDbContext entityContext, int id)
 {
     return((from c in entityContext.CountrySet where c.Id == id select c).FirstOrDefault());
 }
Пример #6
0
 protected override IEnumerable <User> GetEntities(MovieDbContext entityContext)
 {
     return(entityContext.UserSet.ToList());
 }
Пример #7
0
 protected override Comment UpdateEntity(MovieDbContext entityContext, Comment entity)
 {
     return((from e in entityContext.CommentSet
             where e.Id == entity.Id
             select e).FirstOrDefault());
 }
Пример #8
0
 protected override PollVotingRecord UpdateEntity(MovieDbContext entityContext, PollVotingRecord entity)
 {
     return((from en in entityContext.PollVotingRecordSet where en.Id == entity.Id select en).FirstOrDefault());
 }
Пример #9
0
 protected override PollVotingRecord GetEntity(MovieDbContext entityContext, int id)
 {
     return((from en in entityContext.PollVotingRecordSet where en.Id == id select en).FirstOrDefault());
 }
Пример #10
0
 protected override IEnumerable <Review> GetEntities(MovieDbContext entityContext)
 {
     return(entityContext.ReviewSet.ToList());
 }
Пример #11
0
 protected override PollVotingRecord AddEntity(MovieDbContext entityContext, PollVotingRecord entity)
 {
     return(entityContext.PollVotingRecordSet.Add(entity));
 }
Пример #12
0
 protected override Review GetEntity(MovieDbContext entityContext, int id)
 {
     return((from en in entityContext.ReviewSet where en.Id == id select en).FirstOrDefault());
 }
Пример #13
0
 protected override Review UpdateEntity(MovieDbContext entityContext, Review entity)
 {
     return((from en in entityContext.ReviewSet where en.Id == entity.Id select en).FirstOrDefault());
 }
Пример #14
0
 protected override Review AddEntity(MovieDbContext entityContext, Review entity)
 {
     return(entityContext.ReviewSet.Add(entity));
 }
Пример #15
0
        public static void SeedActorsTop1000()
        {
            var actors = XDocument.Load(@"C:\seed\New_\active.xml");

            var actorsName      = actors.Elements("Top1000").Elements("Actor").Elements("Name").Select(t => t.Value).ToList();
            var actorsConst     = actors.Elements("Top1000").Elements("Actor").Elements("Const").Select(t => t.Value).ToList();
            var actorsKnownFor  = actors.Elements("Top1000").Elements("Actor").Elements("KnownFor").Select(t => t.Value).ToList();
            var actorsIsMale    = actors.Elements("Top1000").Elements("Actor").Elements("IsMale").Select(t => t.Value).ToList();
            var actorsBirthDate = actors.Elements("Top1000").Elements("Actor").Elements("Birth").Select(t => t.Value).ToList();
            var forCount        = actorsName.Count;

            var list = new List <string>();
            var firstLastNameSeperated = new List <Seeder.FirstLastName>();

            foreach (var actorFullName in actorsName)
            {
                var splitted = actorFullName.Split(' ');
                switch (splitted.Count())
                {
                case 1:
                    list.Add(actorFullName);
                    break;

                case 2:
                    firstLastNameSeperated.Add(new Seeder.FirstLastName()
                    {
                        First = splitted[0], Last = splitted[1]
                    });
                    break;

                case 3:
                    firstLastNameSeperated.Add(new Seeder.FirstLastName()
                    {
                        First = splitted[0], Last = splitted[1] + " " + splitted[2]
                    });
                    break;

                case 4:
                    firstLastNameSeperated.Add(new Seeder.FirstLastName()
                    {
                        First = splitted[0], Last = splitted[1] + " " + splitted[2] + " " + splitted[3]
                    });
                    break;
                }
            }

            var birthdateFinal = new List <DateTime>();

            foreach (var year in actorsBirthDate)
            {
                DateTime dateOut;
                DateTime.TryParse(year, out dateOut);
                var dateFinal = dateOut.ToShortDateString();

                birthdateFinal.Add(dateOut);
            }

            using (var context = new MovieDbContext())
            {
                for (int i = 0; i < forCount; i++)
                {
                    var   actorKnownForMovieId = actorsKnownFor[i];
                    Movie isThereAmovie        = context.MovieSet.FirstOrDefault(t => t.ImdbLink == actorKnownForMovieId);

                    if (isThereAmovie != null) // Film var mı? : Film var.
                    {
                        // Peki aktör var mı?
                        string actorName      = actorsName[i];
                        Actor  isThereAnActor = context.ActorSet.FirstOrDefault(t => t.FullName == actorName);

                        if (isThereAnActor == null) // böyle bir aktör yok (map da olamaz). ama bu aktörün (known for) movie'si var.
                        {
                            var actorToDb = new Actor()
                            {
                                Biography = "",
                                BirthDate = birthdateFinal[i],
                                CreatedAt = isThereAmovie.CreatedAt,
                                DeathDate = null,
                                FirstName = firstLastNameSeperated[i].First,
                                LastName  = firstLastNameSeperated[i].Last,
                                FullName  = actorsName[i],
                                Gender    = Convert.ToBoolean(actorsIsMale[i]),
                                CountryId = 1,
                                CountyId  = 1,
                                StateId   = 1,
                                ImdbLink  = actorsConst[i],
                                Photo     = "null"
                            };
                            context.ActorSet.Add(actorToDb);
                            context.SaveChanges();

                            context.MovieActorMappingSet.Add(new MovieActorMapping()
                            {
                                MovieId = isThereAmovie.Id,
                                ActorId = actorToDb.Id
                            });
                            context.SaveChanges();
                        }
                        else
                        {
                            // böyle bir aktör var. Film de vardı. O zaman map yapma zamanı.
                            // Tabii hali hazırda map yoksa...

                            // önce gender ayarı


                            MovieActorMapping mp = context.MovieActorMappingSet
                                                   .FirstOrDefault(t => t.MovieId == isThereAmovie.Id && t.ActorId == isThereAnActor.Id);

                            if (mp == null) // map yok
                            {
                                context.MovieActorMappingSet.Add(new MovieActorMapping()
                                {
                                    MovieId = isThereAmovie.Id,
                                    ActorId = isThereAnActor.Id
                                });
                                context.SaveChanges();
                            }
                        }
                    }
                    else
                    {
                        // Actor için KnownFor FİLM YOK. Peki böyle bir Actor var mı?
                        string actorName      = actorsName[i];
                        Actor  isThereAnActor = context.ActorSet.FirstOrDefault(t => t.FullName == actorName);

                        if (isThereAnActor == null) // böyle bir aktör de YOK: ekle o zaman.
                        {
                            var actorToDb = new Actor()
                            {
                                Biography = "",
                                BirthDate = birthdateFinal[i],
                                CreatedAt = DateTime.Now,
                                DeathDate = null,
                                FirstName = firstLastNameSeperated[i].First,
                                LastName  = firstLastNameSeperated[i].Last,
                                FullName  = actorsName[i],
                                Gender    = Convert.ToBoolean(actorsIsMale[i]),
                                CountryId = 1,
                                CountyId  = 1,
                                StateId   = 1,
                                ImdbLink  = actorsConst[i],
                                Photo     = "null"
                            };
                            context.ActorSet.Add(actorToDb);
                            context.SaveChanges();
                        }
                    }
                }
            }
        }
Пример #16
0
 protected override IEnumerable <PollVotingRecord> GetEntities(MovieDbContext entityContext)
 {
     return(entityContext.PollVotingRecordSet.ToList());
 }
Пример #17
0
 protected override User AddEntity(MovieDbContext entityContext, User entity)
 {
     return(entityContext.UserSet.Add(entity));
 }
 protected override BlogPostComment AddEntity(MovieDbContext entityContext, BlogPostComment entity)
 {
     return(entityContext.BlogPostCommentSet.Add(entity));
 }
Пример #19
0
 protected override Comment AddEntity(MovieDbContext entityContext, Comment entity)
 {
     return(entityContext.CommentSet.Add(entity));
 }
 protected override BlogPostComment GetEntity(MovieDbContext entityContext, int id)
 {
     return((from en in entityContext.BlogPostCommentSet where en.Id == id select en).FirstOrDefault());
 }
Пример #21
0
 protected override Comment GetEntity(MovieDbContext entityContext, int id)
 {
     return((from e in entityContext.CommentSet
             where e.Id == id
             select e).FirstOrDefault());
 }
 protected override IEnumerable <BlogPostComment> GetEntities(MovieDbContext entityContext)
 {
     return(entityContext.BlogPostCommentSet.ToList());
 }
Пример #23
0
 protected override Country UpdateEntity(MovieDbContext entityContext, Country entity)
 {
     return((from c in entityContext.CountrySet where c.Id == entity.Id select c).FirstOrDefault());
 }
Пример #24
0
 protected override News AddEntity(MovieDbContext entityContext, News entity)
 {
     return(entityContext.NewsSet.Add(entity));
 }
Пример #25
0
 protected override IEnumerable <Country> GetEntities(MovieDbContext entityContext)
 {
     return(entityContext.CountrySet.ToList());
 }
Пример #26
0
 protected override News UpdateEntity(MovieDbContext entityContext, News entity)
 {
     return((from e in entityContext.NewsSet
             where e.Id == entity.Id
             select e).FirstOrDefault());
 }
Пример #27
0
 protected override State UpdateEntity(MovieDbContext entityContext, State entity)
 {
     return((from s in entityContext.StateSet where s.Id == entity.Id select s).FirstOrDefault());
 }
Пример #28
0
 protected override Director AddEntity(MovieDbContext entityContext, Director entity)
 {
     entity.CreatedAt = DateTime.Now;
     return(entityContext.DirectorSet.Add(entity));
 }
Пример #29
0
 protected override IEnumerable <State> GetEntities(MovieDbContext entityContext)
 {
     return(entityContext.StateSet.ToList());
 }
Пример #30
0
 protected override Role AddEntity(MovieDbContext entityContext, Role entity)
 {
     return(entityContext.RoleSet.Add(entity));
 }