private static async Task ConfigureProduct()
        {
            await ListProducts();

            Console.Write("Enter a product id: ");
            string id = Console.ReadLine();

            var product = await _store.Get <StorageProduct>(p => p.Id == ObjectId.Parse(id));

            if (product != null)
            {
                Console.Write("Enter Target Demographics: ");
                string demographics = Console.ReadLine();
                Console.Write("Enter Skus: ");
                string skus = Console.ReadLine();

                await _store.Update(f => f.Id == ObjectId.Parse(id),
                                    Builders <StorageProduct> .Update.Set(f => f.TargetDemographics, demographics.Split(','))
                                    .Set(f => f.Skus, skus.Split(',')));
            }
        }
        private static async Task ProductsOnMessageConsumed(Message <Null, Product> message)
        {
            var product =
                await _store.Get <StorageProduct>(p => p.MarketingId == ObjectId.Parse(message.Value.MarketingId));

            if (product == null)
            {
                await _store.Add(new StorageProduct
                {
                    MarketingId = ObjectId.Parse(message.Value.MarketingId),
                    Name        = message.Value.Name,
                    Description = message.Value.Description,
                    Skus        = message.Value.Skus
                });
            }
            else
            {
                await _store.Update(f => f.MarketingId == ObjectId.Parse(message.Value.MarketingId),
                                    Builders <StorageProduct> .Update
                                    .Set(f => f.Name, message.Value.Name)
                                    .Set(f => f.Description, message.Value.Description)
                                    .Set(f => f.Skus, message.Value.Skus));
            }
        }
Exemple #3
0
        private static async Task ProduceInventory()
        {
            await ListProducts();

            Console.Write("Enter Product to Produce: ");
            var productId = Console.ReadLine();

            var product = await _store.Get <StorageProduct>(p => p.Id == ObjectId.Parse(productId));

            Console.Write("How many to produce: ");
            string toProduce = Console.ReadLine();

            if (int.TryParse(toProduce, out int quantity))
            {
                await _store.Update(p => p.Id == ObjectId.Parse(productId),
                                    Builders <StorageProduct> .Update.Set(f => f.Available, quantity));

                await _publisher.Publish(new Stock
                {
                    Available   = quantity,
                    MarketingId = product.MarketingId.ToString()
                }, "manufacturing-stock");
            }
        }