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"); } }
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); }