//Thêm Ingredient mới và o bảng Ingredient public async Task <bool> Add(IngredientDto model) { var brand = _mapper.Map <Ingredient>(model); _repoIngredient.Add(brand); return(await _repoIngredient.SaveAll()); }
private async Task CreateIngredients() { int ingredientsCount = await _ingredientRepository.Count(); if (ingredientsCount == 0) { await _ingredientRepository.Add(new Ingredient() { Title = "vodka", MeasurmentId = 1 }); await _ingredientRepository.Add(new Ingredient() { Title = "tonic", MeasurmentId = 2 }); await _ingredientRepository.Add(new Ingredient() { Title = "juice", MeasurmentId = 3 }); } }
//Thêm Ingredient mới và o bảng Ingredient public async Task <bool> Add(IngredientDto model) { var ingredient = _mapper.Map <Ingredient>(model); ingredient.isShow = true; _repoIngredient.Add(ingredient); return(await _repoIngredient.SaveAll()); }
public void Add(MealDTO mealDto) { var meal = new Meal { Name = mealDto.Name, NameForeign = mealDto.NameForeign }; _mealRepository.Add(meal, mealDto.ImageBase64); var ingredients = new List <Ingredient>(); foreach (var item in mealDto.Ingredients) { ingredients.Add(new Ingredient { Name = item.Name, NameForeign = item.NameForeign }); } _ingredientRepository.Add(ingredients); var allergens = new List <Allergen>(); foreach (var item in mealDto.Allergens) { allergens.Add(new Allergen { Name = item.Name, NameForeign = item.NameForeign }); } _allergenRepository.Add(allergens); var mealIngredients = new List <MealIngredient>(); foreach (var item in ingredients) { mealIngredients.Add(new MealIngredient { MealId = meal.Id, IngredientId = item.Id }); } _ingredientRepository.AddMealIngredients(mealIngredients); var mealAllergens = new List <MealAllergen>(); foreach (var item in allergens) { mealAllergens.Add(new MealAllergen { MealId = meal.Id, AllergenId = item.Id }); } _allergenRepository.AddMealAllergens(mealAllergens); }
public void ShouldAddIngredient() { var ingredient = IngredientBuilder.BuildIngredient(); _ingredientRepository.Add(ingredient); _ingredientRepository.Persist(); _ingredientRepository.FindOne(i => i != null).IngredientName.ShouldEqual(ingredient.IngredientName); using (var dataContext = GetNewDataContext()) { var result = dataContext.GetTable <Ingredient>().Single(i => i != null); result.IngredientName.ShouldEqual(ingredient.IngredientName); } }
public Task Add(Ingredient newIngredient) { return(Task.Run(() => { _repository.Add(newIngredient); })); }
public async Task <Ingredient> Add(Ingredient model) { var entity = _ingredientRepository.Add(model); await _ingredientRepository.SaveChangeAsync(); return(model); }
protected override void Before_all_specs() { SetupDatabase(ShopGunSpecBase.Database.ShopGun, typeof(Base).Assembly); IConfiguration configuration = new BasicConfiguration(); var container = configuration.Container; _ingredientRepository = new IngredientRepository(GetNewDataContext()); _semaphoreRepository = new Repository<Semaphore>(GetNewDataContext()); _mentorRepository = new Repository<Mentor>(GetNewDataContext()); _ingredientAdviceRepository = new Repository<IngredientAdvice>(GetNewDataContext()); _ingredientAdviceDomainService = new IngredientAdviceDomainService(_ingredientRepository, _ingredientAdviceRepository, GetNewDataContext()); _mentor = MentorBuilder.BuildMentor(); _mentorRepository.Add(_mentor); _mentorRepository.Persist(); _redSemaphore = SemaphoreBuilder.BuildRedSemaphore(); _semaphoreRepository.Add(_redSemaphore); _greenSemaphore = SemaphoreBuilder.BuildGreenSemaphore(); _semaphoreRepository.Add(_greenSemaphore); _semaphoreRepository.Persist(); _ingredient = IngredientBuilder.BuildIngredient(); _ingredientRepository.Add(_ingredient); _ingredientRepository.Persist(); base.Before_each_spec(); }
protected override void Before_all_specs() { SetupDatabase(ShopGunSpecBase.Database.ShopGun, typeof(Base).Assembly); IConfiguration configuration = new BasicConfiguration(); var container = configuration.Container; _ingredientRepository = new IngredientRepository(GetNewDataContext()); _semaphoreRepository = new Repository <Semaphore>(GetNewDataContext()); _mentorRepository = new Repository <Mentor>(GetNewDataContext()); _ingredientAdviceRepository = new Repository <IngredientAdvice>(GetNewDataContext()); _ingredientAdviceDomainService = new IngredientAdviceDomainService(_ingredientRepository, _ingredientAdviceRepository, GetNewDataContext()); _mentor = MentorBuilder.BuildMentor(); _mentorRepository.Add(_mentor); _mentorRepository.Persist(); _redSemaphore = SemaphoreBuilder.BuildRedSemaphore(); _semaphoreRepository.Add(_redSemaphore); _greenSemaphore = SemaphoreBuilder.BuildGreenSemaphore(); _semaphoreRepository.Add(_greenSemaphore); _semaphoreRepository.Persist(); _ingredient = IngredientBuilder.BuildIngredient(); _ingredientRepository.Add(_ingredient); _ingredientRepository.Persist(); base.Before_each_spec(); }
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); }
public IActionResult AddIngredientToFood(Guid foodId, [FromBody] IngredientDto ingredient) { if (ingredient == null) { return(BadRequest()); } FoodItem foodItem = _foodRepository.GetSingle(foodId); if (foodItem == null) { return(NotFound("FoodNotFound")); } var ingredientModel = _mapper.Map <Ingredient>(ingredient); ingredientModel.FoodItem = foodItem; _repository.Add(ingredientModel); if (!_repository.Save()) { throw new Exception($"Creating a ingredients for food {foodId} failed on save."); } var ingredientToReturn = _mapper.Map <IngredientDto>(ingredientModel); _hubContext.Clients.All.SendAsync("ingredient-added", foodId, ingredientToReturn); return(CreatedAtRoute(nameof(GetSingleIngredient), new { foodId = foodId, id = ingredientToReturn.Id }, ingredientToReturn)); }
/// <summary> /// Creates a new Ingredient and returns it. If an Ingredient or an AlternativeIngredientName with the same name already exist, null is returned. /// </summary> /// <param name="ingredientName"></param> /// <returns></returns> public Ingredient CreateIngredient(string ingredientName) { var alternativeNameRepostory = _repositoryFactory.Build <IRepository <AlternativeIngredientName>, AlternativeIngredientName>(); if (string.IsNullOrEmpty(ingredientName) || _ingredientRepository.Find(i => i.IngredientName == ingredientName).Any() || alternativeNameRepostory.Find(ain => ain.AlternativeName == ingredientName).Any()) { return(null); } var ingredient = new Ingredient { IngredientName = ingredientName }; _ingredientRepository.Add(ingredient); _ingredientRepository.Persist(); return(ingredient); }
public async Task <ActionResult> AddItemToFridge(int id, [FromBody] Ingredient newIgredient) { Fridge fridge = await _repo.GetFridge(id); IngredientDto newIngredientDto = await _ingredientRepo.GetIngredientsFromAPI(newIgredient.Id); string image = newIngredientDto.image; _ingredientRepo.Add(newIgredient, fridge, image); return(Ok()); }
/// <summary> /// Part 2 to add ingredient entry to table /// uses session ID(part 1) and foodID from view to set ingredient properties, then adds them /// </summary> /// <param name="id">food ID from view linked</param> /// <returns>View back to list</returns> public ActionResult AddFoodId(int id) { ingredient.FoodID = id; int ri = (int)Session["RecipeID"]; ingredient.RecipeID = ri; ingredientRepository.Add(ingredient); ingredientRepository.Save(); Recipe r = recipeRepository.GetRecipeID(ri); return(View("Details", r)); }
public async Task <ActionResult> Add([FromBody] IngredientModel ingredient) { var result = await _ingredientRepository.Add(ingredient); if (!result.Item2) { return(StatusCode(500, new ErrorModel { ErrorMessage = result.Item1 })); } return(StatusCode(201, result.Item3)); }
private async void OnImportDietAsync(object p) { var meals = await importExportService.ImportAsync <Meal>(); Meals.ToList().ForEach(m => mealRepository.Remove(m)); Meals.Clear(); meals.ToList().ForEach(m => { m.Ingregients.ToList().ForEach(i => ingredientRepository.Add(i)); mealRepository.Add(m); Meals.Add(m); }); mealRepository.SaveChangesAsync(); CalcTotalNutritionFact(); }
public CreateResponse Create(IngredientRequest request) { try { var ingredient = TypeAdapter.Adapt <Ingredient>(request); _ingredientValidator.ValidateAndThrowException(ingredient, "Base"); _ingredientRepository.Add(ingredient); return(new CreateResponse(ingredient.Id)); } catch (DataAccessException) { throw new ApplicationException(); } }
public int CopyIngredient(int ingredientId) { var model = _ingredientRepository.GetIngredient(ingredientId); var newIngredient = new Ingredient() { ItemId = model.ItemId, //Unit = model.Unit, Measure = null }; int newid = _ingredientRepository.Add(newIngredient); return(newid); }
public void AddIngredient(Ingredient ingredient) { if (!_ingredientRepository.ExistsByName(ingredient.Name)) { _ingredientRepository.Add(ingredient); return; } var existingIngredient = _ingredientRepository.FindByName(ingredient.Name); ingredient.Id = existingIngredient.Id; ingredient.Stock += existingIngredient.Stock; _ingredientRepository.Update(existingIngredient.Id, ingredient); }
public async Task <IActionResult> CreateAsync([FromBody] Ingredient ingredient) { if (!ModelState.IsValid) { return(BadRequest()); } try { await _iIngredientRepository.Add(ingredient); return(Ok()); } catch (Exception) { return(BadRequest()); } }
public IActionResult Add(MealIngredientViewModel model) { var newModel = new Ingredient(); newModel.ItemId = model.ItemId; newModel.Measure = model.Measure; //newModel.Unit = model.Unit; var newId = _ingredientRepository.Add(newModel); var newIMModel = new MealIngredient(); newIMModel.IngredientId = newId; newIMModel.MealId = model.MealId; _mealingredientRepository.Add(newIMModel); return(RedirectToAction("Index", "MealIngredient", new { id = newIMModel.MealId })); }
public IActionResult AddIngredientToFood(Guid foodId, [FromBody] IngredientDto ingredient) { if (ingredient == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } FoodItem foodItem = _foodRepository.GetSingle(foodId); if (foodItem == null) { return(NotFound("FoodNotFound")); } var ingredientModel = Mapper.Map <Ingredient>(ingredient); ingredientModel.FoodItem = foodItem; _repository.Add(ingredientModel); if (!_repository.Save()) { throw new Exception($"Creating a ingredients for food {foodId} failed on save."); } var ingredientToReturn = Mapper.Map <IngredientDto>(ingredientModel); return(CreatedAtRoute("GetIngredientForFood", new { foodId = foodId, id = ingredientToReturn.Id }, ingredientToReturn)); }
public async Task AddIngredient(AddIngredientRequestModel addIngredient) { var newIngredient = _mapper.Map <Ingredient>(addIngredient); await _ingredientRepository.Add(newIngredient); }
public Ingredient Add(Ingredient ingredient) { return(_ingredientRepo.Add(ingredient)); }
public ActionResult <Ingredient> Post(Ingredient content) { return(_contentRepository.Add(content)); }
public void CreateIngredient(IngredientDto ingredientDto) { var ingredient = ingredientDto.MappingIngredient(); ingredientRepository.Add(ingredient); }
public IActionResult Add(Ingredient model) { _ingredientRepository.Add(model); return(View()); }