Ejemplo n.º 1
0
 public void SaveSitemaps(List <SitemapEntry> sitemapEntries)
 {
     foreach (var sitemapEntry in sitemapEntries)
     {
         var existingSitemapEntry =
             _grabberContext.SitemapEntries.FirstOrDefault(
                 se => se.Loc == sitemapEntry.Loc && se.SourceType == sitemapEntry.SourceType);
         if (existingSitemapEntry == null)
         {
             _grabberContext.Add(sitemapEntry);
         }
         else
         {
             existingSitemapEntry.Lastmod = sitemapEntry.Lastmod;
         }
         _grabberContext.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public void SaveJobResult(AdJobResult jobResult)
        {
            _grabberContext.AdDownloadJobs.First(adj => adj.Id == jobResult.DownloadJob.Id).ProcessedAt = DateTime.Now;
            _grabberContext.SaveChanges();
            Entry entry;

            try
            {
                entry = _znakerContext.Entries.First(
                    e => e.IdOnSource == jobResult.DownloadJob.AdId && e.SourceId == jobResult.DownloadJob.SourceType);
            }
            catch (InvalidOperationException)
            {
                entry = new Entry
                {
                    Text       = jobResult.Text,
                    SourceId   = jobResult.DownloadJob.SourceType,
                    CreatedOn  = DateTime.Now,
                    IdOnSource = jobResult.DownloadJob.AdId
                };
                _znakerContext.Add(entry);
            }
            if (jobResult.Contacts == null || jobResult.Contacts.Count == 0)
            {
                _znakerContext.SaveChanges();
                return;
            }
            var contacts = jobResult.Contacts.Select(k =>
            {
                var contact =
                    _znakerContext.Contacts.FirstOrDefault(c => c.ContactType == k.Key && c.Identity == k.Value);
                if (null != contact)
                {
                    contact.UpdatedOn = DateTime.Now;
                    return(contact);
                }
                contact = new Contact
                {
                    ContactType = k.Key,
                    Identity    = k.Value,
                    CreatedOn   = DateTime.Now,
                    UpdatedOn   = DateTime.Now
                };
                _znakerContext.Contacts.Add(contact);
                return(contact);
            }).ToList();
            var entryContacts = contacts.Select(c => new EntryContact
            {
                Contact = c,
                Entry   = entry
            }).ToList();

            _znakerContext.AddRange(entryContacts);
            _znakerContext.SaveChanges();
        }