new void ChangeRecipeDisplayed()
    {
        base.ChangeRecipeDisplayed();
        List <Dictionary <string, int> > recipeProgressList = new List <Dictionary <string, int> >(playerInventoryData.GetRecipeProgress());
        RecipeController recipeToBeDisplayed = GetRecipeToDisplay();

        recipeProgressList.Sort(closestToFinishFirst);
        GameObject dishImageForeground = gameObject.transform.GetChild(0).gameObject;
        int        ingredientIterator  = 0;
        int        hasIngredientCnt    = 0;

        foreach (Transform child in dishImageForeground.transform)
        {
            IngredientController currentIngredient = recipeToBeDisplayed.ingredients[ingredientIterator];
            if (recipeProgressList[priority][currentIngredient.ingredient] != 0)
            {
                child.GetChild(0).GetComponent <Image>().sprite = currentIngredient.GetIngredientImageColored();
                hasIngredientCnt++;
            }
            else
            {
                child.GetChild(0).GetComponent <Image>().sprite = currentIngredient.GetIngredientImageGreyed();
            }
            ingredientIterator++;
        }
        gameObject.GetComponent <Image>().sprite = shownDishTemplatesIncreasingCompletionRate[hasIngredientCnt];
    }
    protected void ChangeRecipeDisplayed()
    {
        List <Dictionary <string, int> > recipeProgressList = new List <Dictionary <string, int> >(playerInventoryData.GetRecipeProgress());
        RecipeController recipeToBeDisplayed = GetRecipeToDisplay();

        recipeProgressList.Sort(closestToFinishFirst);
        GameObject dishImageForeground = gameObject.transform.GetChild(0).gameObject;

        dishImageForeground.GetComponent <Image>().sprite = recipeToBeDisplayed.GetRecipeImage();
        int ingredientIterator = 0;
        int hasIngredientCnt   = 0;

        foreach (Transform child in dishImageForeground.transform)
        {
            IngredientController currentIngredient = recipeToBeDisplayed.ingredients[ingredientIterator];
            if (recipeProgressList[priority][currentIngredient.ingredient] != 0)
            {
                hasIngredientCnt++;
            }
            ingredientIterator++;
        }
        // only set the UI sprite if on a stacked UI element
        if (stackedDishTemplatesIncreasingCompletionRate.Count == 3)
        {
            gameObject.GetComponent <Image>().sprite = stackedDishTemplatesIncreasingCompletionRate[hasIngredientCnt];
        }
    }
Example #3
0
        public static void Show()
        {
            IngredientController controller = new IngredientController();
            IngredientsDataAcess ingredient = new IngredientsDataAcess();

            Console.Write("Ingredient ID:\n");
            int id = Int32.Parse(Console.ReadLine());

            ingredient = controller.FindById(id);

            Console.WriteLine(ingredient.ToString());

            Console.WriteLine($"New name: (leave blank for no change) ({ingredient.Name})");
            string name = Console.ReadLine();

            if (!String.IsNullOrEmpty(name))
            {
                ingredient.Name = name;
            }

            Console.WriteLine($"New stock quantity: (leave blank for no change) ({ingredient.Stock})");
            string stockStr = Console.ReadLine();

            if (!String.IsNullOrEmpty(stockStr))
            {
                int stock = Int32.Parse(stockStr);
                ingredient.Stock = stock;
            }

            controller.Update(ingredient);

            Console.WriteLine("\nIngredient updated!\n");
            Console.ReadKey();
            ClearHelper.Clear();
        }
 public Catalog(IUnitOfWork unitOfWork)
 {
     categoryController    = new CategoryController(unitOfWork);
     recipeController      = new RecipeController(unitOfWork);
     ingredientController  = new IngredientController(unitOfWork);
     cookingStepController = new CookingStepController(unitOfWork);
 }
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            int        id = Int32.Parse(idText.Text);
            Ingredient a  = IngredientController.SearchByID(id);

            NameText.Text     = a.IngredientName;
            QuantityText.Text = a.IngredientStock.ToString();
        }
Example #6
0
 public LeftoversPage()
 {
     InitializeComponent();
     _ingredientController = new IngredientController();
     _ingredients          = new List <string>();
     Entry.TextChanged    += Entry_TextChangedAsync;
     SearchButton.Clicked += SearchButton_ClickedAsync;
 }
 public IngredientControllerTests()
 {
     _unitOfWorkMock = new Mock <IUnitOfWork>();
     _loggerMock     = new Mock <ILogger <IngredientController> >();
     _mockRepository = new Mock <IRepository>();
     _unitOfWorkMock.SetupGet(u => u.Repository).Returns(_mockRepository.Object);
     _ingredientController = new IngredientController(_unitOfWorkMock.Object, _loggerMock.Object);
 }
