Example #1
0
        public static void Main(string[] args)
        {
            //Setup Database
            var mj = new MakeJsonFiles(new FileClient());

            mj.CreateAllTables();

            //Poor Man DI
            var ingredientRepository        = new IngredientRepository(new FileClient());
            var recipeRepository            = new RecipeRepository(new FileClient());
            var recipeIngredientRespository = new RecipeIngredientRepository(new FileClient());
            var recipeManager = new RecipeManager(
                ingredientRepository,
                recipeRepository,
                recipeIngredientRespository
                );

            //Start Program
            var recipes = recipeManager.GetAll();

            foreach (var recipe in recipes)
            {
                var receipt = new RecipeReceipt(recipe);
                Console.WriteLine(receipt.ToString());
            }
        }
Example #2
0
 public RecipeController(RecipeRepository recipeRepository, RecipeIngredientRepository recipeIngredientRepository, IngredientRepository ingredientRepository, SavedRecipesRepository savedRecipes, UserRepository users, FeedbackRepository feedback)
 {
     _recipeRepository           = recipeRepository;
     _recipeIngredientRepository = recipeIngredientRepository;
     _ingredientRepository       = ingredientRepository;
     _savedRecipes = savedRecipes;
     _users        = users;
     _feedback     = feedback;
 }
 public UnitOfWork(ApplicationDbContext context)
 {
     _context          = context;
     Recipes           = new RecipeRepository(_context);
     RecipeIngredients = new RecipeIngredientRepository(_context);
     FoodTypes         = new FoodTypeRepository(_context);
     Foods             = new FoodRepository(_context);
     IngredientTypes   = new IngredientTypeRepository(_context);
     Ingredients       = new IngredientRepository(_context);
     UnitOfMeasures    = new UnitOfMeasureRepository(_context);
 }
Example #4
0
        public UnitOfWork()
        {
            var context = new JsonFileContext();

            Categories = new CategoryRepository(context);
            foreach (var category in Categories.GetAll())
            {
                category.Parent = Categories.SingleOrDefault(y => y.Id == category.ParentId);
            }

            Recipes           = new RecipeRepository(context);
            Ingredients       = new IngredientRepository(context);
            RecipeIngredients = new RecipeIngredientRepository(context);

            foreach (var recipe in Recipes.GetAll())
            {
                recipe.Ingredients = RecipeIngredients.GetRecipeIngredients(recipe.Id).ToList();
                recipe.Ingredients.ForEach(x => x.Ingredient = Ingredients.SingleOrDefault(y => y.Id == x.IngredientId));
            }
        }
Example #5
0
 public RecipeIngredientController(RecipeIngredientRepository recipeIngredientRepository)
 {
     _recipeIngredientRepository = recipeIngredientRepository;
 }
Example #6
0
        public async Task <Recipe> CreateAsync(Recipe recipe)
        {
            if (string.IsNullOrEmpty(recipe.Notes))
            {
                recipe.Notes = "No Notes Yet.";
            }

            // TODO: Extract this out to a function of its own.
            if (string.IsNullOrEmpty(recipe.CreatedBy) || string.IsNullOrEmpty(recipe.ModifiedBy))
            {
                recipe.CreatedBy = await SecurityService.GetCurrentUserName();

                recipe.ModifiedBy = await SecurityService.GetCurrentUserName();
            }

            var existingRecipe = await RecipeRepository.GetByKeyAsync(recipe.Key);

            if (existingRecipe != null && existingRecipe.CreatedBy == recipe.CreatedBy)
            {
                throw new BistroFiftyTwoDuplicateRecipeException(
                          "A recipe with that key already exists.  Edit the existing recipe instead."); //TODO: Once we have update, call update instead.
            }
            var createdRecipe = await RecipeRepository.CreateAsync(recipe);

            var recipeIngredientTasks = new List <Task <RecipeIngredient> >();
            var recipeStepTasks       = new List <Task <Step> >();

            recipe.Ingredients.ToList().ForEach(async r =>
            {
                r.RecipeId = createdRecipe.ID;
                if (string.IsNullOrEmpty(r.Notes))
                {
                    r.Notes = $"Notes for ingredient {r.Ordinal}";
                }

                if (string.IsNullOrEmpty(r.Units))
                {
                    r.Units = "items";
                }

                if (string.IsNullOrEmpty(r.CreatedBy) || string.IsNullOrEmpty(r.ModifiedBy))
                {
                    r.CreatedBy  = await SecurityService.GetCurrentUserName();
                    r.ModifiedBy = await SecurityService.GetCurrentUserName();
                }

                await RecipeIngredientRepository.CreateAsync(r);
            });

            recipe.Steps.ToList().ForEach(async s =>
            {
                s.RecipeId = createdRecipe.ID;

                if (string.IsNullOrEmpty(s.CreatedBy) || string.IsNullOrEmpty(s.ModifiedBy))
                {
                    s.CreatedBy  = await SecurityService.GetCurrentUserName();
                    s.ModifiedBy = await SecurityService.GetCurrentUserName();
                }

                await StepRepository.CreateAsync(s);
            });

            // set the historical version correctly. - may need to do more work here for revisions, set version correctly.
            var recipeHistory = await RecipeHistoryRepository.GetAsync(recipe.FullTextReference);

            recipeHistory.RecipeID = createdRecipe.ID;
            await RecipeHistoryRepository.UpdateAsync(recipeHistory);

            // pull the recipe from the db which also will populate the cache.
            return(await GetByIdAsync(createdRecipe.ID));
        }
Example #7
0
 private async Task PopulateIngredients(Recipe recipe)
 {
     recipe.Ingredients = await RecipeIngredientRepository.GetByRecipeIdAsync(recipe.ID);
 }