Пример #1
0
        private void InsertToDB()
        {
            try
            {
                db = new NewsDB(false);
                var fromDb = from n in db.News
                        from r in db.Region
                        select new
                        {
                            tytul = n.TitleOfNews,
                            linkacz = r.LinkToChannel
                        };

               foreach (var r in GetRegions())
                {
                    foreach (var n in r.News)
                    {
                            bool isInDatabase = false;
                            foreach (var fd in fromDb)
                            {
                                if (fd.linkacz == r.LinkToChannel && fd.tytul == n.TitleOfNews)
                                {
                                    isInDatabase = true;
                                }
                            }
                            if (!isInDatabase)
                            {
                                db.Region.Add(r);
                            }
                    }
                }
                db.SaveChanges();
            }
            catch (Exception)
            {
                try
                {
                    db = new NewsDB(true);
                    var fromDb = from n in db.News
                                 from r in db.Region
                                 select new
                                 {
                                     tytul = n.TitleOfNews,
                                     linkacz = r.LinkToChannel
                                 };
                    foreach (var r in GetRegions())
                    {
                        foreach (var n in r.News)
                        {
                            bool isInDatabase = false;
                            foreach (var fd in fromDb)
                            {
                                if (fd.linkacz == r.LinkToChannel && fd.tytul == n.TitleOfNews)
                                {
                                    isInDatabase = true;
                                }
                            }
                            if (!isInDatabase)
                            {
                                db.Region.Add(r);
                            }
                        }
                    }
                    db.SaveChanges();
                }
                catch (Exception)
                {
                }
            }
        }
Пример #2
0
        private void InsertToDB()
        {
            try
            {
                db = new NewsDB(false);
                var fromDb = from n in db.News
                             from r in db.Region
                             select new
                {
                    tytul   = n.TitleOfNews,
                    linkacz = r.LinkToChannel
                };

                foreach (var r in GetRegions())
                {
                    foreach (var n in r.News)
                    {
                        bool isInDatabase = false;
                        foreach (var fd in fromDb)
                        {
                            if (fd.linkacz == r.LinkToChannel && fd.tytul == n.TitleOfNews)
                            {
                                isInDatabase = true;
                            }
                        }
                        if (!isInDatabase)
                        {
                            db.Region.Add(r);
                        }
                    }
                }
                db.SaveChanges();
            }
            catch (Exception)
            {
                try
                {
                    db = new NewsDB(true);
                    var fromDb = from n in db.News
                                 from r in db.Region
                                 select new
                    {
                        tytul   = n.TitleOfNews,
                        linkacz = r.LinkToChannel
                    };
                    foreach (var r in GetRegions())
                    {
                        foreach (var n in r.News)
                        {
                            bool isInDatabase = false;
                            foreach (var fd in fromDb)
                            {
                                if (fd.linkacz == r.LinkToChannel && fd.tytul == n.TitleOfNews)
                                {
                                    isInDatabase = true;
                                }
                            }
                            if (!isInDatabase)
                            {
                                db.Region.Add(r);
                            }
                        }
                    }
                    db.SaveChanges();
                }
                catch (Exception)
                {
                }
            }
        }