public async Task <IActionResult> GetMenus(string restaurantName)
        {
            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 getMenusExpr =
                from menusRestaurant in RestaurantDomain.GetMenus(restaurantAgg.Restaurant)
                select menusRestaurant;
            var menus = await _interpreter.Interpret(getMenusExpr, Unit.Default);

            /*var getMenus =
             *  from menusRestaurant in RestaurantDomainEx.GetMenus(restaurantAgg.Restaurant)
             *  select menusRestaurant;
             * var menusList = await _interpreter.Interpret(getMenus, Unit.Default);*/

            return(restaurant.Match(
                       found => (IActionResult)Ok(found.Agg.Restaurant.Menus),
                       notFound => NotFound()));
        }
        public async Task <IActionResult> CreateMenu(String RestaurantName, [Bind("Name,MenuType,Visibility,Hours")] Menu entity)
        {
            var checkIfExists = from getRestaurant in RestaurantDomain.GetRestaurant(RestaurantName)
                                let restaurant = (getRestaurant as RestaurantSelected)?.RestaurantAgg.Restaurant
                                                 from getMenu in RestaurantDomain.GetMenu(entity.Name, restaurant.Id)
                                                 select getMenu;
            var checkIfExistsResult = await interpreter.Interpret(checkIfExists, Unit.Default);

            return(await checkIfExistsResult.MatchAsync <IActionResult>(
                       async exists =>
            {
                return BadRequest();
            },
                       async inexistent =>
            {
                var expr = from getRestaurant in RestaurantDomain.GetRestaurant(RestaurantName)
                           let restaurant = (getRestaurant as RestaurantSelected)?.RestaurantAgg.Restaurant
                                            from createEntity in RestaurantDomain.CreateAndPersistMenu(entity, restaurant)
                                            let entityC = (createEntity as MenuCreated)?.Menu
                                                          select createEntity;

                var result = await interpreter.Interpret(expr, Unit.Default);
                return await result.MatchAsync <IActionResult>(
                    async(created) =>
                {
                    //await interpreter.Interpret(Database.AddOrUpdateEntity(created.Menu.Menu), Unit.Default);
                    return (IActionResult)Ok(created.Menu.Menu);
                },
                    async(notCreated) =>
                {
                    return BadRequest();
                });
            }
                       ));
        }
        public async Task <IActionResult> CreateRestaurant([Bind("Name")] Restaurant entity)
        {
            var checkIfExists = from selectRestaurant in RestaurantDomain.GetRestaurant(entity.Name)
                                select selectRestaurant;

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

            return(await result.MatchAsync <IActionResult>(
                       async (exists) =>
            {
                return BadRequest();
            },
                       async (inexistent) =>
            {
                var expr = from createEntity in RestaurantDomain.CreateAndPersistRestaurant(entity)
                           let entityC = (createEntity as RestaurantCreated)?.RestaurantAgg
                                         select createEntity;

                var result = await interpreter.Interpret(expr, Unit.Default);
                return await result.MatchAsync <IActionResult>(
                    async(created) =>
                {
                    return (IActionResult)Ok(created.RestaurantAgg.Restaurant);
                },
                    async(notCreated) =>
                {
                    return BadRequest();
                });
            }
                       ));
        }
        public async Task <IActionResult> GetAllOrdersPopulated(String restaurantName)
        {
            var expr = from selectRestaurant in RestaurantDomain.GetRestaurant(restaurantName)
                       let restaurant = (selectRestaurant as RestaurantSelected)?.RestaurantAgg.Restaurant
                                        from getAllOrdersPopulated in RestaurantDomain.PopulateOrder(restaurant, null, RestaurantDomain.GetAllOrders, RestaurantDomain.GetAllOrderItems, interpreter)
                                        select getAllOrdersPopulated;

            return((IActionResult)Ok(await interpreter.Interpret(expr, Unit.Default)));
        }
        public async Task <IActionResult> GetAllOrders(String restaurantName)
        {
            var expr = from selectRestaurant in RestaurantDomain.GetRestaurant(restaurantName)
                       let restaurant = (selectRestaurant as RestaurantSelected)?.RestaurantAgg
                                        from getAllOrders in RestaurantDomain.GetAllOrdersItems(restaurant.Restaurant.Id)

                                        select getAllOrders;

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

            return(restaurant.Match(
                       found => (IActionResult)Ok(found.Agg.Restaurant),
                       notFound => NotFound()));
        }
        public async Task <IActionResult> GetMenus(string restaurantname)
        {
            var getRestaurantExpr = from restaurant in RestaurantDomain.GetRestaurant(restaurantname)
                                    select restaurant;

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

            return(result.Match(
                       found => (IActionResult) new OkObjectResult(found.RestaurantAgg.Restaurant.Menus),
                       notFound => new NotFoundObjectResult(notFound.Reason)));
        }
        public async Task <IActionResult> GetAllMenuItems(String restaurantName, String menuName)
        {
            var getAllMenuItemsExpr = from selectRestaurant in RestaurantDomain.GetRestaurant(restaurantName)
                                      let restaurant = (selectRestaurant as RestaurantSelected)?.RestaurantAgg
                                                       from selectMenu in RestaurantDomain.GetMenu(menuName, restaurant.Restaurant.Id)
                                                       let menu = (selectMenu as MenuSelected)?.MenuAgg
                                                                  from getAllMenus in RestaurantDomain.GetAllMenuItems(menu.Menu.Id)
                                                                  select getAllMenus;

            return(Ok(await interpreter.Interpret(getAllMenuItemsExpr, Unit.Default)));
        }
        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 async Task <IActionResult> CreateMenuItem(string restaurantname, string menuname, [FromBody] MenuItems menuItem)
        {
            var menuExpr = from restaurant in RestaurantDomain.GetRestaurant(restaurantname)
                           let restaurantFound = (restaurant as RestaurantFound)?.RestaurantAgg.Restaurant
                                                 from menu in RestaurantDomain.GetSpecificMenu(restaurantFound, menuname)
                                                 let foundMenuId = (menu as SpecificMenuFound)?.Menu.Id
                                                                   from menuitemPersisted in RestaurantDomain.CreateMenuItemAndPersist(menuItem, foundMenuId)
                                                                   select menuitemPersisted;


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

            return(result.Match(
                       succesful => (IActionResult) new OkObjectResult(menuItem),
                       failed => new NotFoundObjectResult(failed.Reason)));
        }
        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()

                       ));
        }
