private List <LunchIngredient> ConvertIngredientViewModelsToIngredienten(List <IngredientViewModel> ingredientvms) { List <LunchIngredient> ingredienten = new List <LunchIngredient>(); Debug.WriteLine(ingredientvms.Count); foreach (IngredientViewModel ivm in ingredientvms) { Ingredient ingredient = _ingredientRepository.GetByName(ivm.Naam); if (ingredient == null) { ingredient = new Ingredient { Naam = ivm.Naam }; _ingredientRepository.Add(ingredient); _ingredientRepository.SaveChanges(); } LunchIngredient lunchIngredient = new LunchIngredient { Ingredient = ingredient }; ingredienten.Add(lunchIngredient); } return(ingredienten); }
private static void SelectCoffee() { Console.Write("Please, insert coffee id: "); string a; int id; do { a = Console.ReadLine(); if (a == "") { sum = 0; StartFromInsertingCoins(); } int.TryParse(a, out id); if (id == 0 || coffeeRepo.GetById(id) == null) { Console.Write("Please, insert correct id: "); } else if (sum < coffeeRepo.GetById(id).Price) { Console.Write("You didn't insert enough money for this coffee, please choose another coffee or type enter to restart: "); } } while (id == 0 || coffeeRepo.GetById(id) == null || sum < coffeeRepo.GetById(id).Price); coffee = coffeeRepo.GetById(id); if (CheckIngredients("Sugar") && CheckIngredients("Coffee") && CheckIngredients("Water")) { order.Coffee = coffee; order.CoffeeId = coffee.Id; ingredientRepo.GetByName("Sugar").Quantity -= coffee.SugarPortion; ingredientRepo.Update(ingredientRepo.GetByName("Sugar")); ingredientRepo.GetByName("Water").Quantity -= coffee.WaterPortion; ingredientRepo.Update(ingredientRepo.GetByName("Water")); ingredientRepo.GetByName("Coffee").Quantity -= coffee.CoffeePortion; ingredientRepo.Update(ingredientRepo.GetByName("Coffee")); } }
public async Task <IEnumerable <IngredientDto> > GetByName(string name) { if (name.Equals("null")) { var ingredients = await _ingredientRepository.GetAll(); return(_mapper.Map <IEnumerable <IngredientDto> >(ingredients)); } else { var ingredient = await _ingredientRepository.GetByName(name); return(_mapper.Map <IEnumerable <IngredientDto> >(ingredient)); } }