Exemplo n.º 1
0
 public static Purchase Build(StoreDB db, string[] barcodes)
 {
     return new Purchase() {
         Products = Product.FindByBarcodes(db, barcodes),
         Discounts = Discount.FindByBarcodes(db, barcodes)
     };
 }
Exemplo n.º 2
0
 public static void CreateOrUpdate(StoreDB db, string barcode, float amount)
 {
     Product product = Product.FindByBarcode(db, barcode);
     Discount existing = db.Discounts.Where(p => p.Product.Id == product.Id).FirstOrDefault();
     if (existing == null)
         db.Discounts.Add(new Discount() { Product = product, Amount = amount });
     else
         existing.Amount = amount;
 }
Exemplo n.º 3
0
 public static void CreateOrUpdate(StoreDB db, string barcode, string name, float price)
 {
     Product existing = db.Products.Where(p => p.Barcode == barcode).FirstOrDefault();
     if (existing == null)
         db.Products.Add(new Product() { Barcode = barcode, Name = name, Price = price });
     else
     {
         existing.Name = name;
         existing.Price = price;
     }
 }
Exemplo n.º 4
0
 public Store()
 {
     db = new StoreDB();
 }
Exemplo n.º 5
0
 public static Discount[] FindByBarcodes(StoreDB db, string[] barcodes)
 {
     return barcodes.Select(x => FindByBarcode(db, x)).Where(x => x != null).ToArray();
 }
Exemplo n.º 6
0
 public static Discount FindByBarcode(StoreDB db, string barcode)
 {
     return db.Discounts.Where(p => p.Product.Barcode == barcode).FirstOrDefault();
 }
Exemplo n.º 7
0
 public static Product[] FindByBarcodes(StoreDB db, string[] barcodes)
 {
     return barcodes.Select(b => FindByBarcode(db, b)).ToArray();
 }