Пример #12
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 async Task <IActionResult> CreateMenuItem(String RestaurantName, String MenuName, [Bind("Name,Ingredients,Alergens,Price,Image")] MenuItem entity)
        {
            var checkIfExistsExpr = from selectRestaurant in RestaurantDomain.GetRestaurant(RestaurantName)
                                    let restaurant = (selectRestaurant as RestaurantSelected)?.RestaurantAgg.Restaurant
                                                     from selectMenu in RestaurantDomain.GetMenu(MenuName, restaurant.Id)
                                                     let menu = (selectMenu as MenuSelected)?.MenuAgg.Menu
                                                                from selectMenuItem in RestaurantDomain.GetMenuItem(entity.Name, menu.Id)
                                                                select selectMenuItem;

            var checkIfExistsResult = await interpreter.Interpret(checkIfExistsExpr, Unit.Default);

            return(await checkIfExistsResult.MatchAsync <IActionResult>(
                       async exists =>
            {
                return BadRequest();
            },
                       async inexistent =>
            {
                var expr = from selectRestaurant in RestaurantDomain.GetRestaurant(RestaurantName)
                           let restaurant = (selectRestaurant as RestaurantSelected)?.RestaurantAgg.Restaurant
                                            from selectMenu in RestaurantDomain.GetMenu(MenuName, restaurant.Id)
                                            let menu = (selectMenu as MenuSelected)?.MenuAgg.Menu
                                                       from createEntity in RestaurantDomain.CreateAndPersistMenuItem(menu, entity)
                                                       let entityC = (createEntity as MenuItemCreated)?.MenuItemAgg
                                                                     select createEntity;

                var result = await interpreter.Interpret(expr, Unit.Default);
                return await result.MatchAsync <IActionResult>(
                    async(created) =>
                {
                    await interpreter.Interpret(Database.AddOrUpdateEntity(created.MenuItemAgg.MenuItem), Unit.Default);
                    return (IActionResult)Ok(created.MenuItemAgg.MenuItem);
                },
                    async(notCreated) =>
                {
                    return BadRequest();
                });
            }
                       ));
        }
        public async Task <IActionResult> GetMenuItem(String restaurantName, String menuName, String menuItemName)
        {
            var getMenuItemExpr = from restaurantResult in RestaurantDomain.GetRestaurant(restaurantName)
                                  let restaurant = (restaurantResult as RestaurantSelected)?.RestaurantAgg.Restaurant
                                                   from menuResult in RestaurantDomain.GetMenu(menuName, restaurant.Id)
                                                   let menu = (menuResult as MenuSelected)?.MenuAgg.Menu
                                                              from menuItemResult in RestaurantDomain.GetMenuItem(menuItemName, menu.Id)

                                                              select menuItemResult;

            var getMenuItemResult = await interpreter.Interpret(getMenuItemExpr, Unit.Default);

            return(await getMenuItemResult.MatchAsync <IActionResult>(
                       async (selected) =>
            {
                return (IActionResult)Ok(JsonConvert.SerializeObject(selected.MenuItemAgg.MenuItem));
            },
                       async (notSelected) =>
            {
                return NotFound();
            }
                       ));
        }
        public async Task <IActionResult> GetMenu(string restaurantName, String menuName)
        {
            //Selecting the restaurant
            var expr = from selectRestaurant in RestaurantDomain.GetRestaurant(restaurantName)
                       let restaurant = (selectRestaurant as RestaurantSelected)?.RestaurantAgg
                                        from selectMenu in RestaurantDomain.GetMenu(menuName, restaurant.Restaurant.Id)
                                        let menu = (selectMenu as MenuSelected)?.MenuAgg
                                                   select selectMenu;

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

            return(await exprResult.MatchAsync <IActionResult>(
                       async (selected) =>  // Menu was successfully selected
            {
                return (IActionResult)Ok(selected.MenuAgg.Menu);
            },
                       async (notSelected) =>  // Menu not selected
            {
                return NotFound();
            }

                       ));
        }
Пример #16
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 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!");
        }