Exemple #1
0
        static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddOperations(typeof(Restaurant).Assembly);
            var serviceProvider = serviceCollection.BuildServiceProvider();

            var exprRestaurant01 =
                from restaurantResult in RestaurantDomain.CreateRestaurant("McDonalds", "Piata Victoriei")
                let restaurant = (restaurantResult as RestaurantCreated)?.Restaurant
                                 from MenuResult1 in RestaurantDomain.CreateMenu(restaurant, "Burgers")
                                 let Menu1 = (MenuResult1 as MenuCreated)?.Menu
                                             from newMenu1Item01 in RestaurantDomain.CreateMenuItem(Menu1, "McChicken", 5.00, 100, "list of ingredients", "list of allergens", MenuItemState.Available)
                                             from newMenu1Item02 in RestaurantDomain.CreateMenuItem(Menu1, "BigMac", 10.00, 100, "list of ingredients", "list of allergens", MenuItemState.Available)
                                             from newMenu1Item03 in RestaurantDomain.CreateMenuItem(Menu1, "Cheeseburger", 5.50, 100, "list of ingredients", "list of allergens", MenuItemState.Available)
                                             from MenuResult2 in RestaurantDomain.CreateMenu(restaurant, "Beverages")
                                             let Menu2 = (MenuResult2 as MenuCreated)?.Menu
                                                         from newMenu2Item01 in RestaurantDomain.CreateMenuItem(Menu2, "Coca-Cola", 5.00, 100, "list of ingredients", "list of allergens", MenuItemState.Available)
                                                         from newMenu2Item02 in RestaurantDomain.CreateMenuItem(Menu2, "Sprite", 5.00, 100, "list of ingredients", "list of allergens", MenuItemState.Available)
                                                         from newMenu2Item03 in RestaurantDomain.CreateMenuItem(Menu2, "Apple Juice", 7.00, 100, "list of ingredients", "list of allergens", MenuItemState.Available)
                                                         from Employee01 in RestaurantDomain.CreateEmployee("Waiter", "01", "*****@*****.**", "07xxxxxxxx", "waiter01", restaurant)
                                                         from Employee02 in RestaurantDomain.CreateEmployee("Chef", "01", "*****@*****.**", "07xxxxxxxx", "chef01", restaurant)
                                                         select restaurantResult;

            var exprRestaurant02 =
                from restaurantResult in RestaurantDomain.CreateRestaurant("3F", "Piata Victoriei")
                let restaurant = (restaurantResult as RestaurantCreated)?.Restaurant
                                 from MenuResult1 in RestaurantDomain.CreateMenu(restaurant, "Soups")
                                 let Menu1 = (MenuResult1 as MenuCreated)?.Menu
                                             from newMenu1Item01 in RestaurantDomain.CreateMenuItem(Menu1, "Chicken Soup", 12.00, 150, "list of ingredients", "list of allergens", MenuItemState.Available)
                                             from newMenu1Item02 in RestaurantDomain.CreateMenuItem(Menu1, "Beef Soup", 10.00, 100, "list of ingredients", "list of allergens", MenuItemState.Available)
                                             from MenuResult2 in RestaurantDomain.CreateMenu(restaurant, "Beverages")
                                             let Menu2 = (MenuResult2 as MenuCreated)?.Menu
                                                         from newMenu2Item01 in RestaurantDomain.CreateMenuItem(Menu2, "Coca-Cola", 5.00, 300, "list of ingredients", "list of allergens", MenuItemState.Available)
                                                         from newMenu2Item02 in RestaurantDomain.CreateMenuItem(Menu2, "Sprite", 5.00, 200, "list of ingredients", "list of allergens", MenuItemState.Available)
                                                         from newMenu2Item03 in RestaurantDomain.CreateMenuItem(Menu2, "Pepsi", 5.00, 200, "list of ingredients", "list of allergens", MenuItemState.Available)
                                                         from Employee01 in RestaurantDomain.CreateEmployee("Waiter", "01", "*****@*****.**", "07xxxxxxxx", "waiter01", restaurant)
                                                         from Employee02 in RestaurantDomain.CreateEmployee("Chef", "01", "*****@*****.**", "07xxxxxxxx", "chef01", restaurant)
                                                         select restaurantResult;

            var exprClient01 =
                from clientResult in RestaurantDomain.CreateClient("First", "Client", "*****@*****.**", "07xxxxxxxx", "xxxx xxxx xxxx xxxx", "client01")
                let client = (clientResult as ClientCreated)?.Client
                             select clientResult;

            var exprClient02 =
                from clientResult in RestaurantDomain.CreateClient("Second", "Client", "*****@*****.**", "07xxxxxxxx", "xxxx xxxx xxxx xxxx", "client02")
                let client = (clientResult as ClientCreated)?.Client
                             select clientResult;

            var interpreter = new LiveInterpreterAsync(serviceProvider);

            var resultRestaurant01 = await interpreter.Interpret(exprRestaurant01, Unit.Default);

            var finalResultRestaurant01 = resultRestaurant01.Match(OnRestaurantCreated, OnRestaurantNotCreated);

            Assert.True(finalResultRestaurant01);

            var resultRestaurant02 = await interpreter.Interpret(exprRestaurant02, Unit.Default);

            var finalResultRestaurant02 = resultRestaurant02.Match(OnRestaurantCreated, OnRestaurantNotCreated);

            Assert.True(finalResultRestaurant02);

            /*var resultClient01 = await interpreter.Interpret(exprClient01, Unit.Default);
             * var finalResultClient01 = resultClient01.Match<bool>(OnClientCreated, OnClientNotCreated);
             * Assert.True(finalResultClient01);
             *
             * var resultClient02 = await interpreter.Interpret(exprClient02, Unit.Default);
             * var finalResultClient02 = resultClient02.Match<bool>(OnClientCreated, OnClientNotCreated);
             * Assert.True(finalResultClient02);*/


            //MENU
            Console.WriteLine("Welcome to Order And Pay");
            Console.WriteLine("Please choose one from the following commands:");
            Console.WriteLine("1. Show restaurant");
            //Console.WriteLine("2. Get menus");
            //Console.WriteLine("3. Add to cart");
            Console.WriteLine("0. Exit");

            int k;

            while ((k = Console.Read()) != 0)
            {
                switch (k)
                {
                case 49:
                {
                    foreach (var r in Storage.RestaurantsList)
                    {
                        Console.WriteLine(r.Name);
                    }
                    break;
                }

                case 48:
                    return;
                    //   Console.WriteLine("Command does not exists!");
                    //return;
                }
            }
        }
        static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddOperations(typeof(Restaurant).Assembly);
            serviceCollection.AddOperations(typeof(User).Assembly);
            var serviceProvider = serviceCollection.BuildServiceProvider();

            var expr =
                from restaurantResult in RestaurantDomain.CreateRestaurant("mcdonalds")
                let restaurant = (restaurantResult as RestaurantCreated)?.Restaurant
                                 from newMenu in RestaurantDomain.CreateMenu(restaurant, "burgers", MenuType.Meat)
                                 select restaurantResult;

            var interpreter = new LiveInterpreterAsync(serviceProvider);

            var result = await interpreter.Interpret(expr, Unit.Default);

            var finalResult = result.Match(OnRestaurantCreated, OnRestaurantNotCreated);

            Assert.True(finalResult);


            // User expression
            var userExpr =
                from userResult in RestaurantDomain.CreateUser("Hanz", "HanzPassword", 45)
                let user = (userResult as UserCreated)?.User
                           select userResult;

            var userRez = await interpreter.Interpret(userExpr, Unit.Default);

            var userFinalResult = userRez.Match(OnUserCreated, OnUserNotCreated);

            Assert.True(userFinalResult);

            //MenuItem expression
            var menuItemExpresion =
                from menuItemResult in RestaurantDomain.CreateMenuItem(
                    "Pizza", 13.5m, MenuItemValues.getIngredients(), MenuItemValues.getAlergens(), MenuItemValues.getMenu())
                let menuItem = (menuItemResult as MenuItemCreated)?.MenuItem
                               select menuItemResult;

            var menuItemRez = await interpreter.Interpret(menuItemExpresion, Unit.Default);

            var manuItemFinalResult = menuItemRez.Match(OnMenuItemCreated, OnMenuItemNotCreated);

            Assert.True(manuItemFinalResult);

            //Employee expression
            var employeeExpr =
                from employeeResult in RestaurantDomain.CreateEmployee("Hanz", "Bauer", 30, "Timisoara nr.45",
                                                                       500m, Domain.Models.Gender.Male, Domain.Models.Position.Manager, new Restaurant("Papanasii"))
                let employee = (employeeResult as EmployeeCreated)?.Employee
                               select employeeResult;

            var employeeRez = await interpreter.Interpret(employeeExpr, Unit.Default);

            var employeeFinalResult = employeeRez.Match(OnEmployeeCreated, OnEmployeeNotCreated);

            Assert.True(employeeFinalResult);

            Console.WriteLine("Hello World!");
        }