/// <summary>
        /// Adds an Ingredient to the database.
        /// An Ingredient will only be added if certain criteria have been fulfilled.
        /// If not, an error will be shown.
        /// </summary>
        private void AddIngredient()
        {
            try
            {
                if (Action == "add")
                {
                    _ingredientRepo.AddIngredient(Business.Ingredient.ConvertToNewDataIngredient(Ingredient));
                }

                if (Action == "edit")
                {
                    Data.Ingredient dataIngredient = _ingredientRepo.GetIngredientById(Ingredient.ID);
                    dataIngredient.SellPrice = Ingredient.SellPrice;
                    dataIngredient.BuyPrice  = Ingredient.BuyPrice;
                    dataIngredient.Amount    = Ingredient.Amount;
                    dataIngredient.Name      = Ingredient.Name;
                    dataIngredient.SellPrice = Ingredient.SellPrice;
                    _ingredientRepo.UpdateIngredient(dataIngredient);
                }

                AddOrEditIngredientRequested?.Invoke();
            }
            catch (ArgumentException e)
            {
                ErrorHandler.ThrowError(20001, e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #2
0
        public IngredientDto ServiceGetIngredientById(int id)
        {
            var ingredient = _ingredientRepository.GetIngredientById(id);

            if (ingredient == null)
            {
                return(null);
            }
            return(ingredient);
        }
예제 #3
0
        public IActionResult GetIngredient(int id)
        {
            if (!IngredientExists(id))
            {
                _logger.LogWarning($"Ingredient with id: {id} does not exist.");
                return(NotFound());
            }

            Ingredient ingredient = _ingredientRepo.GetIngredientById(id);

            _logger.LogInformation($"Getting ingredient with id: {id}");
            return(Ok(ingredient));
        }