public async Task <IActionResult> CreateRestaurant([FromBody] Restaurant restaurant)
        {
            var createRestaurantExpr = from entity in RestaurantDomain.CreateRestaurant(restaurant.Name)
                                       let entityRes = (entity as RestaurantCreated)?.RestaurantAgg
                                                       from r in Database.AddOrUpdate(entityRes.Restaurant)
                                                       select r;

            var result = await _interpreter.Interpret(createRestaurantExpr, Unit.Default);

            return(result.Match(
                       succesful => (IActionResult) new OkObjectResult(restaurant),
                       failed => new NotFoundObjectResult(failed.Reason)));
        }
Пример #2
0
        static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

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

            var newRestaurant =
                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(newRestaurant, Unit.Default);

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

            Assert.True(finalResult);

            Console.WriteLine("Hello World!");
        }
Пример #3
0
        static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddOperations(typeof(Restaurant).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)
                                 let menu = (newMenu as MenuCreated)?.Menu
                                            from menuItem1 in RestaurantDomain.CreateMenuItem(menu, "mcpuisor", 5, new List <string>()
            {
                "pui", "sos", "castraveti"
            })
                                            from menuItem2 in RestaurantDomain.CreateMenuItem(menu, "cheeseburger", 5, new List <string>()
            {
                "vita", "sos", "branza"
            })
                                            select menuItem2;

            var interpreter = new LiveInterpreterAsync(serviceProvider);

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

            var r =
                result.Match(
                    created =>
            {
                Console.WriteLine("Menu Item:" + created.MenuItem.Title + " was created");
                return(created);
            },
                    notCreated =>
            {
                Console.WriteLine($"Menu item failed because {notCreated.Reason}");
                return(notCreated);
            });
            //var finalResult = result.Match<bool>(OnRestaurantCreated, OnRestaurantNotCreated);
            //Assert.True(finalResult);
            var expr2 =
                from restaurant in RestaurantDomain.GetRestaurant("mcdonalds")
                select restaurant;
            var interpreter2 = new LiveInterpreterAsync(serviceProvider);
            var result2      = await interpreter.Interpret(expr2, Unit.Default);

            var r2 =
                result2.Match(
                    Found =>
            {
                Console.WriteLine("Restaurant:" + Found.Restaurant.Name + " was found");
                return(Found);
            },
                    notFound =>
            {
                Console.WriteLine($"Restaurant not found because {notFound.Reason}");
                return(notFound);
            }
                    );
            var expr3 =
                from restaurant in RestaurantDomain.GetRestaurant("mcdonalds")
                let restaurant2 = (restaurant as RestaurantFound)?.Restaurant
                                  from menu in RestaurantDomain.GetMenus(restaurant2, "burgers")
                                  let menu2 = (menu as MenuFound)?.Menu
                                              from item in RestaurantDomain.GetMenuItem(menu2, "mcpuisor")
                                              let item2 = (item as MenuItemGot)?.MenuItem
                                                          from client in RestaurantDomain.GetClient("gicu")
                                                          let client2 = (client as ClientFound)?.Client
                                                                        from addcart in RestaurantDomain.AddToCart("", client2, item2, 2)
                                                                        select addcart;
            var interpreter3 = new LiveInterpreterAsync(serviceProvider);
            var result3      = await interpreter.Interpret(expr3, Unit.Default);

            var r3 =
                result3.Match(
                    Succesful =>
            {
                Console.WriteLine("item successfully added to cart:" + Succesful.Cart);
                return(Succesful);
            },
                    NotSuccesful =>
            {
                Console.WriteLine("couldn't add to cart because:" + NotSuccesful.Reason + " was found");
                return(NotSuccesful);
            },
                    InvalidRequest =>
            {
                Console.WriteLine("couldn't add to cart because:" + InvalidRequest.Reason + " was found");
                return(InvalidRequest);
            }
                    );
        }
Пример #4
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!");
        }