public AuthenticatedController()
 {
     iRepo        = new IngredientsRepository();
     cRepo        = new CreatorRepository();
     uRepo        = new UserRepository();
     cocktailRepo = new CocktailsRepository();
 }
Exemplo n.º 2
0
        static async Task TestRepo()
        {
            var repo = new ArticlesRepository("Articles");

            // Example with Print Baked into the Object itself
            List <Articles> articles = new List <Articles>();

            articles = (await repo.GetAllAsync()).ToList();
            TestTool.PrintSuccess("Got {0} row from Articles\n", articles.Count());
            articles.First().PrintKeys();
            articles.ForEach(article => article.Print());

            //
            var repoEmployees          = new EmployeesRepository("Employees");
            List <Employees> employees = (await repoEmployees.GetAllAsync()).ToList();

            TestTool.PrintSuccess("Got {0} row from Employees\n", employees.Count());
            Console.Write("{0}\t{1}\t{2}\t{3}\t{4}\n", "ID", "Name", "LastName", "Email", "Password");
            employees.ForEach(employee => Console.Write("{0}\t{1}\t{2}\t{3}\t{4}\n", employee.ID, employee.Name, employee.LastName, employee.Email, new string('*', employee.Password.Length)));

            //
            var repoIngredients = new IngredientsRepository("Ingredients");
            var ingredients     = (await repoIngredients.GetAllAsync()).ToList();

            TestTool.PrintSuccess("Got {0} row from Ingredients\n", employees.Count());
            Console.Write("{0}\t{1}\t{2}\n", "ID", "Name", "Price");
            ingredients.ForEach(ingredient => Console.Write("{0}\t{1}\t{2}\n", ingredient.ID, ingredient.Name, ingredient.Price));

            //
            var           repoOrders = new OrdersRepository("Orders");
            List <Orders> orders     = (await repoOrders.GetAllAsync()).ToList();

            TestTool.PrintSuccess("Got {0} row from Orders\n", orders.Count());
            Console.Write("{0}\t{1}\t{2}\t{3}\t{4}\n", "ID", "TimeCreated", "Orderstatus", "Price", "CustomerID");
            orders.ForEach(order => Console.Write("{0}\t{1}\t{2}\t{3}\t{4}\n", order.ID, order.TimeCreated, order.Orderstatus, order.Price, order.CustomerID));


            //Orders order = (await repoOrders.GetAsync(4));


            //await repoOrders.UpdateAsync(new Orders() {ID = 12, Orderstatus = 0, Price = 124, CustomerID = 1 });

            //await repoIngredients.InsertCustomIngredientsAsync(orders.First(), articles.First(), articles.First().Ingredients);
            //Orders order = orders.First() ;
            //List<Articles> tempArticles = articles.GetRange(0, 2);
            //await repoOrders.MakeOrderAsync(order, tempArticles);

            //List<Articles> orderListArticles = (await repo.GetAllAsync(order)).ToList();
            //foreach (var item in orderListArticles)
            //{
            //    Console.WriteLine(item.Name + " " + item.Type);
            //    foreach (var item2 in item.Ingredients)
            //    {
            //        Console.Write(item2.Name.Trim() + ", ");
            //    }
            //}
            //articles[0].ID = 71;
            //await General.articlesRepo.UpdateAsync(articles[0]);
        }
 public UnitofWork(PizzaBoxContext context)
 {
     _context    = context;
     Customer    = new CustomerRepository(_context);
     Employee    = new EmployeeRepository(_context);
     Pizza       = new PizzaRepository(_context);
     Order       = new OrderRepository(_context);
     Address     = new AddressRepository(_context);
     Store       = new StoreRepository(_context);
     Ingrediants = new IngredientsRepository(_context);
 }
Exemplo n.º 4
0
 public void Delete(int id)
 {
     using (var ingredient = new IngredientsRepository())
     {
         TreatmentIngredients treat = ingredient.GetById(id);
         if (treat != null)
         {
             ingredient.Delete(treat);
         }
     }
 }
