/// <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;
            }
        }
Exemplo n.º 2
0
        public void AddSale()
        {
            if (SelectedProduct != null)
            {
                ObservableCollection <Data.RecipeItem> recipes =
                    new ObservableCollection <Data.RecipeItem>(_iRecipeRepo.GetRecipes()
                                                               .Where(recipe => recipe.Product.ID.Equals(SelectedProduct.ID)));

                bool isAddSalePossible = true;

                for (int i = 0; i < Amount; i++)
                {
                    isAddSalePossible = true;
                    foreach (Data.RecipeItem recipe in recipes)
                    {
                        Data.Ingredient ingredient = recipe.Ingredient;
                        if (ingredient.Amount < recipe.Amount)
                        {
                            isAddSalePossible = false;
                            ErrorHandler.ThrowError(0, $"{Properties.Resources.ToLittleOf}: {recipe.Ingredient.Name}");
                        }
                    }

                    if (isAddSalePossible)
                    {
                        foreach (Data.RecipeItem recipe in recipes)
                        {
                            Data.Ingredient ingredient = recipe.Ingredient;
                            ingredient.Amount -= recipe.Amount;
                            _iIngredientRepo.UpdateIngredient(ingredient);
                        }
                        Data.Sale sale = new Data.Sale()
                        {
                            Cooked = 0, Delivered = 0, Paid = 0, Product = SelectedProduct.ConvertToData()
                        };
                        _iOccupanciesRepo.AddSale(_occupancy, sale);
                        MessageHandler.InvokeSuccessMessage(Properties.Resources.InformationAddSale, Properties.Resources.InformationSaleAdded.Replace("{product}", $"{SelectedProduct.Name}"));
                    }
                }
                ViewBack();
            }
        }
Exemplo n.º 3
0
        public IActionResult PutIngredient(int id, Ingredient ingredient)
        {
            if (id != ingredient.Id)
            {
                _logger.LogWarning($"Route value id: {id} does not match ingredient id: {ingredient.Id}");
                return(BadRequest());
            }

            if (!IngredientExists(id))
            {
                _logger.LogWarning($"Ingredient with id: {id} does not exist.");
                return(NotFound());
            }

            _ingredientRepo.UpdateIngredient(ingredient);
            _ingredientRepo.SaveChanges();

            _logger.LogInformation($"Ingredient with id: {id} has been updated.");
            return(NoContent());
        }