public static void SetAvailableToFalse() { using (ScraperDbContext context = new ScraperDbContext()) { context.Database.ExecuteSqlCommand("UPDATE [Laptops] SET IsAvailable = 0"); } }
public static void SeedHostDb(ScraperDbContext context) { context.SuppressAutoSetTenantId = true; // Host seed new InitialHostDbBuilder(context).Create(); // Default tenant seed (in host database). new DefaultTenantBuilder(context).Create(); new TenantRoleAndUserBuilder(context, 1).Create(); }
public static void SetAvailableToTrue(string name) { using (ScraperDbContext context = new ScraperDbContext()) { var laptops = context.Laptops.Where(n => n.ProductName == name).ToList(); foreach (var entity in laptops) { entity.IsAvailable = true; } context.SaveChanges(); } }
public static void UpdateLowestPrice(string name) { using (ScraperDbContext context = new ScraperDbContext()) { var laptops = context.Laptops.Where(n => n.ProductName == name).ToList(); foreach (var entity in laptops) { entity.LowestPrice = context.Laptops.Where(n => n.ProductName == name).Min(p => p.ProductPrice); } context.SaveChanges(); } }
public static void UpdateAvgPrice(string name) { using (var context = new ScraperDbContext()) { var laptops = context.Laptops.Where(n => n.ProductName == name).ToList(); foreach (var entity in laptops) { entity.AveragePrice = Math.Round(context.Laptops.Where(n => n.ProductName == name).Average(p => p.ProductPrice), 2); } context.SaveChanges(); } }
public Scraper(ScraperDbContext context, IOptions <List <TemplateBusca> > templates, IBusca roupa, IScraperFactory scraperRepository, ILogger <Scraper> logger ) { _context = context; _templates = templates; _roupa = roupa; _logger = logger; _scraperRepository = scraperRepository; //_scraperDistritoModas = scraperPostHaus; }
public GoodsController(ILogger <GoodsController> logger, ScraperDbContext dbContext) { _logger = logger; this._dbContext = dbContext; }
public Busca(ScraperDbContext context, ILogger <Busca> logger) { _context = context; _logger = logger; }
public DefaultEditionCreator(ScraperDbContext context) { _context = context; }
public InitialHostDbBuilder(ScraperDbContext context) { _context = context; }
public TenantRoleAndUserBuilder(ScraperDbContext context, int tenantId) { _context = context; _tenantId = tenantId; }
public HostRoleAndUserCreator(ScraperDbContext context) { _context = context; }
public DefaultSettingsCreator(ScraperDbContext context) { _context = context; }
public DefaultTenantBuilder(ScraperDbContext context) { _context = context; }
public static void AddingProduct(IEnumerable <string> categoryLink) { Console.WriteLine("Checking for price/product changes"); Stopwatch addingLaptopStopwatch = new Stopwatch(); addingLaptopStopwatch.Start(); foreach (var line in categoryLink) { int pageNumber = 1; int productListCount = 1; while (productListCount != 0) { var url = "https://www.1a.lv" + line + "/" + pageNumber; Console.WriteLine(url); WebClient client = new WebClient(); string html = client.DownloadString(url); var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html); var productListItems = ProductListHtml(htmlDocument); for (int i = 0; i < productListItems.Count; i++) { using (var context = new ScraperDbContext()) { var laptop = new Laptop(); var productName = ProductName(productListItems[i]); var productPrice = ProductPrice(htmlDocument, i); laptop.AddingDate = DateTime.Now; var checkNameExist = context.Laptops.Where(name => name.ProductName == productName).ToList(); if (!checkNameExist.Any()) { laptop.ProductName = productName; laptop.ProductPrice = productPrice; laptop.Category = line.Split('/').Last(); context.Laptops.Add(laptop); context.SaveChanges(); ProductServices.UpdatePriceChanges(productName); ProductServices.UpdateAvgPrice(productName); ProductServices.UpdateLowestPrice(productName); ProductServices.UpdateHighestPrice(productName); ProductServices.SetAvailableToTrue(productName); } else { var checkPriceExist = context.Laptops.FirstOrDefault(name => name.ProductName == productName && name.ProductPrice == productPrice); if (checkPriceExist == null) { laptop.ProductName = productName; laptop.ProductPrice = productPrice; laptop.Category = line.Split('/').Last(); context.Laptops.Add(laptop); context.SaveChanges(); ProductServices.UpdatePriceChanges(productName); ProductServices.UpdateAvgPrice(productName); ProductServices.UpdateLowestPrice(productName); ProductServices.UpdateHighestPrice(productName); } ProductServices.SetAvailableToTrue(productName); } } } productListCount = productListItems.Count(); pageNumber++; } } addingLaptopStopwatch.Stop(); Console.WriteLine("Time for the htmlService to finish checking prices is " + (addingLaptopStopwatch.ElapsedMilliseconds / 60000).ToString() + " minutes and " + ((addingLaptopStopwatch.ElapsedMilliseconds % 60000) / 1000).ToString() + " seconds"); }
public DefaultLanguagesCreator(ScraperDbContext context) { _context = context; }
public DefaultController(ScraperDbContext dbContext) { this.dbContext = dbContext; }