public void AddEarningAsync(decimal total)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var flag = 0;
                        var dailyEarning = context.DailyEarnings.FirstOrDefault(x => x.Date == DateTime.Today);

                        if (dailyEarning == null)
                        {
                            flag = 1;
                            dailyEarning = new DailyEarning {Date = DateTime.Today};
                        }

                        dailyEarning.Earnings += total;

                        if (flag == 1)
                        {
                            context.DailyEarnings.Add(dailyEarning);
                        }

                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
        public void AddBarcodeAsync(Product originalProduct, Barcode barcode)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var product = context.Products.FirstOrDefault(x => x.ID == originalProduct.ID);

                        product.Barcodes.Add(barcode);
                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
        public void UpdateProductAsync(Product originalProduct, double quantity = 0)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var product = context.Products.FirstOrDefault(x => x.ID == originalProduct.ID);

                        product.Name = originalProduct.Name;
                        product.BuyingPrice = originalProduct.BuyingPrice;
                        product.SellingPrice = originalProduct.SellingPrice;
                        product.Measure = originalProduct.Measure;
                        product.Quantity += quantity;

                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
        public void DeleteProductAsync(Product originalProduct)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (s, e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var product = context.Products.FirstOrDefault(x => x.ID == originalProduct.ID);

                        var barcodes = product.Barcodes.ToList();
                        foreach (var barcode in barcodes)
                        {
                            context.Barcodes.Remove(barcode);
                        }

                        var shipments = product.Shipments.ToList();
                        foreach (var shipment in shipments)
                        {
                            context.Shipments.Remove(shipment);
                        }

                        var expirationDates = product.ExpirationDates.ToList();
                        foreach (var date in expirationDates)
                        {
                            context.ExpirationDates.Remove(date);
                        }

                        context.Products.Remove(product);
                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
        public void AddWasteToSellerAsync(Seller originalSeller, Waste waste)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var seller = context.Sellers.Find(originalSeller.ID);
                        seller.Wastes.Add(waste);
                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
        public void AddShipmentAsync(Product product, double quantity)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var shipment = new Shipment();
                        shipment.Quantity = quantity;
                        shipment.Date = DateTime.Today;
                        shipment.ProductID = product.ID;

                        var existingShipment =
                            context.Shipments.FirstOrDefault(
                                x => x.ProductID == shipment.ProductID && x.Date.CompareTo(DateTime.Today) == 0);
                        if (existingShipment == null)
                        {
                            context.Shipments.Add(shipment);
                        }
                        else
                        {
                            existingShipment.Quantity += shipment.Quantity;
                        }

                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
        public void AddProductAsync(Product originalProduct)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        context.Products.Add(originalProduct);
                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
 public void AddNotFoundProduct(NotFoundProduct product)
 {
     using (var context = new EugenieEntities(connectionStringAsString))
     {
         context.NotFoundProducts.Add(product);
         context.SaveChanges();
     }
 }