Example #8
0
 public static async Task ListIngredientsAsync(IngredientController ingredientController, int count = 0)
 {
     foreach (var ingredient in await ingredientController.GetIngredientsAsync())
     {
         Console.WriteLine($"{++count}. {ingredient.Name}.");
     }
     Console.WriteLine("\t\t*enter*");
     Console.ReadLine();
 }
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            Ingredient a = new Ingredient();

            a.IngredientName   = NameText.Text;
            a.IngredientStock  = Int32.Parse(QuantityText.Text);
            a.IngredientStatus = "Active";
            IngredientController.addIngredient(a);
            RefreshTable();
        }
Example #10
0
    /* sets the MVC relationships */
    public void createMVC(IngredientModel m, IngredientView v, IngredientController c)
    {
        Model      = m;
        View       = v;
        Controller = c;

        Model.setElement(this);
        View.setElement(this);
        Controller.setElement(this);
    }
        public void Delete_InvalidID_ReturnsNotFoundResult()
        {
            // Arrange
            IDataRepository <Ingredient> mockRepository = Substitute.For <IDataRepository <Ingredient> >();
            IngredientController         ingredientCont = new IngredientController(mockRepository);
            // Act
            var notFoundResult = ingredientCont.Delete(68);

            // Assert
            Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult);
        }
        public void GetById_UnknownintPassed_ReturnsNotFoundResult()
        {
            // Arrange
            IDataRepository <Ingredient> mockRepository = Substitute.For <IDataRepository <Ingredient> >();
            IngredientController         ingredientCont = new IngredientController(mockRepository);
            // Act
            var notFoundResult = ingredientCont.Get(68);

            // Assert
            Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult);
        }
Example #13
0
        public AddRecipePage()
        {
            InitializeComponent();

            Recipe = new Recipe {
            };
            ingredientController          = new IngredientController();
            ingredients                   = new List <Ingredient>();
            ingredientsEntry.TextChanged += IngredientsEntry_TextChangedAsync;
            BindingContext                = this;
        }
        public void Put_Null_Should_ReturnsBadRequest()
        {
            // Arrange
            IDataRepository <Ingredient> mockRepository = Substitute.For <IDataRepository <Ingredient> >();
            IngredientController         ingredientCont = new IngredientController(mockRepository);
            // Act
            Ingredient newIngredient = null;
            var        badRequest    = ingredientCont.Put(68, newIngredient);

            // Assert
            Assert.IsType <Microsoft.AspNetCore.Mvc.BadRequestObjectResult>(badRequest);
        }
Example #15
0
        private void DoInsertButton(object sender, RoutedEventArgs e)
        {
            int quantity;

            Int32.TryParse(quantityBox.Text, out quantity);

            IngredientController.DoInsertIngredient(attNameText.Text, quantity);
            KitchenHomePage kitHome = new KitchenHomePage();

            this.NavigationService.Navigate(kitHome);
            MessageBox.Show("Ingredient Inserted !");
        }
        public void Get_WhenCalled_ReturnsOkResult()
        {
            // Arrange
            IDataRepository <Ingredient> mockRepository = Substitute.For <IDataRepository <Ingredient> >();
            IngredientController         ingredientCont = new IngredientController(mockRepository);
            FilterModel fm = new FilterModel();
            // Act
            var okResult = ingredientCont.Get(fm);

            // Assert
            Assert.IsType <ActionResult <PagedCollectionResponse <Ingredient> > >(okResult);
        }
Example #17
0
        public static void Show()
        {
            IngredientsDataAcess ingredient = new IngredientsDataAcess();

            Console.Write("Ingredient ID:\n");
            int id = Int32.Parse(Console.ReadLine());

            IngredientController controller = new IngredientController();

            controller.Delete(id);

            Console.WriteLine("\nIngredient deleted!\n");
            Console.ReadKey();
            ClearHelper.Clear();
        }
        public static void Show()
        {
            Console.WriteLine("Fetching Data, please wait...");

            IngredientController        controller = new IngredientController();
            List <IngredientsDataAcess> list       = controller.getAll();

            ClearHelper.Clear();
            Console.WriteLine("Ingredients:\n");

            foreach (IngredientsDataAcess ingredient in list)
            {
                Console.WriteLine(ingredient.ToString());
            }
        }
        public void Put_Invalid_ID_Should_ReturnsNotFoundResult()
        {
            // Arrange
            IDataRepository <Ingredient> mockRepository = Substitute.For <IDataRepository <Ingredient> >();
            IngredientController         ingredientCont = new IngredientController(mockRepository);
            // Act
            Ingredient newIngredient = new Ingredient()
            {
                IsValid = false, Name = "Changed"
            };
            var notFoundResult = ingredientCont.Put(68, newIngredient);

            // Assert
            Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult);
        }
