public async Task <IActionResult> GetAllRestaurants()
        {
            var getAllRestaurantsExpr = from restaurants in Database.Query <GetAllRestaurantsQuery, List <Restaurant> >(new GetAllRestaurantsQuery())
                                        from restarauntsResult in RestaurantDomain.GetAllRestaurants(restaurants)
                                        select restarauntsResult;

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

            return(result.Match(
                       found => (IActionResult) new OkObjectResult(found.Restaurants),
                       notFound => new NotFoundObjectResult(notFound.Reason)));
        }
        public async Task <IActionResult> CreateMenu(string restaurantname, [FromBody] Menus menu)
        {
            var menuExpr = from restaurant in RestaurantDomain.GetRestaurant(restaurantname)
                           let restaurantFoundId = (restaurant as RestaurantFound)?.RestaurantAgg.Restaurant.Id
                                                   from persistedMenu in RestaurantDomain.CreateMenuAndPersist(menu, restaurantFoundId)
                                                   select persistedMenu;

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

            return(result.Match(
                       succesful => (IActionResult) new OkObjectResult(menu),
                       failed => new NotFoundObjectResult(failed.Reason)));
        }
        public static async Task PopulateRestaurantModel(RestaurantAgg restaurantAgg, Func <int, IO <ICollection <Menu> > > getAllMenus, Func <int, IO <ICollection <MenuItem> > > getAllMenuItems, LiveInterpreterAsync interpreter)
        {
            var expression = from allMenus in getAllMenus(restaurantAgg.Restaurant.Id)
                             select allMenus;

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

            restaurantAgg.Menus = result;
            foreach (var menu in restaurantAgg.Menus)
            {
                var expressionMenuItem = from allMenuItems in getAllMenuItems(menu.Id)
                                         select allMenuItems;

                var resultMenuItem = await interpreter.Interpret(expressionMenuItem, Unit.Default);

                menu.MenuItem = resultMenuItem;
            }
        }
        public async Task <IActionResult> SelectRestaurant(String name)
        {
            var expr = from selectRestaurant in RestaurantDomain.GetRestaurant(name)
                       let restaurant = (selectRestaurant as RestaurantSelected)?.RestaurantAgg
                                        from populatedRestaurant in RestaurantDomain.PopulateRestaurant(restaurant, RestaurantDomain.GetAllMenus, RestaurantDomain.GetAllMenuItems, interpreter)
                                        let newRestaurant = (populatedRestaurant as RestaurantPopulated)?.RestaurantAgg
                                                            select populatedRestaurant;

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

            return(await exprResult.MatchAsync <IActionResult>(
                       async (selected) =>
            {
                return (IActionResult)Ok(JsonConvert.SerializeObject(selected.RestaurantAgg.Restaurant));
            },
                       async (notSelected) => NotFound()

                       ));
        }
예제 #5
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!");
        }
