private ItemIngredient GetItemIngredient(int id, out bool cachedAdd, out bool cachedChange, out bool cachedRemove) { cachedAdd = false; cachedChange = false; cachedRemove = false; foreach (ItemIngredient itemIngredient in _itemIngredientsAdded.Where(itemIngredient => itemIngredient.Id == id)) { cachedAdd = true; return(itemIngredient); } foreach (ItemIngredient itemIngredient in _itemIngredientsNeedingUpdate.Where(itemIngredient => itemIngredient.Id == id)) { cachedChange = true; return(itemIngredient); } foreach (ItemIngredient itemIngredient in _itemIngredientsRemoved.Where(itemIngredient => itemIngredient.Id == id)) { cachedRemove = true; return(itemIngredient); } return(ItemIngredient.Get(id)); }
public void Update(int itemId) { // Added Ingredients foreach (ItemIngredient itemIngredient in _itemIngredientsAdded) { itemIngredient.SetItemId(itemId); itemIngredient.Update(); ItemIngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, itemId, itemIngredient.IngredientId, null, itemIngredient.Amount, itemIngredient.MeasurementUnit); } // Changed Ingredients foreach (ItemIngredient itemIngredient in _itemIngredientsNeedingUpdate) { ItemIngredient original = ItemIngredient.Get(itemIngredient.Id); double oldAmount = UnitConversion.Convert(original.Amount, original.MeasurementUnit, itemIngredient.MeasurementUnit); itemIngredient.Update(); ItemIngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, itemId, itemIngredient.IngredientId, oldAmount, itemIngredient.Amount, itemIngredient.MeasurementUnit); } // Removed Ingredients foreach (ItemIngredient itemIngredient in _itemIngredientsRemoved) { ItemIngredient.Delete(itemIngredient.Id); ItemIngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, itemId, itemIngredient.IngredientId, itemIngredient.Amount, null, itemIngredient.MeasurementUnit); } _itemIngredientsAdded.Clear(); _itemIngredientsNeedingUpdate.Clear(); _itemIngredientsRemoved.Clear(); }
private void buttonAdd_Click(object sender, RoutedEventArgs e) { FormattedListBoxItem selectedItem = listBox.SelectedItem as FormattedListBoxItem; if (selectedItem == null) { return; } PosDialogWindow window = IngredientAmountControl.CreateInDefaultWindow(Strings.ItemEditorIngredientAmount); IngredientAmountControl control = window.DockedControl as IngredientAmountControl; PosDialogWindow parent = Window.GetWindow(this) as PosDialogWindow; Ingredient ingredient = Ingredient.Get(selectedItem.Id); control.Amount = 0; control.MeasurementUnit = ingredient.MeasurementUnit; window.ShowDialog(parent); if (!window.ClosedByUser && (control.Amount > 0)) { _itemIngredientsAdded.Add( ItemIngredient.Add(0, selectedItem.Id, control.Amount, control.MeasurementUnit)); InitializeFields(); DoValueChangedEvent(); } }
/// <summary> /// Adds an ingredient to the shopping list, in the group with the given name. /// </summary> /// <param name="ingredient">The ingredient.</param> /// <param name="groupName">Name of the group.</param> public void AddIngredientToShoppingList(Ingredient ingredient, String groupName) { ItemIngredient itemIngredient = ToolItem.CreateItemIngredient(ingredient); itemIngredient.Group = groupName; this.ShoppingList[groupName].Items.Add(itemIngredient); this.RefreshViews(new AddedIngredientEvent(this, ingredient, groupName)); }
public async Task <ActionResult> DeleteConfirmed(int id) { ItemIngredient itemIngredient = await this.Context.ItemIngredients.FindAsync(id); this.Context.ItemIngredients.Remove(itemIngredient); await this.Context.SaveChangesAsync(); return(RedirectToAction("Index")); }
private void AddIngredientSetToListBox(ItemIngredient itemIngredient, Ingredient ingredient) { string amount = FormatSingleToString(itemIngredient.Amount); string tagLine = ingredient.FullName + Environment.NewLine + Strings.ItemEditorAmount + amount + " " + itemIngredient.MeasurementUnit.ToString() + ((amount.Equals("1.0") ? "" : Strings.S)); listBoxItemIngredients.Items.Add(new FormattedListBoxItem(itemIngredient.Id, tagLine, true)); }
public async Task <ActionResult> Edit([Bind(Include = "ItemIngredientId,Quantity,ItemId,IngredientItemId")] ItemIngredient itemIngredient) { if (ModelState.IsValid) { this.Context.Entry(itemIngredient).State = EntityState.Modified; await this.Context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.IngredientItemId = new SelectList(this.Context.Items, "ItemId", "Name", itemIngredient.IngredientItemId); ViewBag.ItemId = new SelectList(this.Context.Items, "ItemId", "Name", itemIngredient.ItemId); return(View(itemIngredient)); }
public void Cancel() { foreach (ItemIngredient itemIngredient in _itemIngredientsAdded) { ItemIngredient.Delete(itemIngredient.Id); } _itemIngredientsAdded.Clear(); _itemIngredientsNeedingUpdate.Clear(); _itemIngredientsRemoved.Clear(); // Reset UI InitializeFields(); }
// GET: ItemIngredients/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ItemIngredient itemIngredient = await this.Context.ItemIngredients.FindAsync(id); if (itemIngredient == null) { return(HttpNotFound()); } return(View(itemIngredient)); }
public static void AdjustInventoryByItem(int itemId, double itemPortionSize, bool increase) { if (itemId > 0) { foreach (ItemIngredient itemIngredientIngredient in ItemIngredient.GetAll(itemId)) { AdjustInventoryByIngredient( itemIngredientIngredient.IngredientId, increase, itemIngredientIngredient.Amount * itemPortionSize, itemIngredientIngredient.MeasurementUnit); } } }
// GET: ItemIngredients/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ItemIngredient itemIngredient = await this.Context.ItemIngredients.FindAsync(id); if (itemIngredient == null) { return(HttpNotFound()); } ViewBag.IngredientItemId = new SelectList(this.Context.Items, "ItemId", "Name", itemIngredient.IngredientItemId); ViewBag.ItemId = new SelectList(this.Context.Items, "ItemId", "Name", itemIngredient.ItemId); return(View(itemIngredient)); }
/// <summary> /// Handles the Click event of the RemoveIngredient control. Removes an ingredient from the corresponding group of the shopping list. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private async void RemoveIngredient_Click(object sender, RoutedEventArgs e) { if (sender is Button) { Button but = (Button)sender; ItemIngredient item = (ItemIngredient)but.DataContext; this.model.RemoveIngredientFromShoppingList(item, item.Group); StorageFolder folder = KnownFolders.PicturesLibrary; StorageFile shoppingListFile = await folder.CreateFileAsync("shoppingList.json", CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteTextAsync(shoppingListFile, this.model.StringifyShoppingList()); PreparePrintContent(); } }
// Button add + private void OnClickAddIngredient(object sender, RoutedEventArgs e) { ItemIngredient ingr = new ItemIngredient(); //ingr = ((Button)sender).Content as ItemIngredient; Button bt = sender as Button; int index = (int)bt.Tag; ingr = icItem.Items[index] as ItemIngredient; var content = ((Button)sender).Content; var item = itemIngredientLocal.FirstOrDefault(i => i.IdIngredient == ingr.IdIngredient); if (item != null) { item.Ingredient_quantity = item.Ingredient_quantity + 1; if (ingr.Ingredient_category_id == 3) { item.Ingredient_price += item.Ingredient_price; } tb_value.Text = item.Ingredient_quantity.ToString(); content = item.Ingredient_quantity.ToString(); ingr.Ingredient_quantity = item.Ingredient_quantity; } else { itemIngredientLocal.Add(new ItemIngredient() { IdItem = ingr.IdItem, IdIngredient = ingr.IdIngredient, Item_title = ingr.Item_title, Ingredient_title = ingr.Ingredient_title, Ingredient_price = ingr.Ingredient_category_id == 3 ? ingr.Ingredient_price : 0, Ingredient_quantity = 1 }); ingr.Ingredient_quantity = 1; } // tb_value.Text = cvm.IngredientCounter.ToString(); }
private void RemoveItemIngredient(int id) { bool added, changed, removed; ItemIngredient itemIngredient = GetItemIngredient(id, out added, out changed, out removed); if (added) { _itemIngredientsAdded.Remove(itemIngredient); } if (changed) { _itemIngredientsNeedingUpdate.Remove(itemIngredient); } if (!added && !removed) { _itemIngredientsRemoved.Add(itemIngredient); } }
private void InitializeFields() { listBox.SelectedItem = null; listBoxItemIngredients.SelectedItem = null; listBox.Items.Clear(); listBoxItemIngredients.Items.Clear(); List <Ingredient> ingredients = new List <Ingredient>(_cachedIngredients); if (ActiveItem != null) { foreach (ItemIngredient itemIngredient in ItemIngredient.GetAll(ActiveItem.Id)) { bool added, changed, removed; ItemIngredient current = GetItemIngredient(itemIngredient.Id, out added, out changed, out removed); if (!removed) { Ingredient ingredient = Ingredient.Find(ingredients, itemIngredient.IngredientId); AddIngredientSetToListBox( (changed ? current : itemIngredient), ingredient); ingredients.Remove(ingredient); } } } // Note: Added ones have an ItemId of zero so GetAll (above) will not find them foreach (ItemIngredient itemIngredient in _itemIngredientsAdded) { Ingredient ingredient = Ingredient.Find(ingredients, itemIngredient.IngredientId); AddIngredientSetToListBox(itemIngredient, ingredient); ingredients.Remove(ingredient); } foreach (Ingredient ingredient in ingredients) { listBox.Items.Add(new FormattedListBoxItem(ingredient.Id, ingredient.FullName, true)); } SetButtonsEnabled(); }
private void buttonAmount_Click(object sender, RoutedEventArgs e) { FormattedListBoxItem selectedItem = (FormattedListBoxItem)listBoxItemIngredients.SelectedItem; bool added = false, changed = false, removed = false; ItemIngredient itemIngredient = GetItemIngredient(selectedItem.Id, out added, out changed, out removed); Ingredient ingredient = Ingredient.Get(itemIngredient.IngredientId); PosDialogWindow window = IngredientAmountControl .CreateInDefaultWindow(Strings.ItemEditorEditIngredient); IngredientAmountControl control = window.DockedControl as IngredientAmountControl; PosDialogWindow parent = Window.GetWindow(this) as PosDialogWindow; control.Amount = itemIngredient.Amount; control.MeasurementUnit = itemIngredient.MeasurementUnit; window.ShowDialog(parent); if (!window.ClosedByUser) { if (control.Amount > 0) { itemIngredient.SetAmount(control.Amount); itemIngredient.SetMeasurementUnit(control.MeasurementUnit); if (!added && !changed) { _itemIngredientsNeedingUpdate.Add(itemIngredient); } } else { RemoveItemIngredient(selectedItem.Id); } listBox.SelectedItem = null; InitializeFields(); DoValueChangedEvent(); } }
// Button sub - private void OnClickSubstractIngredient(object sender, RoutedEventArgs e) { ItemIngredient ingr = new ItemIngredient(); ingr = ((Button)sender).Tag as ItemIngredient; var item = itemIngredientLocal.FirstOrDefault(i => i.IdIngredient == ingr.IdIngredient); if (item != null) { if (item.Ingredient_quantity == 1) { itemIngredientLocal.Remove(item); ingr.Ingredient_quantity = 0; } else { item.Ingredient_quantity = item.Ingredient_quantity - 1; item.Ingredient_price -= item.Ingredient_price; ingr.Ingredient_quantity = item.Ingredient_quantity; } } }
public ObservableCollection <Cart> GetOrderDetail(int id) { if (BddOk) { using (ModelCezar db = new ModelCezar()) { //var orderDetailQuery = (from itmSel in db.item_selection // join itm in db.ITEM on itmSel.id_item equals itm.id_item // join ing in db.INGREDIENT on itmSel.id_ingredient equals ing.id_ingredient // where itmSel.id_orders == id // select new Cart() // { // ItemId = itm.id_item, // ItemTitle = itm.item_title, // ItemQuantity = (int)(itm.item_quantity == null ? 1 : itm.item_quantity) // }); ObservableCollection <ItemIngredient> ingredients = new ObservableCollection <ItemIngredient>(); ObservableCollection <Cart> cart = new ObservableCollection <Cart>(); ItemIngredient itg = new ItemIngredient(); List <int> idItem = new List <int>(); //var res = (from selection in db.item_selection where selection.id_orders == id select selection).ToList(); var res = ( from itmSel in db.item_selection join itm in db.ITEM on itmSel.id_item equals itm.id_item join ing in db.INGREDIENT on itmSel.id_ingredient equals ing.id_ingredient into ingredient from x in ingredient.DefaultIfEmpty() where itmSel.id_orders == id select new { itmSel }).ToList(); var test = res; foreach (var var in res.GroupBy(x => x.itmSel.ITEM.id_item).Select(s => s.First()).ToList()) { var ingred = test.Where(z => z.itmSel.id_item == var.itmSel.id_item).ToList(); if (ingred != null) { foreach (var i in ingred) { if (i.itmSel.INGREDIENT != null) { ingredients.Add(new ItemIngredient() { IdIngredient = i.itmSel.INGREDIENT.id_ingredient, Ingredient_title = i.itmSel.INGREDIENT.ingredient_title }); } } cart.Add(new Cart() { ItemId = var.itmSel.id_item, ItemTitle = var.itmSel.ITEM.item_title, ItemQuantity = (int)(var.itmSel.item_selection_quantity == null ? 1 : var.itmSel.item_selection_quantity), SelectedIngredients = ingredients }); } else { cart.Add(new Cart() { ItemId = var.itmSel.id_item, ItemTitle = var.itmSel.ITEM.item_title, ItemQuantity = (int)(var.itmSel.item_selection_quantity == null ? 1 : var.itmSel.item_selection_quantity), }); } ingredients = new ObservableCollection <ItemIngredient>(); } //var result = (from order in db.ORDERS // from itmSel in order.item_selection // join itm in db.ITEM on itmSel.id_item equals itm.id_item // join ing in db.INGREDIENT.DefaultIfEmpty() on itmSel.id_ingredient equals ing.id_ingredient // where order.id_orders == id // select new // { // itmSel // }).ToList(); //var orderDetailQuery = (from itmSel in db.item_selection // join order in db.ORDERS on itmSel.id_orders equals order.id_orders // join itm in db.ITEM on itmSel.id_item equals itm.id_item // join ing in db.INGREDIENT.DefaultIfEmpty() on itmSel.id_ingredient equals ing.id_ingredient // where order.id_orders == id // select new // { // itmSel // }) // .ToList(); //foreach (var item in result) //{ // //GroupBy(x => x.itmSel.ITEM.id_item).Select(s => s.First()).ToList() // if (item.itmSel.INGREDIENT.id_ingredient > 0) // { // ingredients.Add(new ItemIngredient() // { // IdIngredient = item.itmSel.INGREDIENT.id_ingredient, // Ingredient_title = item.itmSel.INGREDIENT.ingredient_title // }); // cart.Add(new Cart() // { // ItemId = item.itmSel.ITEM.id_item, // ItemTitle = item.itmSel.ITEM.item_title, // SelectedIngredients = ingredients // }); // } // else // { // cart.Add(new Cart() // { // ItemId = item.itmSel.ITEM.id_item, // ItemTitle = item.itmSel.ITEM.item_title, // }); // } //} return(cart); } } else { return(null); } }
/// <summary> /// Removes an ingredient from the shopping list, in the group with the given name. /// </summary> /// <param name="itemIngredient">The item ingredient.</param> /// <param name="groupName">Name of the group.</param> public void RemoveIngredientFromShoppingList(ItemIngredient itemIngredient, String groupName) { this.ShoppingList[groupName].Items.Remove(itemIngredient); this.RefreshViews(new RemovedIngredientEvent(this, itemIngredient.Ingredient, groupName)); }
// Cette méthode est appelée lorsque l'utilisateur veut modifier un article ajouter dans le panier public ItemOption(Cart list, int idItem, int index, List <CATEGORY_INGREDIENT> catIng, ObservableCollection <ItemIngredient> ingredients) { InitializeComponent(); counter = 0; if (index > -1) { indexLocal = index; db = new ModelCezar(); _cart = list; lst = list.SelectedIngredients; if (catIng.Count <= 1) { bt_NextOption.Visibility = Visibility.Collapsed; } bt_BackOption.Visibility = Visibility.Collapsed; itemLocal.id_item = list.ItemId; itemLocal.item_price = (decimal)list.ItemPriceWithoutSupp; itemLocal.item_title = list.ItemTitle; itemLocal.cooked = list.Cooked; catIngLocalCount = catIng.Count; catIngLocal = catIng; CATEGORY_INGREDIENT ci = new CATEGORY_INGREDIENT(); ci = catIng[counter]; int id = catIng[counter].id_category_ingredient; var optionQuery = (from ing in db.INGREDIENT join ingCat in db.CATEGORY_INGREDIENT on ing.id_category_ingredient equals ingCat.id_category_ingredient select new ItemIngredient() { IdItem = idItem, IdIngredient = ing.id_ingredient, Ingredient_category_tutle = ingCat.category_ingredient_title, Item_title = list.ItemTitle, Ingredient_category_id = ingCat.id_category_ingredient, Ingredient_title = ing.ingredient_title, Ingredient_price = (double)ing.ingredient_price, Ingredient_quantity = 0 }); listIngredient = new ObservableCollection <ItemIngredient>(optionQuery.ToList()); icItem.ItemsSource = listIngredient.Where(i => i.Ingredient_category_id == id); ItemIngredient ingrr = new ItemIngredient(); for (int i = 0; i < listIngredient.Count; i++) { ingrr = listIngredient[i] as ItemIngredient; foreach (var itm in ingredients) { if (ingrr.IdIngredient == itm.IdIngredient) { itemIngredientLocal.Add(new ItemIngredient() { IdItem = itm.IdItem, IdIngredient = itm.IdIngredient, Item_title = itm.Item_title, Ingredient_title = itm.Ingredient_title, Ingredient_price = itm.Ingredient_category_id == 3 ? ingrr.Ingredient_price : 0, Ingredient_quantity = itm.Ingredient_quantity }); ingrr.Ingredient_quantity = itm.Ingredient_quantity; break; } } } #region COMMENT //var reqForMeat = (from ing in db.INGREDIENT.Where(i => i.ITEM.Any() && i.id_category_ingredient == 1) // from itm in db.ITEM.Where(it => it.INGREDIENT.Contains(ing) && it.id_item == idItem) // select new ItemIngredient() // { // IdItem = itm.id_item, // IdIngredient = ing.id_ingredient, // Item_title = itm.item_title, // Ingredient_title = ing.ingredient_title, // Ingredient_quantity = 0 // }); // var reqForMeat = (from ing in db.INGREDIENT.Where(i => i.ITEM.Any() && i.id_category_ingredient == 1) // from itm in db.ITEM.Where(it => it.INGREDIENT.Contains(ing) && it.id_item == idItem) // select new ItemIngredient() // { // IdItem = itm.id_item, // IdIngredient = ing.id_ingredient, // Item_title = itm.item_title, // Ingredient_title = ing.ingredient_title, // Ingredient_quantity = 0 // } //); // tb_optionTitle.Text = "Options " + itemLocal.item_title; // var reqForSauce = (from ing in db.INGREDIENT.Where(i => i.ITEM.Any() && i.id_category_ingredient == 2) // from itm in db.ITEM.Where(it => it.INGREDIENT.Contains(ing) && it.id_item == idItem) // select new ItemIngredient() // { // IdItem = itm.id_item, // IdIngredient = ing.id_ingredient, // Item_title = itm.item_title, // Ingredient_title = ing.ingredient_title, // Ingredient_quantity = 0 // } //); // var reqForSupp = (from ing in db.INGREDIENT.Where(i => i.ITEM.Any() && i.id_category_ingredient == 3) // from itm in db.ITEM.Where(it => it.INGREDIENT.Contains(ing) && it.id_item == idItem) // select new ItemIngredient() // { // IdItem = itm.id_item, // IdIngredient = ing.id_ingredient, // Item_title = itm.item_title, // Ingredient_title = ing.ingredient_title, // Ingredient_price = (double)ing.ingredient_price, // Ingredient_quantity = 0 // } //); // lb_choixViande.ItemsSource = new ObservableCollection<ItemIngredient>(reqForMeat.ToList()); // lb_choixSauce.ItemsSource = new ObservableCollection<ItemIngredient>(reqForSauce.ToList()); // lb_choixSupp.ItemsSource = new ObservableCollection<ItemIngredient>(reqForSupp.ToList()); #endregion } // lb_choixViande.SelectedIndex = lb_choixViande.Items.IndexOf(lst[0].Ingredient_title) }