Exemplo n.º 5
0
 static Unit()
 {
     _context                  = new MyAppDbContext("DbRest");
     DishesRepository          = new DishesRepository(_context);
     CompositionsRepository    = new CompositionsRepository(_context);
     IngredientsRepository     = new IngredientsRepository(_context);
     OrdersRepository          = new OrdersRepository(_context);
     OrderFromMenuesRepository = new OrderFromMenuesRepository(_context);
     PurchasersRepository      = new PurchasersRepository(_context);
     StewardsRepository        = new StewardsRepository(_context);
     SuppliesRepository        = new SuppliesRepository(_context);
 }
        public async Task Setup()
        {
            _repositoryComponent        = new RepositoryComponent();
            _repositoryComponent.IsTest = true;

            var ingredientsFactory    = new IngredientsFactory(new IngredientBuilder());
            var ingredientsRepository = new IngredientsRepository(_repositoryComponent);
            await ingredientsRepository.ConfigureAsync(ingredientsFactory.GetDefaultIngredients());

            var drinkRecipesFactory    = new DrinkRecipeFactory(new DrinkRecipeBuilder());
            var drinkRecipesRepository = new DrinkRecipesRepository(_repositoryComponent, new DrinkIngredientRepository(_repositoryComponent));
            await drinkRecipesRepository.ConfigureAsync(drinkRecipesFactory.GetDefaultDrinks());
        }
 public ActionResult Edit([Bind(Include = "RecipesID,Name,Instructions, Ingredients, Portion, Time")] Recipes recipe)
 {
     if (ModelState.IsValid)
     {
         var ingredientsRepository = new IngredientsRepository(repository.GetContext());
         recipe.IngredientsList = ingredientsRepository.GenerateIngredientList(recipe);
         if(!recipe.Approved)
         {
             recipe.Approved = true;
         }
         repository.Entry(recipe).State = EntityState.Modified;
         repository.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(recipe);
 }
Exemplo n.º 8
0
 public List <IngredientsViewPar> GetAll()
 {
     using (var ingredient = new IngredientsRepository())
     {
         return(ingredient.GetAll().Select(x => new IngredientsViewPar
         {
             IngredientId = x.IngredientId,
             IngredientName = x.IngredientName,
             NumIngredients = x.NumIngredients,
             IngredientMass = x.IngredientMass,
             Ingredientprice = x.Ingredientprice,
             TotalPrice = x.TotalPrice,
             TotalMass = x.TotalMass,
         }).ToList());
     }
 }
 public ActionResult Edit([Bind(Include = "RecipesID,Name,Instructions, Ingredients, Portion, Time")] Recipes recipe)
 {
     if (ModelState.IsValid)
     {
         var ingredientsRepository = new IngredientsRepository(repository.GetContext());
         recipe.IngredientsList = ingredientsRepository.GenerateIngredientList(recipe);
         if (!recipe.Approved)
         {
             recipe.Approved = true;
         }
         repository.Entry(recipe).State = EntityState.Modified;
         repository.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(recipe));
 }
Exemplo n.º 10
0
        public void Default_Ingredients_Test()
        {
            RunOnDatabase(s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepo    = new FridgeRepository(s);
                var ingredCatRepo = new IngredientsCategoryRepository(s);
                var repository    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);

                // Act

                // Assert
                Assert.IsTrue(true);
            });
        }
Exemplo n.º 11
0
 public void GetByVotesNumber_Should_Work_Ok()
 {
     RunOnDatabase(async s =>
     {
         DestroyDatabase();
         // Arrange
         var fridgeRepo    = new FridgeRepository(s);
         var ingredCatRepo = new IngredientsCategoryRepository(s);
         var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
         var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
         // Act
         Populate(s);
         var res = await recipeRepo.GetByVotesNumber(4, recipeRepo.GetAll());
         // Assert
         Assert.IsTrue(0 == res.ToList().Count);
     });
 }
Exemplo n.º 12
0
 public void ContainsIngredient_Should_Work_Ok()
 {
     RunOnDatabase(async s =>
     {
         DestroyDatabase();
         // Arrange
         var fridgeRepo    = new FridgeRepository(s);
         var ingredCatRepo = new IngredientsCategoryRepository(s);
         var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
         var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
         // Act
         Populate(s);
         var res = await recipeRepo.ContainsIngredient(recipeRepo.GetByName("r1", recipeRepo.GetAll()).Result.First().Id, ingredRepo.GetByName("i1").Result.First().Id);
         // Assert
         Assert.IsTrue(res);
     });
 }
