public ManagerViewFood(Food food) { InitializeComponent(); var context = new MSSQLContext(); FoodImage.Source = WorkWithImage.ConvertArrayByteToImage(food.Image); NameFood.Text = food.Name; Category.Text = context.Categories.Find(food.CategoryId).Name; Price.Text = food.CurrentPrice.ToString(); InMenu.IsChecked = food.InMenu; Description.Text = food.Description; this.food = food; var structures = context.Structures.Where(s => s.FoodId == food.Id).ToList(); foreach (var currentStructure in structures) { if (structures.IndexOf(currentStructure) == structures.Count) { Ingredients.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + "."; } else { Ingredients.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + " ,"; } } context.Database.Connection.Close(); }
public UserViewFood(Food currentFood, List <FoodInBasket> basket, Button basketButton) { InitializeComponent(); Price.Text = currentFood.CurrentPrice.ToString(); FoodDescription.Text = currentFood.Description; AddToBasket.IsEnabled = Validation.CanUserBuy(basket, currentFood); foodImage.Source = WorkWithImage.ConvertArrayByteToImage(currentFood.Image); using (var context = new MSSQLContext()) { var structures = context.Structures.Where(s => s.FoodId == currentFood.Id) .Include(s => s.Ingredient) .ToList(); foreach (var currentStructure in structures) { if (structures.IndexOf(currentStructure) == structures.Count) { FoodStruct.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + $" {currentStructure.Quantity} {currentStructure.Ingredient.Unit}."; } else { FoodStruct.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + $" {currentStructure.Quantity} {currentStructure.Ingredient.Unit},"; } } } this.basket = basket; this.currentFood = currentFood; this.basketButton = basketButton; }
private void LoadFood() { using (MSSQLContext context = new MSSQLContext()) { foreach (var item in context.Structures.Where(s => s.FoodId == food.Id).ToList()) { model.Add(new IngredientsModel() { CookingStep = item.CookingStep, Unit = item.Ingredient.Unit, Weight = item.Quantity, IngredientName = item.Ingredient.Name }); } Table.ItemsSource = model; AddFood.IsEnabled = false; AddFood.Visibility = Visibility.Hidden; Name.Text = food.Name; Category.Text = context.Categories.Find(food.CategoryId).Name; Image.Source = WorkWithImage.ConvertArrayByteToImage(food.Image); } }
private void LoadFood(int category = 0, string name = "") { bool checkIngredients; Menu.Items.Clear(); using (var context = new MSSQLContext()) { foreach (var food in listFood) { checkIngredients = true; var structures = context.Structures.Where(s => s.FoodId == food.Id).ToList(); foreach (var currentStructure in structures) { bool exist = false; foreach (var ingredient in listIngredients) { exist = ingredient.Id == currentStructure.IngredientId; if (exist) { break; } } if (!exist) { checkIngredients = false; break; } } if (!checkIngredients) { continue; } if (food.CategoryId != category && category != 0) { continue; } if (!food.Name.StartsWith(name) && name != "") { continue; } var stackpanel = new StackPanel() { Orientation = Orientation.Horizontal }; Label label = new Label() { Content = food.Name, Foreground = Brushes.White, FontWeight = FontWeights.DemiBold, FontSize = 16, VerticalAlignment = VerticalAlignment.Center }; Image img = new Image() { Source = WorkWithImage.ConvertArrayByteToImage(food.Image), }; var button = new Button() { Name = "Name" + food.Id.ToString(), IsEnabled = true, Foreground = Brushes.White, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(5), Content = $"{food.Name}", }; stackpanel.Children.Add(img); stackpanel.Children.Add(label); stackpanel.Children.Add(button); button.Click += EventForFood; Menu.Items.Add(stackpanel); } } }