예제 #6
0
        static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddOperations(typeof(RestaurantAgg).Assembly);
            serviceCollection.AddOperations(typeof(ClientAgg).Assembly);
            serviceCollection.AddOperations(typeof(EmployeeAgg).Assembly);
            serviceCollection.AddOperations(typeof(MenuAgg).Assembly);
            serviceCollection.AddOperations(typeof(MenuItemAgg).Assembly);
            serviceCollection.AddOperations(typeof(OrderAgg).Assembly);
            serviceCollection.AddOperations(typeof(OrderItemAgg).Assembly);

            serviceCollection.AddOperations(typeof(AddOrUpdateOp).Assembly);
            serviceCollection.AddTransient(typeof(IOp <,>), typeof(QueryOp <,>));

            serviceCollection.AddDbContext <OrderAndPayContext>(ServiceLifetime.Singleton);

            serviceCollection.AddOperations(typeof(OrderAndPayContext).Assembly);

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var interpreter     = new LiveInterpreterAsync(serviceProvider);


            //Adding a Restaurant
            var exprRestaurant =
                from restaurantResult in RestaurantDomain.CreateRestaurantAndPersist("Piata 9", "Strada Rozelor, nr.35")
                let restaurant = (restaurantResult as RestaurantCreated).Restaurant
                                 from menuResult1 in RestaurantDomain.CreateMenuAndPersist("Menu of the day", restaurant.Restaurant)
                                 let menu1 = (menuResult1 as MenuCreated)?.Menu
                                             from menuResult2 in RestaurantDomain.CreateMenuAndPersist("Breakfast", restaurant.Restaurant)
                                             let menu2 = (menuResult2 as MenuCreated)?.Menu
                                                         from menuResult3 in RestaurantDomain.CreateMenuAndPersist("Soup", restaurant.Restaurant)
                                                         let menu3 = (menuResult3 as MenuCreated)?.Menu
                                                                     from menuResult4 in RestaurantDomain.CreateMenuAndPersist("MainCourse", restaurant.Restaurant)
                                                                     let menu4 = (menuResult4 as MenuCreated)?.Menu
                                                                                 from menuResult5 in RestaurantDomain.CreateMenuAndPersist("Pasta", restaurant.Restaurant)
                                                                                 let menu5 = (menuResult5 as MenuCreated)?.Menu
                                                                                             from menuResult6 in RestaurantDomain.CreateMenuAndPersist("Pizza", restaurant.Restaurant)
                                                                                             let menu6 = (menuResult6 as MenuCreated)?.Menu
                                                                                                         from menuResult7 in RestaurantDomain.CreateMenuAndPersist("Desserts", restaurant.Restaurant)
                                                                                                         let menu7 = (menuResult7 as MenuCreated)?.Menu
                                                                                                                     from menuResult8 in RestaurantDomain.CreateMenuAndPersist("Drinks", restaurant.Restaurant)
                                                                                                                     let menu8 = (menuResult8 as MenuCreated)?.Menu
                                                                                                                                 from menuItemResult1 in RestaurantDomain.CreateMenuItemAndPersist(menu1.Menu, "Menu of the day", "ingredients", "allergens", 100, 15.99m, true)
                                                                                                                                 let menuItem1 = (menuItemResult1 as MenuItemCreated)?.MenuItem
                                                                                                                                                 from menuItemResult2 in RestaurantDomain.CreateMenuItemAndPersist(menu2.Menu, "Breakfast 1", "ingredients", "allergens", 150, 12.00m, true)
                                                                                                                                                 let menuItem2 = (menuItemResult2 as MenuItemCreated)?.MenuItem
                                                                                                                                                                 from menuItemResult3 in RestaurantDomain.CreateMenuItemAndPersist(menu1.Menu, "Chicken Soup", "ingredients", "allergens", 200, 16.00m, true)
                                                                                                                                                                 let menuItem3 = (menuItemResult3 as MenuItemCreated)?.MenuItem
                                                                                                                                                                                 from menuItemResult4 in RestaurantDomain.CreateMenuItemAndPersist(menu2.Menu, "Beef Soup", "ingredients", "allergens", 100, 17.00m, true)
                                                                                                                                                                                 let menuItem4 = (menuItemResult4 as MenuItemCreated)?.MenuItem
                                                                                                                                                                                                 from menuItemResult5 in RestaurantDomain.CreateMenuItemAndPersist(menu1.Menu, "Chicken Schnitzel", "ingredients", "allergens", 100, 20.00m, true)
                                                                                                                                                                                                 let menuItem5 = (menuItemResult5 as MenuItemCreated)?.MenuItem
                                                                                                                                                                                                                 from menuItemResult6 in RestaurantDomain.CreateMenuItemAndPersist(menu1.Menu, "Carbonara", "ingredients", "allergens", 150, 19.00m, true)
                                                                                                                                                                                                                 let menuItem6 = (menuItemResult6 as MenuItemCreated)?.MenuItem
                                                                                                                                                                                                                                 from menuItemResult7 in RestaurantDomain.CreateMenuItemAndPersist(menu1.Menu, "Spaghetti Bolognese", "ingredients", "allergens", 200, 18.00m, true)
                                                                                                                                                                                                                                 let menuItem7 = (menuItemResult7 as MenuItemCreated)?.MenuItem
                                                                                                                                                                                                                                                 from menuItemResult8 in RestaurantDomain.CreateMenuItemAndPersist(menu2.Menu, "Lasagna", "ingredients", "allergens", 100, 27.00m, true)
                                                                                                                                                                                                                                                 let menuItem8 = (menuItemResult8 as MenuItemCreated)?.MenuItem
                                                                                                                                                                                                                                                                 from menuItemResult9 in RestaurantDomain.CreateMenuItemAndPersist(menu1.Menu, "Quatro Stagioni", "ingredients", "allergens", 100, 25.00m, true)
                                                                                                                                                                                                                                                                 let menuItem9 = (menuItemResult9 as MenuItemCreated)?.MenuItem
                                                                                                                                                                                                                                                                                 from menuItemResult10 in RestaurantDomain.CreateMenuItemAndPersist(menu1.Menu, "Cheesecake", "ingredients", "allergens", 150, 30.00m, true)
                                                                                                                                                                                                                                                                                 let menuItem10 = (menuItemResult10 as MenuItemCreated)?.MenuItem
                                                                                                                                                                                                                                                                                                  from menuItemResult11 in RestaurantDomain.CreateMenuItemAndPersist(menu1.Menu, "Coca-Cola", "ingredients", "allergens", 200, 5.00m, true)
                                                                                                                                                                                                                                                                                                  let menuItem11 = (menuItemResult11 as MenuItemCreated)?.MenuItem

                                                                                                                                                                                                                                                                                                                   /* from clientResult in RestaurantDomainEx.CreateClientAndPersist("Fifth", "Client", "*****@*****.**", "07xxxxxxxx", "xxxxxxxxxxxxxxxx", "fifth.client", "client05")
                                                                                                                                                                                                                                                                                                                    * let client = (clientResult as ClientCreated)?.Client*/
                                                                                                                                                                                                                                                                                                                   from client in RestaurantDomainEx.GetClient("first.client")
                                                                                                                                                                                                                                                                                                                   from cartItemResult1 in RestaurantDomain.AddToCart("sessionClient05", menuItem4.MenuItem, 1, "special requests")
                                                                                                                                                                                                                                                                                                                   let cartItem1 = (cartItemResult1 as AddToCartSuccessful)?.CartItem
                                                                                                                                                                                                                                                                                                                                   from cartItemResult2 in RestaurantDomain.AddToCart("sessionClient05", menuItem2.MenuItem, 2, "special requests")
                                                                                                                                                                                                                                                                                                                                   let cartItem2 = (cartItemResult2 as AddToCartSuccessful)?.CartItem
                                                                                                                                                                                                                                                                                                                                                   from cartItemResult3 in RestaurantDomain.AddToCart("sessionClient05", menuItem3.MenuItem, 3, "special requests")
                                                                                                                                                                                                                                                                                                                                                   let cartItem3 = (cartItemResult3 as AddToCartSuccessful)?.CartItem

                                                                                                                                                                                                                                                                                                                                                                   from orderResult in RestaurantDomain.PlaceOrderAndPersist(client.Client, restaurant.Restaurant, 140.00m, 5)
                                                                                                                                                                                                                                                                                                                                                                   let order = (orderResult as OrderPlaced)?.Order

                                                                                                                                                                                                                                                                                                                                                                               from orderItemResult1 in RestaurantDomain.CreateOrderItemAndPersist(cartItem1, order.Order)
                                                                                                                                                                                                                                                                                                                                                                               from orderItemResult2 in RestaurantDomain.CreateOrderItemAndPersist(cartItem2, order.Order)
                                                                                                                                                                                                                                                                                                                                                                               from orderItemResult3 in RestaurantDomain.CreateOrderItemAndPersist(cartItem3, order.Order)

                                                                                                                                                                                                                                                                                                                                                                               select restaurant;
            var resultRestaurant = await interpreter.Interpret(exprRestaurant, Unit.Default);

            //var restaurant = await interpreter.Interpret(exprRestaurant, Unit.Default);
            //var finalResultRestaurant = restaurant.Match(OnRestaurantCreated, OnRestaurantNotCreated);
            //Assert.True(finalResultRestaurant);

            //Adding a Client

            /* var exprClient =
             *   from clientResult in RestaurantDomainEx.CreateClientAndPersist("Third", "Client", "*****@*****.**", "07xxxxxxxx", "xxxxxxxxxxxxxxxx", "third.client", "client03")
             *   let client = (clientResult as ClientCreated)?.Client
             *   select clientResult;
             *
             * var resultClient = await interpreter.Interpret(exprClient, Unit.Default);
             *
             *
             * //Adding an Employee
             * var exprEmployee =
             *     from employeeResult in RestaurantDomainEx.CreateEmployeeAndPersist("Employee", "01", "*****@*****.**", "07xxxxxxxx", "Chef", "Chef01", "password", 4)
             *     let employee = (employeeResult as EmployeeCreated)?.Employee
             *     select employeeResult;
             *
             * var resultEmployee = await interpreter.Interpret(exprEmployee, Unit.Default);*/



            // Testing Queries

            /*var getRestaurantExpr =
             *  from restaurantResult in RestaurantDomainEx.GetRestaurant("Restaurant_4")
             *  select restaurantResult;
             *
             * var interpretedRestaurant = await interpreter.Interpret(getRestaurantExpr, Unit.Default);*/
            //var restaurantResponse = interpretedRestaurant.Match<bool>(OnRestaurantFound, OnRestaurantNotFound);

            /*var exprFindClient =
             *  from clientResult in RestaurantDomainEx.GetClient("second.client")
             *  select clientResult;
             * var client = await interpreter.Interpret(exprFindClient, Unit.Default);*/

            /*var exprFindEmployee =
             *  from employeeResult in RestaurantDomainEx.GetEmployee(restaurant.Restaurant.Id, "waiter01")
             *  select employeeResult;
             * var employee = await interpreter.Interpret(exprFindEmployee, Unit.Default);*/

            /*var exprFindMenus =
             * from menusResult in RestaurantDomainEx.GetMenus(interpretedRestaurant.Restaurant)
             * select menusResult;
             * var menus = await interpreter.Interpret(exprFindMenus, Unit.Default);*/

            //var finalResultMenus = menus.Match(OnMenusFound, OnMenusNotFound);
            //Assert.True(finalResultMenus);

            //Console.WriteLine(restaurant.Restaurant.Name);
            //Console.WriteLine(client.Client.ClientId);
            //Console.WriteLine(employee.Employee.EmployeeId);

            /*foreach (Menu m in menus.Menus)
             * {
             *  Console.WriteLine(m.Name);
             * }*/
        }
