Пример #1
0
        private static async Task ExecuteDemo()
        {
            var orderId = await CreateOrders();

            var storage = new OrdersStorage(ApiUrl, new ConsoleLoggerWriter());

            var mainOrder = await storage.GetOrderById(orderId);

            await mainOrder.AddOrderItem("Xiaomi Mi10", "Brand new chinese phone", 4);

            var iphoneItems = new List <IOrderItem>();

            Console.WriteLine("Orders in storage");
            foreach (var order in await storage.GetAllOrders())
            {
                Console.WriteLine($"Order with Id:{order.Id}");
                foreach (var orderItem in order.Items)
                {
                    PrintOrderItem(orderItem);
                    if (orderItem.Name.Contains("Iphone"))
                    {
                        iphoneItems.Add(orderItem);
                        continue;
                    }

                    if (orderItem.Name.Contains("Samsung"))
                    {
                        await orderItem.RemoveItem();
                    }
                }
            }

            foreach (var item in iphoneItems)
            {
                await item.ChangeQuantity(999);
            }

            Console.WriteLine("Orders after change");
            await PrintStorage(storage);

            Console.WriteLine("Purging all orders");
            foreach (var order in await storage.GetAllOrders())
            {
                await order.Purge();
            }

            await PrintStorage(storage);
        }
Пример #2
0
 private static async Task PrintStorage(OrdersStorage storage)
 {
     foreach (var order in await storage.GetAllOrders())
     {
         Console.WriteLine($"Order with Id:{order.Id}");
         foreach (var orderItem in order.Items)
         {
             PrintOrderItem(orderItem);
         }
     }
 }
Пример #3
0
 public IActionResult GetAllOrders()
 {
     return(Ok(_orders.GetAllOrders()));
 }