Пример #1
0
 public static void AddItems(IEnumerable <Item> cars)
 {
     try
     {
         using (var db = new AvitoContext())
         {
             db.Items.AddRange(cars);
             var count = db.SaveChanges();
             Logger.Info($"{count} records saved to database");
         }
     }
     catch (Exception e)
     {
         Logger.Error(e, "Add Items to DB FAILD");
     }
 }
Пример #2
0
        private IEnumerable <Item> FilterItems(IEnumerable <Item> items)
        {
            var listItems = new List <Item>();

            using (var db = new AvitoContext())
            {
                try
                {
                    listItems.AddRange(items.Where(item => db.Items.FirstOrDefault(i => i.Link == item.Link) == null));
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Error add range");
                }
            }
            return(listItems);
        }