Ejemplo n.º 1
0
 private void nonWebBtn_Click(object sender, EventArgs e)
 {
     using (var db = new ComparerModel())
     {
         var productA = new Product() { Id = 1, Name = "pienas", Price = 1.02f, Date = DateTime.Now, Accept = false };
         var productB = new Product() { Id = 2, Name = "suris", Price = 2.54f, Date = DateTime.Now, Accept = false };
         db.Products.Add(productA);
         db.Products.Add(productB);
         db.SaveChanges();
     }
 }
        public List <RecentProduct> PickRecentChanges(int amount)
        {
            using (var db = new ComparerModel())
            {
                var wholeList  = db.Price.ToList();
                var recentList = wholeList.OrderByDescending(x => x.DateT);
                var productsWithRecentDifference = new List <RecentProduct>();

                int i = 0;
                int pickedProducts = 0;
                var temp           = new RecentProduct();
                foreach (var product in recentList)
                {
                    if (pickedProducts == amount)
                    {
                        break;
                    }
                    temp = new RecentProduct()
                    {
                        name        = product.ProductID,
                        shopName    = product.ShopID,
                        recentDate  = product.DateT,
                        recentPrice = product.PriceD
                    };
                    i++;
                    foreach (var product2 in recentList.Skip(i))
                    {
                        if (product.ProductID == product2.ProductID && product.ShopID == product2.ShopID && product.PriceD != product2.PriceD)
                        {
                            temp.beforeDate  = product2.DateT;
                            temp.beforePrice = product2.PriceD;
                            productsWithRecentDifference.Add(temp);
                            pickedProducts++;
                            break;
                        }
                    }
                }
                return(productsWithRecentDifference);
            }
        }