Example #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("press enter to start");
            _ = Console.ReadLine();

            var ordersApi = new OrdersApi(_httpClient, _config, _secrets);

            var orders = await ordersApi.GetInProgressOrdersAsync().ConfigureAwait(false);

            Console.WriteLine($"Fetched {orders.Content.Count} orders that are in progress.");

            Console.WriteLine("Calculation top 5 products sold");

            var orderBll = new OrdersBll();

            var topFiveSold = orderBll
                              .OrderProductsByQuantity(orders)
                              .Take(5)
                              .ToList();

            Console.WriteLine("Getting product names...");

            var productsAPi = new ProductsApi(_httpClient, _config, _secrets);

            foreach (var(MerchantProductNo, Gtin, Sold) in topFiveSold)
            {
                var product = (await productsAPi.GetProductAsync(MerchantProductNo !).ConfigureAwait(false)).Content.First();
                Console.WriteLine($"Sold: {Sold}, No: {MerchantProductNo}, Gtin: {Gtin}, Stock: {product.Stock}, Name: {product.Name}");
            }

            Console.WriteLine("Updating random product stock to 25...");

            var randomProductIndexToUpdate = _random.Next(0, topFiveSold.Count);
            var randomProduct = topFiveSold.ElementAt(randomProductIndexToUpdate);

            var success = await productsAPi.UpdateProductStockQuantityAsync(randomProduct.MerchantProductNo !, 25);

            Console.WriteLine($"Success: {success}");
            Console.WriteLine("Press enter to close");
            _ = Console.ReadLine();
        }