Example #1
0
        public IEnumerable <RecipeDto> ServiceGetRecipes()
        {
            var toreturn          = _recipeRepository.GetRecipes().Select(x => x);
            var realthingtoReturn = new List <RecipeDto>();

            foreach (var item in toreturn)
            {
                realthingtoReturn.Add(ServiceGetRecipeById(item.id));
            }
            return(realthingtoReturn);
        }
Example #2
0
        /// <summary>
        /// Sets the collections.
        /// </summary>
        public void Loaded()
        {
            Categories     = _categoryRepo.GetCategories();
            AllIngredients = _ingredientRepo.GetIngredients();

            ProductRecipeItems = new ObservableCollection <Data.RecipeItem>(_recipeRepo.GetRecipes()
                                                                            .Where(r => r.Product.ID.Equals(SelectedRecipeItem.Product.ID)));
        }
Example #3
0
        public IEnumerable <Recipe> Get()
        {
            IEnumerable <Recipe> recipes = _recipeRepo.GetRecipes();

            if (recipes != null)
            {
                _logger.LogInformation("Getting all recipes.");
                return(recipes.ToList());
            }
            _logger.LogWarning("Attempted to get recipes but no recipes were available.");
            return(null);
        }
Example #4
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();
            }
        }
        public IEnumerable <RecipeDto> GetRecipes()
        {
            var recipes = _recipeRepository.GetRecipes();

            return(recipes.Select(x => x).ToList());
        }
 public ActionResult <IEnumerable <Recipe> > Get()
 {
     return(new JsonResult(_recipeRepo.GetRecipes()));
 }
Example #7
0
        private void DeleteProduct(Product product)
        {
            try
            {
                ObservableCollection <RecipeItem> recipeItemList = new ObservableCollection <RecipeItem>(_recipeRepo.GetRecipes()
                                                                                                         .Where(r => r.Product.ID.Equals(product.ID)));

                foreach (RecipeItem recipeItem in recipeItemList)
                {
                    _recipeRepo.DeleteRecipe(recipeItem);
                }

                Products.Remove(product);
                _productRepo.DeleteProduct(product);
                MessageHandler.InvokeSuccessMessage(Resources.InformationDeleteProduct, Resources.InformationProductDeleted.Replace("{name}", product.Name));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }