Example #1
0
        static EShop AddEShop(Database db)
        {
            var eShop  = new EShop();
            var events = eShop.InitShop("EShop");

            Save(events, eShop, db);
            return(eShop);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
 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);
         }
     });
 }
Example #7
0
 static void ShowCurrentState(EShop eShop)
 {
     Console.WriteLine(". Current state");
     Console.WriteLine(eShop.State);
 }