Exemplo n.º 13
0
        public static async void Populate(DatabaseContext s)
        {
            var categoryRepo = new IngredientsCategoryRepository(s);
            IEnumerable <IngredientCategory> categories = GetDefaultCategories();

            foreach (var ingredientCategory in categories)
            {
                await categoryRepo.Add(ingredientCategory);
            }
            var fridgeRepos    = new FridgeRepository(s);
            var ingredientRepo = new IngredientsRepository(s, categoryRepo, fridgeRepos);
            var recipeRepo     = new RecipesRepository(s, fridgeRepos, ingredientRepo);

            Ingredient i1   = Ingredient.Create(categories.First().Id, "i1", "cup", 0.9);
            Ingredient i2   = Ingredient.Create(categories.First().Id, "i2", "piece", 1.9);
            Ingredient i3   = Ingredient.Create(categories.First().Id, "i3", "slice", 0.5);
            Ingredient i4   = Ingredient.Create(categories.First().Id, "i3", "cup", 30);
            User       user = User.Create("xx", true, "*****@*****.**", "sh", "sdsbdk", "sureal");

            var userRepo = new UsersRepository(s);
            await userRepo.Add(user);

            await ingredientRepo.Add(i1);

            await ingredientRepo.Add(i2);

            await ingredientRepo.Add(i3);

            await ingredientRepo.Add(i4);

            Recipe recipe1 = Recipe.Create(user.Id, "r1", "reteta", RecipeStatusType.Approved, 10, 1, KitchenType.Asian);
            Recipe recipe2 = Recipe.Create(user.Id, "r2", "reteta2", RecipeStatusType.Approved, 15, 2, KitchenType.Unspecified);
            await recipeRepo.Add(recipe1);

            await recipeRepo.Add(recipe2);

            await recipeRepo.UpdateAllCosts();

            await fridgeRepos.Add(PairItem.Create(i1.Id, recipe1.Id, 2));

            await fridgeRepos.Add(PairItem.Create(i2.Id, recipe1.Id, 4));

            await fridgeRepos.Add(PairItem.Create(i3.Id, recipe1.Id, 1));

            await fridgeRepos.Add(PairItem.Create(i1.Id, recipe2.Id, 3));
        }
Exemplo n.º 14
0
 public void Add(IngredientsModelView model)
 {
     using (var ingredient = new IngredientsRepository())
     {
         var treat = new TreatmentIngredients
         {
             IngredientId    = model.IngredientId,
             IngredientName  = model.IngredientName,
             NumIngredients  = model.NumIngredients,
             IngredientMass  = model.IngredientMass,
             Ingredientprice = model.Ingredientprice,
             TotalPrice      = model.Ingredientprice * model.NumIngredients,
             TotalMass       = model.IngredientMass * model.NumIngredients
         };
         ingredient.Insert(treat);
     }
 }
Exemplo n.º 15
0
 public void Update(IngredientsViewPar model)
 {
     using (var ingredient = new IngredientsRepository())
     {
         TreatmentIngredients treat = ingredient.GetById(model.IngredientId);
         if (treat != null)
         {
             treat.IngredientId    = model.IngredientId;
             treat.IngredientName  = model.IngredientName;
             treat.NumIngredients  = model.NumIngredients;
             treat.IngredientMass  = model.IngredientMass;
             treat.Ingredientprice = model.Ingredientprice;
             treat.TotalPrice      = model.Ingredientprice * model.NumIngredients;
             treat.TotalMass       = model.IngredientMass * model.NumIngredients;
             ingredient.Update(treat);
         }
     }
 }