예제 #7
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);
            }
                    );
        }
        public async Task <IActionResult> GetClient(string clientId)
        {
            var getClientExpr =
                from clientResult in RestaurantDomain.GetClient(clientId)
                select clientResult;
            var client = await _interpreter.Interpret(getClientExpr, Unit.Default);

            return(client.Match(
                       found => (IActionResult)Ok(found.Agg.Client),
                       notFound => NotFound()));
        }
        public async Task <IActionResult> GetAllRestaurants()
        {
            var expr = from selectRestaurants in RestaurantDomain.GetAllRestaurants()
                       select selectRestaurants;

            return(Ok(await interpreter.Interpret(expr, Unit.Default)));
        }
예제 #10
0
        public async Task <IActionResult> GetEmployee(string restaurantName, string employeeId)
        {
            var getRestaurantExpr =
                from restaurantResult in RestaurantDomain.GetRestaurant(restaurantName)
                select restaurantResult;
            var restaurant = await _interpreter.Interpret(getRestaurantExpr, Unit.Default);

            var getRestaurant =
                from restaurantResult in RestaurantDomainEx.GetRestaurant(restaurantName)
                select restaurantResult;
            var restaurantAgg = await _interpreter.Interpret(getRestaurant, Unit.Default);

            var getEmployeeExpr =
                from employeeResult in RestaurantDomain.GetEmployee(restaurantAgg.Restaurant.Id, employeeId)
                select employeeResult;
            var employee = await _interpreter.Interpret(getEmployeeExpr, Unit.Default);

            return(restaurant.Match(
                       found => (IActionResult)Ok(found.Agg.Restaurant),
                       notFound => NotFound()));
        }
        public static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddOperations(typeof(RestaurantAgg).Assembly);
            serviceCollection.AddOperations(typeof(MenuAgg).Assembly);
            serviceCollection.AddOperations(typeof(AddOrUpdateEntityOp).Assembly);
            serviceCollection.AddTransient(typeof(IOp <,>), typeof(QueryOp <,>));

            serviceCollection.AddDbContext <OrderAndPayContext>(ServiceLifetime.Singleton);

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var interpreter = new LiveInterpreterAsync(serviceProvider);

            //Selecting the restaurant
            var expr = from selectRestaurant in RestaurantDomain.GetRestaurant("McDonalds")
                       let restaurant = (selectRestaurant as RestaurantAgg)?.Restaurant
                                        select selectRestaurant;

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

            var finalExpr = await exprResult.MatchAsync(
                async (persisted) => // Restaurant Successfully selected
            {
                // Populates the RestaurantAgg model with the data from two functions, using a LiveAsyncInterpreter.
                // This function will firstly populate the ICollection<Menu> Menus by calling GetAllMenus, with all the menus from the database that have the restaurant's id
                // After the ICollection<Menu> will be filled, for each entity it will call the GetAllMenuItems function to populate the menu
                await RestaurantDomain.PopulateRestaurantModel(persisted.RestaurantAgg, RestaurantDomain.GetAllMenus, RestaurantDomain.GetAllMenuItems, interpreter);

                //// Selects a menu with a specific name
                var selectMenuExpr                       = from selectMenu in RestaurantDomain.GetMenu("Chicken", persisted.RestaurantAgg.Restaurant.Id)
                                                let menu = (selectMenu as MenuSelected)?.MenuAgg
                                                           select selectMenu;

                var selectMenuRes    = await interpreter.Interpret(selectMenuExpr, Unit.Default);
                var selectMenuResult = await selectMenuRes.MatchAsync(
                    async(selected) =>      // Menu was successfully selected
                {
                    selected.MenuAgg.Menu.Hours = "8-13";

                    var updateRestaurantExprUnique = from updateRestauruant in RestaurantDomain.UpdateAndPersistMenu(selected.MenuAgg.Menu)
                                                     let updatem = (updateRestauruant as MenuUpdated)?.Menu
                                                                   select updateRestauruant;
                    var updateRestaurantFin = await interpreter.Interpret(updateRestaurantExprUnique, Unit.Default);

                    var matchh = updateRestaurantFin.Match(
                        updated =>
                    {
                        return(updated);
                    },
                        notUpdated =>
                    {
                        return(notUpdated);
                    }
                        );
                    //var getAllMenuItems = from getAllMenus in RestaurantDomain.GetAllMenuItems(10)
                    //                      select getAllMenus;

                    //var getAllMenusResult = await interpreter.Interpret(getAllMenuItems, Unit.Default);

                    return(selected);
                },
                    async(notSelected) =>      // Menu not selected
                {
                    return(notSelected);
                }

                    );

                return(persisted);
            },
                async (notPersisted) => // Restaurant not selected
            {
                return(notPersisted);
            }

                );

            Console.WriteLine("Hello World!");
        }
