public static void SetAvailableToFalse()
 {
     using (ScraperDbContext context = new ScraperDbContext())
     {
         context.Database.ExecuteSqlCommand("UPDATE [Laptops] SET IsAvailable = 0");
     }
 }
示例#2
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();
            }
        }
示例#6
0
        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;
        }
示例#7
0
 public GoodsController(ILogger <GoodsController> logger, ScraperDbContext dbContext)
 {
     _logger         = logger;
     this._dbContext = dbContext;
 }
示例#8
0
 public Busca(ScraperDbContext context,
              ILogger <Busca> logger)
 {
     _context = context;
     _logger  = logger;
 }
示例#9
0
 public DefaultEditionCreator(ScraperDbContext context)
 {
     _context = context;
 }
示例#10
0
 public InitialHostDbBuilder(ScraperDbContext context)
 {
     _context = context;
 }
示例#11
0
 public TenantRoleAndUserBuilder(ScraperDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
 public HostRoleAndUserCreator(ScraperDbContext context)
 {
     _context = context;
 }
示例#13
0
 public DefaultSettingsCreator(ScraperDbContext context)
 {
     _context = context;
 }
示例#14
0
 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");
        }
示例#16
0
 public DefaultLanguagesCreator(ScraperDbContext context)
 {
     _context = context;
 }
示例#17
0
 public DefaultController(ScraperDbContext dbContext)
 {
     this.dbContext = dbContext;
 }