Example #20
0
        public static async Task FindIngredientAsync(IngredientController ingredientController, string answer = "")
        {
            Console.Write("Введите название ингредиента : ");
            var ingr = await ingredientController.FindAndGetIngredientAsync(Console.ReadLine().ToLower());

            if (ingr != null)
            {
                Console.WriteLine($"{ingr.Name} есть в списке.");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine();
                while (true)
                {
                    Console.Write(
                        "Такого ингредиента нет, создать ли ?\n" +
                        "1. да\n" +
                        "2. нет\n" +
                        "(number): ");
                    if (int.TryParse(Console.ReadLine(), out int tempResult))
                    {
                        int countIngredients = 0;
                        switch (tempResult)
                        {
                        case 1:
                            do
                            {
                                Console.WriteLine("Введите колличество ингредиентов: ");
                                answer = Console.ReadLine();
                            } while (!int.TryParse(answer, out countIngredients));

                            var ingredientsId = new List <int>();
                            for (int count = 1; count <= countIngredients; count++)
                            {
                                Console.WriteLine("Введите ингредиент:");
                                Console.Write($"{count}. ");
                                ingredientsId.Add(await ingredientController.AddedIfNewAsync(Console.ReadLine()));
                            }
                            return;

                        case 2:
                            return;
                        }
                    }
                }
            }
        }
Example #21
0
        public static async Task AddIngredientsAsync(IngredientController ingredientController, string answer = "", int count = 0)
        {
            do
            {
                Console.WriteLine("Введите колличество ингредиентов: ");
                answer = Console.ReadLine();
            } while (!int.TryParse(answer, out count));

            var ingredientsId = new List <int>();

            for (int i = 1; i <= count; i++)
            {
                Console.WriteLine("Введите ингредиент:");
                Console.Write($"{i}. ");
                ingredientsId.Add(await ingredientController.AddedIfNewAsync(Console.ReadLine()));
            }
        }
Example #22
0
        public void IngredientControllerNotEmpty()
        {
            //set options for dbcontext
            var dbOption = new DbContextOptionsBuilder <DatabaseContext>()
                           .UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=CAWhatCanIEat;Trusted_Connection=True;MultipleActiveResultSets=true")
                           .Options;

            //set controller + dbcontext
            var controller = new IngredientController(new DatabaseContext(dbOption));

            string item = "all";

            //get result from controller
            var result = controller.Get(item);

            //check if the result is not null
            Assert.NotNull(result);
        }
Example #23
0
        public static void ShowForm()
        {
            IngredientsDataAcess ingredient = new IngredientsDataAcess();

            Console.Write("Ingrediente Name:\n");
            ingredient.Name = Console.ReadLine();

            Console.Write("Quantity in Stock:\n");
            ingredient.Stock = Int32.Parse(Console.ReadLine());

            IngredientController controller = new IngredientController();

            controller.Save(ingredient);

            Console.WriteLine("\nIngredient saved!\n");
            Console.ReadKey();
            ClearHelper.Clear();
        }
Example #24
0
        public static async Task FindAsync(RecipeController recipeController, IngredientController ingredientController)
        {
            Console.Write("1. Поиск рецепта.\n" +
                          "2. Поиск ингредиента.\n" +
                          "3. Вернуться.\n" +
                          "4. Выйти.\n" +
                          "(number):");
            if (int.TryParse(Console.ReadLine(), out int result))
            {
                Console.Clear();
                switch (result)
                {
                case 1:
                    #region Find Recipe
                    await FindRecipeAsync(recipeController, ingredientController);

                    #endregion
                    break;

                case 2:
                    #region Find Ingredient
                    await FindIngredientAsync(ingredientController);

                    #endregion
                    break;

                case 3:
                    return;

                case 4:
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Ошибка в вводе данных.");
                    break;
                }
            }
            else
            {
                Console.WriteLine("Ошибка в вводе данных.");
            }
        }