Exemplo n.º 16
0
        public void Given_Repository_When_Get_By_Ingredient_ShouldBe_Correct()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepos    = new FridgeRepository(s);
                var categoryRepo   = new IngredientsCategoryRepository(s);
                var ingredientRepo = new IngredientsRepository(s, categoryRepo, fridgeRepos);
                var recipeRepo     = new RecipesRepository(s, fridgeRepos, ingredientRepo);

                // Act
                Populate(s);
                var data = await fridgeRepos.GetByIngredient(ingredientRepo.GetByName("i1").Result.First().Id);

                // Assert
                Assert.AreEqual(2, data.ToList().Count);
            });
        }
Exemplo n.º 17
0
        public void GetByPreparationTime_Should_Work_Ok()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepo    = new FridgeRepository(s);
                var ingredCatRepo = new IngredientsCategoryRepository(s);
                var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
                var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
                // Act
                Populate(s);

                var res = await recipeRepo.GetByPrepatationTime(25, recipeRepo.GetAll());

                // Assert
                Assert.AreEqual(1, res.ToList().Count);
            });
        }
Exemplo n.º 18
0
 public IngredientsViewPar GetById(int id)
 {
     using (var ingredient = new IngredientsRepository())
     {
         TreatmentIngredients treat = ingredient.GetById(id);
         var ingredientview         = new IngredientsViewPar();
         if (treat != null)
         {
             ingredientview.IngredientId    = treat.IngredientId;
             ingredientview.IngredientName  = treat.IngredientName;
             ingredientview.NumIngredients  = treat.NumIngredients;
             ingredientview.IngredientMass  = treat.IngredientMass;
             ingredientview.Ingredientprice = treat.Ingredientprice;
             ingredientview.TotalPrice      = treat.TotalPrice;
             ingredientview.TotalMass       = treat.TotalMass;
         }
         return(ingredientview);
     }
 }
Exemplo n.º 19
0
        public void ExcludesIngredients_Should_Work_Ok()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepo    = new FridgeRepository(s);
                var ingredCatRepo = new IngredientsCategoryRepository(s);
                var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
                var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
                // Act
                Populate(s);
                List <Ingredient> igToAdd = new List <Ingredient>();
                igToAdd.Add(ingredRepo.GetByName("i1").Result.First());
                var res = await recipeRepo.ExcludesTheseIngredients(recipeRepo.GetByName("r1", recipeRepo.GetAll()).Result.First().Id, igToAdd);

                // Assert
                Assert.AreEqual(false, res);
            });
        }
Exemplo n.º 20
0
        public void GetByOnlyIngredients_Should_Work_Ok()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepo    = new FridgeRepository(s);
                var ingredCatRepo = new IngredientsCategoryRepository(s);
                var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
                var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
                // Act
                Populate(s);
                List <Ingredient> igToAdd = new List <Ingredient>();
                igToAdd.Add(ingredRepo.GetByName("i1").Result.First());
                var res = await recipeRepo.GetByOnlyIngredients(igToAdd, recipeRepo.GetAll());

                // Assert
                Assert.AreEqual(1, res.ToList().Count);
            });
        }
Exemplo n.º 21
0
        public async Task CallConfigureTwice_OneTable_And_NoDuplicateIngredients()
        {
            // arrange
            var ingredientRepository = new IngredientsRepository(new RepositoryComponent()
            {
                IsTest = true
            });
            // act
            await ingredientRepository.ConfigureAsync(TestData.CreateDefaultIngredients());

            await ingredientRepository.ConfigureAsync(TestData.CreateDefaultIngredients());

            // assert
            var connection = ingredientRepository.Component.Connection;
            var tableCount = await ingredientRepository.Component.Connection.TableCount(IngredientsRepository.TableName);

            var items = await connection.Table <Ingredient>().ToListAsync();

            tableCount.ShouldBe(1);
            items.Count.ShouldBe(6);
        }
Exemplo n.º 22
0
 public void AddIngredientCustom_ShouldWork()
 {
     RunOnDatabase(async s =>
     {
         DestroyDatabase();
         // Arrange
         var fridgeRepo    = new FridgeRepository(s);
         var ingredCatRepo = new IngredientsCategoryRepository(s);
         var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
         var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
         IEnumerable <IngredientCategory> categories = GetDefaultCategories();
         // Act
         Populate(s);
         int count = ingredRepo.GetAll().Result.Count();
         await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "t", "ms", "new", 1, 1, 1);
         await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "First Category", "i3", "cup", 1, 1, 1);
         //await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "Another Category", "i3", "cup", 1, 1, 1);
         await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "asfasfasfasfy", "i5", "cup", 1, 1, 1);
         // Assert
         Assert.AreEqual(count + 3, ingredRepo.GetAll().Result.Count());
     });
 }
