private void addShoppingButton_Click(object sender, RoutedEventArgs e) { Igredient igredient = new Igredient(); igredient.NAME = igredientNameTextBox.Text; if (igredient.NAME.Length == 0) { notiMessageSnackbar.MessageQueue.Enqueue("Không được bỏ trống tên nguyên liệu", "Cancel", () => { }); return; } else { //Do Nothing } igredient.QUANTITY = igredientQuantityTextBox.Text; if (igredient.QUANTITY.Length == 0) { notiMessageSnackbar.MessageQueue.Enqueue("Không được bỏ trống số lượng nguyên liệu", "Cancel", () => { }); return; } else { //Do Nothing } igredientNameTextBox.Text = ""; igredientQuantityTextBox.Text = ""; recipe.Igredients.Add(igredient); igredientsListView.ItemsSource = recipe.Igredients.ToList(); }
public bool ContainsIgredient(IEnumerable <Igredient> igredientList, Igredient igredientParam) { foreach (Igredient igredient in igredientList) { if (igredient == igredientParam) { return(true); } } return(false); }
public AddViewModel() { Recipe = new Recipe() { Image = "addImage" }; Igredient = new Igredient() { Name = String.Empty, Unit = null, Quantity = 0 }; igredientList = new List <Igredient>(); Units = new List <string>() { "kg", "dag", "g", "l", "ml", "szt" }; TakePhoto = new Command(takePhoto); PickPhoto = new Command(pickPhoto); AddIgredient = new Command(addIgredient); RemoveIgredient = new Command(removeIgredient); AddRecpie = new Command(addRecpie); }
private void addIgredient() { if (Igredient.Name == null || Igredient.Quantity <= 0 || Igredient.Unit == null) { return; } int index; if (Int32.TryParse(Igredient.Unit, out index)) { Igredient.Unit = Units[index]; } igredientList.Add(Igredient); OnPropertyChanged("IgredientListString"); Igredient = new Igredient() { Name = igredient.Name, Quantity = igredient.Quantity, Unit = igredient.Unit }; }
public ActionResult Save(NewDishViewModel newDish, HttpPostedFileBase image1) { if (ModelState.IsValid) { // Checking if the dish alredy exists if (newDish.DishId == 0) { var dish = new Dish(); dish.Name = newDish.Name; dish.Description = newDish.Description; dish.Price = newDish.Price; dish.IsPescatarian = newDish.IsPescatarian; dish.IsVegan = newDish.IsVegan; dish.IsVegetarian = newDish.IsVegetarian; dish.HasPeanuts = newDish.HasPeanuts; dish.HasSeafood = newDish.HasSeafood; dish.Enabled = true; // Seting up the image as byte array if (image1 != null) { dish.Image = new byte[image1.ContentLength]; image1.InputStream.Read(dish.Image, 0, image1.ContentLength); } foreach (var item in newDish.Igredients) { if (item.IsChecked == true) { // Same as below Igredient ig = igredientRepo.GetById(item.IgredientId); dish.Igredients.Add(ig); } } try { dishRepo.Insert(dish); log.Info("New dish named " + newDish.Name + " was created"); } catch (Exception e) { log.Error(e.Message); return(View("Error", new HandleErrorInfo(new Exception("Dish not saved"), "Chef", "Save"))); } } else { // If dish already exists in database var dishInDb = dishRepo.GetById(newDish.DishId); dishInDb.Name = newDish.Name; dishInDb.Description = newDish.Description; dishInDb.Price = newDish.Price; dishInDb.IsPescatarian = newDish.IsPescatarian; dishInDb.IsVegan = newDish.IsVegan; dishInDb.IsVegetarian = newDish.IsVegetarian; dishInDb.HasPeanuts = newDish.HasPeanuts; dishInDb.HasSeafood = newDish.HasSeafood; dishInDb.Enabled = true; if (image1 != null) { dishInDb.Image = new byte[image1.ContentLength]; image1.InputStream.Read(dishInDb.Image, 0, image1.ContentLength); } // Reset ingredients i the existing dish dishInDb.Igredients.Clear(); foreach (var item in newDish.Igredients) { if (item.IsChecked == true) { // Should not create new igredients but take those from db Igredient ig = igredientRepo.GetById(item.IgredientId); dishInDb.Igredients.Add(ig); } } log.Info("Dishish named " + dishInDb.Name + " was edited"); } try { dishRepo.Save(); return(RedirectToAction("Index", "Chef")); } catch (Exception e) { log.Error(e.Message); return(View("Error", new HandleErrorInfo(new Exception("Dish not saved"), "Chef", "Save"))); } } else { // In case of not valid form data return(View("SaveDish", newDish)); } }