static EShop AddEShop(Database db) { var eShop = new EShop(); var events = eShop.InitShop("EShop"); Save(events, eShop, db); return(eShop); }
static void AddProduct(EShop eShop, Database db) { Console.WriteLine(". Add product"); var(product, qty) = GetProductQuantity(); var events = eShop.AddProductType(product, qty); Save(events, eShop, db); }
static void ReportLossOrDamage(EShop eShop, Database db) { Console.WriteLine(". Report loss or damage"); var(product, qty) = GetProductQuantity(); var events = eShop.ReportStockLossOrDamage(product, qty); Save(events, eShop, db); }
static void SellItems(EShop eShop, Database db) { Console.WriteLine(". Sell items"); var(product, qty) = GetProductQuantity(); var events = eShop.SellItems(product, qty); Save(events, eShop, db); }
static void RefillStock(EShop eShop, Database db) { Console.WriteLine(". Refill stock"); var(product, qty) = GetProductQuantity(); var events = eShop.RefillStock(product, qty); Save(events, eShop, db); }
static void Save(List <Event> events, EShop eShop, Database db) { eShop.Apply(events); events.ForEach(e => { try { var stored = StoredEvent.From(e, eShop.State.Name, eShop.State.Id); db.AddAsync(stored.Id.ToString(), stored).GetAwaiter().GetResult(); } catch (Exception ex) { Console.WriteLine(ex.Message + ex.StackTrace); Console.WriteLine("Press any key to terminate."); Console.ReadKey(); Environment.Exit(-1); } }); }
static void ShowCurrentState(EShop eShop) { Console.WriteLine(". Current state"); Console.WriteLine(eShop.State); }