Exemplo n.º 23
0
 public void GetSpecificCategory_ShouldWork()
 {
     RunOnDatabase(async s =>
     {
         DestroyDatabase();
         // Arrange
         var fridgeRepo    = new FridgeRepository(s);
         var ingredCatRepo = new IngredientsCategoryRepository(s);
         var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
         var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
         IEnumerable <IngredientCategory> categories = GetDefaultCategories();
         // Act
         Populate(s);
         await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "asfasfasfasfy", "cup", "i5", 1, 1, 1);
         await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "other-ingredients", "cup", "i6", 1, 1, 1);
         var res  = await ingredRepo.GetSpecificCategory("i5");
         var res2 = await ingredRepo.GetSpecificCategory("i6");
         var res1 = await ingredRepo.GetSpecificCategory("null");
         // Assert
         Assert.AreEqual(res, ingredCatRepo.GetByName("asfasfasfasfy").Result.Id);
         Assert.AreEqual(res2, null);
         Assert.AreEqual(null, res1);
     });
 }
Exemplo n.º 24
0
        public void Exists_Should_Work_Ok()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepo    = new FridgeRepository(s);
                var ingredCatRepo = new IngredientsCategoryRepository(s);
                var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
                IEnumerable <IngredientCategory> categories = GetDefaultCategories();
                // Act
                foreach (var ingredientCategory in categories)
                {
                    await ingredCatRepo.Add(ingredientCategory);
                }
                await ingredRepo.Add(Ingredient.Create(ingredCatRepo.GetAll().Result.First().Id, "onion", "piece", 1.2));

                // Assert
                Boolean bool1 = ingredRepo.Exists("onion").Result;
                Boolean bool2 = ingredRepo.Exists("onion", "piece").Result;
                Boolean bool3 = ingredRepo.Exists("onion", "slice").Result;
                Assert.IsTrue(bool1 && bool2 && !bool3);
            });
        }
Exemplo n.º 25
0
        public void GetByFilter_Should_Work_Ok()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepo    = new FridgeRepository(s);
                var ingredCatRepo = new IngredientsCategoryRepository(s);
                var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
                var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
                // Act
                Populate(s);
                var filtru = new Filter();

                //var res = await recipeRepo.GetByFilter(filtru);
                filtru.Name            = "r1";
                filtru.Cuisine         = KitchenType.Asian;
                filtru.PreparationTime = 10;

                var res = await recipeRepo.GetByFilter(filtru);
                // Assert
                Assert.AreEqual(1, res.ToList().Count);
            });
        }
Exemplo n.º 26
0
 public IngredientsController()
 {
     _context = new JPGPizzaDbContext();
     _ingredientsRepository = new IngredientsRepository(_context);
 }
Exemplo n.º 27
0
 public AdminController()
 {
     iRepo = new IngredientsRepository();
     cRepo = new CocktailsRepository();
     uRepo = new UserRepository();
 }
Exemplo n.º 28
0
 public IngredientsService(IngredientsRepository repo)
 {
     _repo = repo;
 }
Exemplo n.º 29
0
 // constructor for the MattController that calls the AddMealProfile() Class and assigns it
 // to the private variable _addMealProfiles      and again for _addMealProfilesRepository
 public MattController()
 {
     _addMealProfiles           = new AddMealProfile();
     _addMealProfilesRepository = new AddMealProfilesRepository();
     _ingredientsRepository     = new IngredientsRepository();
 }
Exemplo n.º 30
0
 public Ingredients_Services()
 {
     _repo = new IngredientsRepository();
 }
Exemplo n.º 31
0
 public MealsController(MealsRepository mealRepository, IngredientsRepository ingredientsRepository)
 {
     _mealRepository        = mealRepository;
     _ingredientsRepository = ingredientsRepository;
 }