Ejemplo n.º 1
0
        static void DeleteDups()
        {
            MovieEntities    db     = new MovieEntities();
            HashSet <string> movies = new HashSet <string>();
            var dups = db.Movies.GroupBy(i => i.ImdbID).Where(x => x.Count() > 1).Distinct();

            foreach (var movie in db.Movies)
            {
                var test = db.Movies.Where(p => p.Title == "Peter Pan");
                var q    = test.ToList();
                if (q.Count > 1)
                {
                    //var delete =
                    for (int k = 1; k < q.Count(); k++)
                    {
                        try
                        {
                            var  movies1 = q.ToList();
                            long tempid  = movies1.ElementAt(k).ID;
                            //// TODO: This query is to find the valid record which should not be deleted inside the posterinfo class
                            var validPosterInfo = (from h in db.PosterInfoes
                                                   where h.MovieId == tempid
                                                   select h).ToList();
                            if (validPosterInfo.Count() == 0)
                            {
                                db.Movies.Remove(q.ElementAt(k));
                                db.SaveChanges();
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                }
            }

            foreach (var item in movies)
            {
                var m = db.Movies.Where(s => s.ImdbID == item);
                db.Movies.Remove(m.First());
                db.SaveChanges();
            }
            Console.WriteLine(movies.Count());
        }
Ejemplo n.º 2
0
        static void ConvertToBase64Image()
        {
            MovieEntities db = new MovieEntities();

            foreach (PosterInfo poster in db.PosterInfoes)
            {
                if (poster.Imdb != null && !string.IsNullOrWhiteSpace(poster.Imdb))
                {
                    string base64 = ImageToByteArray(poster.Imdb);
                    poster.LocalPath = base64;
                    db.SaveChanges();
                }
            }
        }