Example #25
0
    public override void instantiateElement(Vector3 startPos, Vector3 endPos)
    {
        IngredientModel newModel = new IngredientModel();

        // instantiate GameObject
        GameObject newObject = Singletons.Instantiator.instantiateObject(Type);

        // get the View from GameObject
        IngredientView newView = newObject.transform.GetComponent <IngredientView>();

        // assign MVC so everyone knows each other
        IngredientController newController = new IngredientController();

        this.createMVC(newModel, newView, newController);

        // update Model values - must be done after MVC is created
        newModel.Position = endPos;
        newModel.initModel();
    }
        public void Add_ValidObject_Then_Get_Should_bring_Something()
        {
            // Arrange

            DbContextOptions <RepositoryContext> options = new MockDBHandler().IngredientWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                IDataRepository <Ingredient> mockRepository = new IngredientManager(context);
                IngredientController         ingredientCont = new IngredientController(mockRepository);
                FilterModel fm = new FilterModel();
                //Act

                var okResult = ingredientCont.Get(fm) as ActionResult <PagedCollectionResponse <Ingredient> >;

                // Assert
                var retObj = Assert.IsType <ActionResult <PagedCollectionResponse <Ingredient> > >(okResult);
                Assert.Equal(3, retObj.Value.Items.ToList().Count);
            }
        }
        public void Add_ValidObjectPassed_ReturnedResponseHasCreatedItem()
        {
            // Arrange
            IDataRepository <Ingredient> mockRepository = Substitute.For <IDataRepository <Ingredient> >();
            IngredientController         ingredientCont = new IngredientController(mockRepository);

            Ingredient tempIngredient = new Ingredient()
            {
                IsValid = true,
                Name    = "TestIngredient"
            };

            // Act
            IActionResult actionResult  = ingredientCont.Post(tempIngredient);
            var           createdResult = actionResult as CreatedAtRouteResult;

            // Assert
            Assert.NotNull(createdResult);
            Assert.Equal("TestIngredient", ((Ingredient)createdResult.Value).Name);
            Assert.Equal(0, ((Ingredient)createdResult.Value).ID);
        }
        public void Delete_ShouldWork()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().IngredientWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                IDataRepository <Ingredient> mockRepository = new IngredientManager(context);
                IngredientController         ingredientCont = new IngredientController(mockRepository);
                FilterModel fm = new FilterModel();
                //Act
                var putResult = ingredientCont.Delete(2) as OkObjectResult;
                var okResult  = ingredientCont.Get(fm);
                var retObj    = Assert.IsType <ActionResult <PagedCollectionResponse <Ingredient> > >(okResult);
                // Assert
                Assert.Equal(2, retObj.Value.Items.ToList().Count);

                Assert.Equal("Ing1", retObj.Value.Items.ToList()[0].Name);
                Assert.Equal("Ing3", retObj.Value.Items.ToList()[1].Name);
            }
        }
Example #29
0
        private static void Main(string[] args)
        {
            Console.InputEncoding  = Encoding.Unicode;
            Console.OutputEncoding = Encoding.Unicode;
            JsonContext          jsonContext          = new JsonContext();
            UnitOfWork           unitOfWork           = new UnitOfWork(jsonContext);
            CategoryController   categoryController   = new CategoryController(unitOfWork);
            RecipeController     recipeController     = new RecipeController(unitOfWork);
            IngredientController ingredientController = new IngredientController(unitOfWork);

            categoryController.ShowCategories();

            int numberSelectedCategory = GetNumberCategory(categoryController);

            recipeController.ShowRecipesCategory(numberSelectedCategory);

            int numberSelectedRecipe = GetNumberRecipe(recipeController, numberSelectedCategory);

            recipeController.ShowSelectedRecipe(numberSelectedRecipe, numberSelectedCategory);

            Console.WriteLine("Хотите создать свой рецепт?(y/n)");
            string choiceCreateRecipe = Console.ReadLine();

            if (choiceCreateRecipe.ToUpper() == "Y")
            {
                CreateRecipe(recipeController);
                jsonContext.Ingredients = ingredientController.GetAllIngredients();
                ingredientController.SaveIngredients();
            }

            Console.WriteLine("Показать ингредиенты которые использовались в рецептах?(y/n)");
            string choiceShowIngredient = Console.ReadLine();

            if (choiceShowIngredient.ToUpper() == "Y")
            {
                ingredientController.ShowAllIngredients();
            }

            Console.WriteLine("");
        }
        public IngredientControllerTest()
        {
            _unitOfWorkMock = new Mock <IUnitOfWork>();
            _repositoryMock = new Mock <IRepository>();

            _expectedIngredient = new Ingredient
            {
                Id   = 1,
                Name = "expected"
            };

            _expectedListIngredient = new List <Ingredient>()
            {
                _expectedIngredient
            };

            // Simulate "Repository" property to return prevously created mock object for IRepository
            _unitOfWorkMock.SetupGet(o => o.Repository)
            .Returns(_repositoryMock.Object);

            _unitOfWorkMock.Setup(o => o.SaveAsync());

            _controller = new IngredientController(_unitOfWorkMock.Object);
        }