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(); }); } )); }