예제 #12
0
        static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddOperations(typeof(RestaurantAgg).Assembly);
            serviceCollection.AddOperations(typeof(ClientAgg).Assembly);
            serviceCollection.AddOperations(typeof(EmployeeAgg).Assembly);
            serviceCollection.AddOperations(typeof(MenuAgg).Assembly);
            serviceCollection.AddOperations(typeof(MenuItemAgg).Assembly);
            serviceCollection.AddOperations(typeof(OrderAgg).Assembly);
            serviceCollection.AddOperations(typeof(OrderItemAgg).Assembly);

            serviceCollection.AddOperations(typeof(AddOrUpdateOp).Assembly);
            serviceCollection.AddTransient(typeof(IOp <,>), typeof(QueryOp <,>));

            serviceCollection.AddDbContext <OrderAndPayContext>(ServiceLifetime.Singleton);

            serviceCollection.AddOperations(typeof(OrderAndPayContext).Assembly);

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var interpreter     = new LiveInterpreterAsync(serviceProvider);

            /*
             * //Adding a Restaurant
             *      var exprRestaurant =
             *          from restaurantResult in RestaurantDomainEx.CreateRestaurantAndPersist("Restaurant_7", "address")
             *          let restaurant = (restaurantResult as RestaurantCreated)?.Restaurant
             *
             *          /*from menuResult1 in RestaurantDomainEx.CreateMenuAndPersist("Pasta", restaurant.Restaurant)
             *          let menu1 = (menuResult1 as MenuCreated)?.Menu
             *          from menuResult2 in RestaurantDomainEx.CreateMenuAndPersist("Pizza", restaurant.Restaurant)
             *          let menu2 = (menuResult2 as MenuCreated)?.Menu
             *
             *          from menuItemResult1 in RestaurantDomainEx.CreateMenuItemAndPersist(menu1.Menu, "Carbonara", "ingredients", "allergens", 100, 27.00, true)
             *          let menuItem1 = (menuItemResult1 as MenuItemCreated)?.MenuItem
             *          from menuItemResult2 in RestaurantDomainEx.CreateMenuItemAndPersist(menu1.Menu, "Spaghetti", "ingredients", "allergens", 150, 25.00, true)
             *          let menuItem2 = (menuItemResult2 as MenuItemCreated)?.MenuItem
             *          from menuItemResult3 in RestaurantDomainEx.CreateMenuItemAndPersist(menu1.Menu, "Macaroni", "ingredients", "allergens", 200, 21.00, true)
             *          let menuItem3 = (menuItemResult3 as MenuItemCreated)?.MenuItem
             *          from menuItemResult4 in RestaurantDomainEx.CreateMenuItemAndPersist(menu2.Menu, "Pizza", "ingredients", "allergens", 1, 30.00, true)
             *          let menuItem4 = (menuItemResult4 as MenuItemCreated)?.MenuItem
             *
             *          from clientResult in RestaurantDomainEx.CreateClientAndPersist("Fifth", "Client", "*****@*****.**", "07xxxxxxxx", "xxxxxxxxxxxxxxxx", "fifth.client", "client05")
             *          let client = (clientResult as ClientCreated)?.Client
             *
             *          from cartItemResult1 in RestaurantDomain.AddToCart("sessionClient05", menuItem4.MenuItem, 1, "special requests")
             *          let cartItem1 = (cartItemResult1 as AddToCartSuccessful)?.CartItem
             *          from cartItemResult2 in RestaurantDomain.AddToCart("sessionClient05", menuItem2.MenuItem, 2, "special requests")
             *          let cartItem2 = (cartItemResult2 as AddToCartSuccessful)?.CartItem
             *          from cartItemResult3 in RestaurantDomain.AddToCart("sessionClient05", menuItem3.MenuItem, 3, "special requests")
             *          let cartItem3 = (cartItemResult3 as AddToCartSuccessful)?.CartItem
             *
             *          from orderResult in RestaurantDomainEx.PlaceOrder(client.Client, restaurant.Restaurant, 140.00, 5)
             *          let order = (orderResult as OrderPlaced)?.Order
             *
             *          from orderItemResult1 in RestaurantDomainEx.CreateOrderItem(cartItem1, order.Order)
             *          //from orderItemResult2 in RestaurantDomainEx.CreateOrderItem(cartItem2, order.Order)
             *          //from orderItemResult3 in RestaurantDomainEx.CreateOrderItem(cartItem3, order.Order)
             *
             * select restaurantResult;
             *
             *       var resultRestaurant = await interpreter.Interpret(exprRestaurant, Unit.Default);
             *
             *
             * //Adding a Client
             * var exprClient =
             *  from clientResult in RestaurantDomainEx.CreateClientAndPersist("Third", "Client", "*****@*****.**", "07xxxxxxxx", "xxxxxxxxxxxxxxxx", "third.client", "client03")
             *  let client = (clientResult as ClientCreated)?.Client
             *  select clientResult;
             *
             * var resultClient = await interpreter.Interpret(exprClient, Unit.Default);
             *
             *
             * //Adding an Employee
             * var exprEmployee =
             *    from employeeResult in RestaurantDomainEx.CreateEmployeeAndPersist("Employee", "01", "*****@*****.**", "07xxxxxxxx", "Chef", "Chef01", "password", 4)
             *    let employee = (employeeResult as EmployeeCreated)?.Employee
             *    select employeeResult;
             *
             * var resultEmployee = await interpreter.Interpret(exprEmployee, Unit.Default);
             */

            // Testing Queries
            var exprFindRestaurant =
                from restaurantResult in RestaurantDomainEx.GetRestaurant("Restaurant_1")
                select restaurantResult;
            var restaurant = await interpreter.Interpret(exprFindRestaurant, Unit.Default);

            var exprFindClient =
                from clientResult in RestaurantDomainEx.GetClient("second.client")
                select clientResult;
            var client = await interpreter.Interpret(exprFindClient, Unit.Default);

            var exprFindEmployee =
                from employeeResult in RestaurantDomainEx.GetEmployee(restaurant.Restaurant.Id, "waiter01")
                select employeeResult;
            var employee = await interpreter.Interpret(exprFindEmployee, Unit.Default);

            var exprFindMenus =
                from menusResult in RestaurantDomainEx.GetMenus(restaurant.Restaurant)
                select menusResult;
            var menus = await interpreter.Interpret(exprFindMenus, Unit.Default);

            Console.WriteLine(restaurant.Restaurant.Name);
            Console.WriteLine(client.Client.ClientId);
            Console.WriteLine(employee.Employee.EmployeeId);

            foreach (Menu m in menus)
            {
                Console.WriteLine(m.Name);
            }
        }
예제 #13
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;
                }
            }
        }
예제 #14
0
        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!");
        }