public PopulateRestaurantCmd(RestaurantAgg restaurant, Func<int, IO<ICollection<Menu>>> getAllMenus, Func<int, IO<ICollection<MenuItem>>> getAllMenuItems, LiveInterpreterAsync interpreter) { RestaurantAgg = restaurant; GetAllMenus = getAllMenus; GetAllMenuItems = getAllMenuItems; this.interpreter = interpreter; }
public override Task <ICreateRestaurantResult> Work(CreateRestaurantCmd Op, Unit state) { RestaurantAgg newRestaurantAgg = new RestaurantAgg(new Restaurant() { Name = Op.Name, Address = Op.Address }); return(Task.FromResult <ICreateRestaurantResult>(new RestaurantCreated(newRestaurantAgg))); }
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 override Task <ICreateRestaurantResult> Work(CreateRestaurantCmd Op, Unit state) { var(valid, validationResults) = Op.Validate(); string validationMessage = ""; validationResults.ForEach(x => validationMessage += x.ErrorMessage); if (!valid) { return(Task.FromResult <ICreateRestaurantResult>(new RestaurantNotCreated(validationMessage))); } RestaurantAgg newRestaurant = new RestaurantAgg(new Restaurant() { Name = Op.Name }); return(Task.FromResult <ICreateRestaurantResult>(new RestaurantCreated(newRestaurant))); }
public RestaurantFound(RestaurantAgg agg) { Agg = agg; }
public OrderPlaced(RestaurantAgg restaurant, Order order) { Restaurant = restaurant; Order = order; }
// 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 public static IO <IPopulateRestaurantResult> PopulateRestaurant(RestaurantAgg restaurantAgg, Func <int, IO <ICollection <Menu> > > getAllMenus, Func <int, IO <ICollection <MenuItem> > > getAllMenuItems, LiveInterpreterAsync interpreter) => NewIO <PopulateRestaurantOp.PopulateRestaurantCmd, IPopulateRestaurantResult>(new PopulateRestaurantOp.PopulateRestaurantCmd(restaurantAgg, getAllMenus, getAllMenuItems, interpreter));
public PlaceOrderCmd(Order order, RestaurantAgg restaurant) { Order = order; Restaurant = restaurant; }
public RestaurantCreated(RestaurantAgg restaurant) { RestaurantAgg = restaurant; }
public RestaurantFound(RestaurantAgg restaurant) { RestaurantAgg = restaurant; }
public RestaurantSelected(RestaurantAgg restaurant) { RestaurantAgg = restaurant; }
public RestaurantPopulated(RestaurantAgg restaurantAgg) { RestaurantAgg = restaurantAgg; }
public static IO <IPlaceOrderResult> CreateAndPlaceOrder(Client client, RestaurantAgg restaurant) => from createOrderResult in CreateOder(client) let createdOrder = (createOrderResult as OrderCreated)?.Order from placeOrderResult in PlaceOrder(createdOrder, restaurant) select placeOrderResult;
public static IO <IPlaceOrderResult> PlaceOrder(Order order, RestaurantAgg restaurant) => NewIO <PlaceOrderCmd, IPlaceOrderResult>(new PlaceOrderCmd(order, restaurant));