public bool UpdateRecipe(RecipeView recipe) { var updatedRecipe = GetRecipeById(recipe.Id); if (updatedRecipe != null) { updatedRecipe.Name = recipe.Name; updatedRecipe.Description = recipe.Description; updatedRecipe.RecipeTags.RemoveAll(r => r.RecipeId == recipe.Id); SaveChanges(); //update tags at some point foreach (string t in recipe.Tags) { var result = _tags.FindTag(t); if (result == null) { result = _tags.AddTag(t); } //add the 'join' between recipe and tag _recipe.Add(new RecipeTag { RecipeId = recipe.Id, TagId = result.Id }); } _recipe.Recipes.Update(updatedRecipe); SaveChanges(); return(true); } else { return(false); } }
public MainMenuViewModel() { Menu = new ObservableCollection <ItemMenu>(); var product = new ItemMenu() { Name = "Продукт", Open = new Command((() => { var view = new ProductsView(); CurrentPage = view; })) }; var unit = new ItemMenu() { Name = "Единицы измерения", Open = new Command((() => { var view = new UnitsView(); CurrentPage = view; })) }; var recipe = new ItemMenu() { Name = "Рецепты", Open = new Command((() => { var view = new RecipeView(); CurrentPage = view; })) }; var provider = new ItemMenu() { Name = "Поставщики", Open = new Command((() => { var view = new ProductsView(); CurrentPage = view; })) }; var location = new ItemMenu() { Name = "Локации", Open = new Command((() => { var view = new LocationView(); CurrentPage = view; })) }; Menu.Add(product); Menu.Add(unit); Menu.Add(location); Menu.Add(recipe); Menu.Add(provider); }
private bool RecipeHasExpiredIngredient(RecipeView recipe, IngredientView ingredient) { if (recipe.Ingredients.Contains(ingredient.Title)) { return(ingredient.UseByDate < DateTime.Now); } return(false); }
public MainWindow() { InitializeComponent(); _groceryListView = new GroceryListView(new GroceryListVM(_groceryListRepo)); _recipeView = new RecipeView(new RecipeVM(_groceryListRepo)); _ingredientsView = new IngredientsView(new IngredientsVM(_groceryListRepo)); MainContent.Content = _groceryListView; }
private void OnItemSelected(object sender) { var recipe = _recipeList.Find(x => x.RecipeName.ToString() == SelectedRecipe); var recipeView = new RecipeView { DataContext = new RecipeViewModel(recipe) }; recipeView.Show(); }
public AddRecipeWinodw(RecipeView rv) { InitializeComponent(); TagDisplayer.ItemsSource = Enum.GetValues(typeof(Tag)); IngredientDisplayer.ItemsSource = Pantry.Ingredients; this.rv = rv; TextBoxOptions(); this.Focus(); }
public void ExpiredUseByIngredientsAreNotIncludedInRecipes() { var useByExpiredIngredient = new IngredientView() { Title = "Ham", BestBefore = "2021-03-25", UseBy = "2020-01-01" }; var useByNotExpiredIngredient = new IngredientView() { Title = "Cheese", BestBefore = "2021-03-25", UseBy = "2021-01-01" }; var lsIngredients = new List <IngredientView>() { useByExpiredIngredient, useByNotExpiredIngredient }; var recipeWExpired = new RecipeView() { Title = "Ham & Cheese Toastie", Ingredients = new List <string>() { "Ham", "Cheese", "Bread", "Butter" } }; var recipeWithoutExpired = new RecipeView() { Title = "Cheese Toastie", Ingredients = new List <string>() { "Cheese", "Bread", "Butter" } }; var lsRecipes = new List <RecipeView>() { recipeWExpired, recipeWithoutExpired }; var ingredientRepo = new TestIngredientRepository(lsIngredients); var recipeRepo = new TestRecipeRepository(lsRecipes); var recipeService = new RecipeService(recipeRepo, ingredientRepo); var result = recipeService.GetRecipes(); Assert.Equal(result.Count, 1); }
public void InitializeLateBinding() { CanvasWidthBox.SetBinding(TextBox.TextProperty, new Binding("CanvasWidth")); CanvasWidthBox.DataContext = CADCanvas.Binder; CanvasHeightBox.SetBinding(TextBox.TextProperty, new Binding("CanvasHeight")); CanvasHeightBox.DataContext = CADCanvas.Binder; RecipeView.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("CommandList")); RecipeView.DataContext = Recipe.Binder; }
public void RefreshRecipeScreen() { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { // TODO: Cause the RecipeResultsViewModel in the RecipeView to refresh its recipes, instead of // recreating the RecipeView object. This could perhaps be done by triggering an event, or // reaching into the view/viewmodel and calling it directly (but that's probably very bad form). screens[RECIPE_VIEW] = new RecipeView(); })); }
public IActionResult RecipeById(int id) { var recipe = _recipe.GetRecipeById(id); if (recipe != null) { RecipeView rv = RecipeToView(recipe); return(Ok(rv)); } return(NotFound()); }
//[Route("{id:int}")] public IActionResult UpdateRecipe([FromBody] RecipeView r) { if (ModelState.IsValid) { if (_recipe.UpdateRecipe(r)) { return(Ok()); } } return(BadRequest()); }
public void GetRecipesIfIngredientsMatchTest() { var ingredient1 = new IngredientView() { Title = "Ham", BestBefore = "2021-03-25", UseBy = "2021-01-01" }; var ingredient2 = new IngredientView() { Title = "Cheese", BestBefore = "2021-03-25", UseBy = "2021-01-01" }; var lsIngredients = new List <IngredientView>() { ingredient1, ingredient2 }; var recipe1 = new RecipeView() { Title = "Ham Toastie", Ingredients = new List <string>() { "Ham", "Bread", "Butter" } }; var recipe2 = new RecipeView() { Title = "Rice Toastie", Ingredients = new List <string>() { "Rice", "Butter" } }; var lsRecipes = new List <RecipeView>() { recipe1, recipe2 }; var ingredientRepo = new TestIngredientRepository(lsIngredients); var recipeRepo = new TestRecipeRepository(lsRecipes); var recipeService = new RecipeService(recipeRepo, ingredientRepo); var result = recipeService.GetRecipes(); Assert.Equal(result.Count, 1); }
public ActionResult Create(RecipeView model) { if (ModelState.IsValid) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <RecipeView, RecipeDTO>()).CreateMapper(); var item = mapper.Map <RecipeView, RecipeDTO>(model); RecipeService.Create(item); return(RedirectToAction($"GetListOfRecipes/{item.PatientId}")); } return(Create(model)); }
private Recipe ToRecipe(RecipeView view) { return(new Recipe { Name = view.Name, Direction = view.Direction, ChefId = view.ChefId, Image = view.Image, Rating = view.Rating, RecipeId = view.RecipeId }); }
public async Task <IActionResult> Index([FromServices] PlanDetailsViewModel toView) { //akutalnie zalogowany użytkownik var user = await _userManager.GetUserAsync(User); // pobieramy jego ostatni dodany plan var plan = _planService.LastAddedPlan(user.UserName); if (plan != null) { var days = _dayNameService.GetAll(); toView.PlanName = plan.Name; var dayNamesList = new List <DayNameViewModel>(); foreach (var day in days) { var recipesInDay = plan.RecipePlans.Where(a => a.DayName.Id == day.Id); if (recipesInDay.Count() >= 1) { var tempDay = new DayNameViewModel { DayName = day.Name }; var recipesList = new List <RecipeView>(); foreach (var recipe in recipesInDay) { var tempRecipes = new RecipeView(); tempRecipes.Id = recipe.Recipe.Id; tempRecipes.MealName = recipe.MealName; tempRecipes.RecipeName = recipe.Recipe.Name; recipesList.Add(tempRecipes); } tempDay.RecipeList = recipesList; dayNamesList.Add(tempDay); } } toView.DayNames = dayNamesList; } else { toView = null; } //przekazujemy do widoku liczbę dodanych planów i przepisów ViewBag.AddedRecipie = _recipeService.countAddedByUser(user.UserName); ViewBag.AddedPlans = _planService.CountAddedByUser(user.UserName); ViewBag.userName = user.Name; // do _LoginPartial.cshtml return(View(toView)); }
private async void HandleOpenRecipe(IRecipe recipe) { if (recipe is null) { return; } var page = new RecipeView { BindingContext = new RecipeViewModel(recipe) }; await PushAsync(page); }
private RecipeView RecipeToView(Recipe r) { var return_me = new RecipeView { Id = r.Id, Name = r.Name, Description = r.Description }; foreach (RecipeTag rt in r.RecipeTags) { return_me.Tags.Add(rt.Tag.Name); } return(return_me); }
private void execute(object obj) { var key = obj.ToString(); if (key == RECIPE_VIEW && screens[key] == null) { screens[key] = new RecipeView(); } if (key == TRADING_VIEW && screens[key] == null) { screens[key] = new TradingView(); } LoadView(screens[key]); }
static void Main(string[] args) { //Application.UseSystemConsole = true; Application.Init (); var top = Application.Top; var win = new Window ("Recipe Navigator"){ X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () }; var dataSource = new SqliteDataSource(); productSelectorView = new ProductSelectorView(dataSource) { X = 0, Y = 0, Width = Dim.Percent(25), Height = Dim.Fill() }; recipeView = new RecipeView(dataSource) { X = Pos.Right(productSelectorView), Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; productSelectorView.ProductChanged += productId => { recipeView.SetProduct(productId); }; win.Add(productSelectorView); win.Add(recipeView); top.Add (win); Application.Run(); }
public async Task GenerateFriyayFika() { // kör koden så att det finns en recipie url var specifiedIngredients = Ingredients.CheckSpecifiedIngredients(); RecepieUrl = await RootObject.GetRandomRecipieURLAsync(specifiedIngredients); // var hej = RootObject.Results.First<Result>().Href; // Uri heej = new Uri(hej); // men varför redirectar den inte till recipieView?? var recipieView = new RecipeView(); recipieView.Navigate(RecepieUrl); // hur navigera till RecipieView?! this.Frame.Navigate(typeof(RecipeView)); }
public IActionResult Recipe([FromBody] RecipeView r) { if (ModelState.IsValid) { //automapper var recipe = new Recipe { Name = r.Name, Description = r.Description }; if (_recipe.AddRecipe(recipe)) { // see if tags exist, if not add them // then add many-many mapping via recipetag foreach (string t in r.Tags) { var result = _tags.FindTag(t); if (result == null) { result = _tags.AddTag(t); } //add the 'join' between recipe and tag _context.Add(new RecipeTag { RecipeId = recipe.Id, TagId = result.Id }); _context.SaveChanges(); } var uri = Url.Link("RecipeById", new { recipe.Id }); RecipeView rv = RecipeToView(recipe); return(Created(uri, rv)); } else { return(BadRequest("Invalid Recipe - cannot add to database")); } } else //model state is invalid { return(BadRequest("Invalid Model")); } }
private List <RecipeView> ExecuteRecipeViewSqlCmd(SqlConnection sqlConnection, SqlCommand cmd) { List <RecipeView> returnedList = new List <RecipeView>(); try { sqlConnection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { RecipeView recipeView = new RecipeView(); recipeView.RecipeId = reader.GetFieldValue <int>(0); recipeView.Name = reader.GetFieldValue <string>(1); if (!reader.IsDBNull(2)) { recipeView.ImageUrl = reader.GetFieldValue <string>(2); } else { recipeView.ImageUrl = ""; } recipeView.CategoryId = reader.GetFieldValue <int>(3); recipeView.CategoryName = reader.GetFieldValue <string>(4); returnedList.Add(recipeView); } }; } catch (Exception ex) { _logger.ErrorMessage(ex); } finally { sqlConnection.Close(); } return(returnedList); }
private void BindInfoTags(RepeaterItem item) { RecipeView recipeView = item.DataItem as RecipeView; Recipe recipe = BusinessFacade.Instance.GetRecipe(recipeView.RecipeId); HtmlGenericControl divMyFavoritesInfoTag = item.FindControl("myFavoritesInfoTag") as HtmlGenericControl; Label lblAllFavorites = item.FindControl("lblAllFavorites") as Label; Label lblAllMenus = item.FindControl("lblAllMenus") as Label; if (recipe != null) { Recipe[] ufRecipes = BusinessFacade.Instance.GetUserFavoritesRecipes(((BasePage)Page).UserId); Recipe inMyFavorites = ufRecipes.SingleOrDefault(fr => fr.RecipeId == recipe.RecipeId); if (inMyFavorites == null) { divMyFavoritesInfoTag.Visible = false; } else { divMyFavoritesInfoTag.Visible = true; } } int?allUsersFavorite = BusinessFacade.Instance.GetRecipeUserFavoritesCount(recipe.RecipeId); if (allUsersFavorite != null) { lblAllFavorites.Text = allUsersFavorite.ToString(); } int?allMenus = BusinessFacade.Instance.GetRecipeMenusCount(recipe.RecipeId); if (allMenus != null) { lblAllMenus.Text = allMenus.ToString(); } }
public async Task <ActionResult> Create(RecipeView view) { if (ModelState.IsValid) { var pic = string.Empty; var folder = "~/Content/Photos"; if (view.LogoFile != null) { pic = FileUpload.UploadPhoto(view.LogoFile, folder); pic = string.Format("{0}/{1}", folder, pic); } var recipe = ToRecipe(view); recipe.Image = pic; db.Recipes.Add(recipe); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ChefId = new SelectList(db.Chefs, "ChefId", "FirstName", view.ChefId); return(View(view)); }
public ViewAndEditRecipeWindow(RecipeView rv) { InitializeComponent(); TextBoxOptions(); ParentPanel.DataContext = this; TagDisplayer.ItemsSource = Enum.GetValues(typeof(Tag)); foreach (Object obj in TagDisplayer.Items) { foreach (Tag t in ((rv.ListBox_RecipeView.SelectedItem as Recipe).TagList)) { if (t == ((Tag)obj)) { TagDisplayer.SelectedItems.Add(obj); } } } TagDisplayer.SelectedItems.Add(TagDisplayer.Items); IngredientDisplayer.ItemsSource = Pantry.Ingredients; foreach (Object obj in IngredientDisplayer.Items) { foreach (Ingredient i in ((rv.ListBox_RecipeView.SelectedItem as Recipe).IngredientList)) { if (i.Name == ((Ingredient)obj).Name) { IngredientDisplayer.SelectedItems.Add(obj); } } } IngredientDisplayer.SelectedItems.Add(IngredientDisplayer.Items); TitleEntryTB.Text = ((Recipe)rv.ListBox_RecipeView.SelectedItem).Title; DirectionsEntryTB.Text = ((Recipe)rv.ListBox_RecipeView.SelectedItem).Directions; NotesEntryTB.Text = ((Recipe)rv.ListBox_RecipeView.SelectedItem).Notes; this.rv = rv; Enabled = false; this.Focus(); }
public void BestBeforeOrderingTest() { var ingredient1 = new IngredientView() { Title = "Ham", BestBefore = "2021-03-25", UseBy = "2021-01-01" }; var ingredient2 = new IngredientView() { Title = "Cheese", BestBefore = "2020-01-01", UseBy = "2021-01-01" }; var ingredient3 = new IngredientView() { Title = "Beans", BestBefore = "2021-04-01", UseBy = "2021-01-01" }; var lsIngredients = new List <IngredientView>() { ingredient1, ingredient2, ingredient3 }; var recipe1 = new RecipeView() { Title = "Ham Toastie", Ingredients = new List <string>() { "Ham", "Bread", "Butter" } }; var recipe2 = new RecipeView() { Title = "Cheese Toastie", Ingredients = new List <string>() { "Cheese", "Bread", "Butter" } }; var recipe3 = new RecipeView() { Title = "Beans Toastie", Ingredients = new List <string>() { "Beans", "Bread", "Butter" } }; var lsRecipes = new List <RecipeView>() { recipe1, recipe2, recipe3 }; var ingredientRepo = new TestIngredientRepository(lsIngredients); var recipeRepo = new TestRecipeRepository(lsRecipes); var recipeService = new RecipeService(recipeRepo, ingredientRepo); var result = recipeService.GetRecipes(); var lastRecipe = result[2]; Assert.Equal(recipe2, lastRecipe); }
public void Run() { Settings appSettings = new Settings(); //init settings (hardcoded- can be .json too) IFileManager fileManager = new FileManager(); UnitOfWork fileUnit = new UnitOfWork(fileManager); fileUnit.ReadFiles(); //read all tables from files to storage ITopView topView = new TopView(appSettings); //top menu plank view instance IKeyReader arrowsFull = new ArrowsKeyReader(); //key reader for categories and lists IKeyReader arrowsSimple = new SimpleReader(); //key reader for main top menu ITreePrinter <TopCategory> topPrinter = new TreeView <TopCategory>(appSettings); ITreePrinter <Category> treePrinter = new TreeView <Category>(appSettings); //tree category printer IItemsView listPrinter = new ItemsView(appSettings); //list items printer RecipeView recipeView = new RecipeView(fileUnit, topView); //to show selected recipe TreeNavigator <TopCategory> topNavigator = new TreeNavigator <TopCategory>(); TreeNavigator <Category> treeNavigator = new TreeNavigator <Category>(); //tree navigator ListNavigator listNavigator = new ListNavigator(arrowsFull, listPrinter); //list navigator IItemChooseView ingredientChooserView = new ItemChooseView(fileUnit); //view for choose ingredients new recipe IRecipeCreatorView recipeCreatorView = new RecipeCreatorView(fileUnit); //all recipe creator view IItemCreator itemCreator = new ItemCreator(topView, fileUnit); //ingredient creator view while (true) { topView.ShowMenu(string.Empty); ICategory mainMenuItem = topNavigator.Navigate(fileUnit.TopMenu.GetAll(), arrowsSimple, topPrinter, appSettings.AutoexpandTree); switch (mainMenuItem.Id) { case 1: //working with recipes ICategory recipeCategory = treeNavigator.Navigate(fileUnit.Categories.GetAll(), arrowsFull, treePrinter, appSettings.AutoexpandTree); RecipesSelector recipesSelector = new RecipesSelector(); //recipes selector for displaying if (recipeCategory == null) { break; } topView.ShowMenu(recipeCategory.Name); var recipesIn = recipesSelector.SelectRecipes(recipeCategory, fileUnit.Recipes.GetAll(), fileUnit.Categories.GetAll()); var recipeChosen = listNavigator.Navigate(recipesIn, out var action, false); if (recipeChosen == null && action == Action.Create) { Recipe newRecipe = new Recipe(); topView.ShowMenu($"Категория {recipeCategory.Name} > Новый рецепт . " + $"Выберите ингридиенты c помощью Space", true); var selectedIingredients = ingredientChooserView.Choose(listNavigator, itemCreator); //Get ingredients topView.ShowMenu($"Категория {recipeCategory.Name} > Новый рецепт "); recipeCreatorView.FillRecipe(newRecipe, selectedIingredients, recipeCategory); } if (recipeChosen != null && action == Action.Select) { recipeView.ShowRecipe(recipeChosen); } break; case 2: // working with ingredients Action action1; do { topView.ShowMenu(mainMenuItem.Name); var ingredientChosen = listNavigator.Navigate(fileUnit.Ingredients.GetListables(), out action1, false); if (ingredientChosen == null && action1 == Action.Create) { topView.ShowMenu(string.Empty); itemCreator.Create(); } } while (action1 != Action.Esc); break; case 3: fileUnit.Dispose(true); return; } } }