示例#1
0
        public void RenderTheRightView_AddIngredient_WithTheCorrectModel_IngredientViewModel_WhenModelStateIsNotValid()
        {
            //Arrange
            var ingredientsServiceMock    = new Mock <IIngredientsService>();
            var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>();
            var recipesServiceMock        = new Mock <IRecipesService>();
            var mappingServiceMock        = new Mock <IMappingService>();
            var controller = new IngredientsController(ingredientsServiceMock.Object, foodCategoriesServiceMock.Object, recipesServiceMock.Object, mappingServiceMock.Object);

            AddIngredientViewModel ingredientModel = new AddIngredientViewModel();

            ingredientModel.Name = null;
            var selectedFoodCategoryId = Guid.NewGuid();

            ingredientModel.SelectedFoodCategoryId  = selectedFoodCategoryId;
            ingredientModel.PricePerMeasuringUnit   = 1.80m;
            ingredientModel.QuantityInMeasuringUnit = 2;

            var validationContext = new ValidationContext(ingredientModel, null, null);
            var validationResults = new List <ValidationResult>();

            Validator.TryValidateObject(ingredientModel, validationContext, validationResults, true);
            foreach (var validationResult in validationResults)
            {
                controller.ModelState.AddModelError(validationResult.MemberNames.First(), validationResult.ErrorMessage);
            }

            //Act & Assert
            controller.WithCallTo(x => x.AddIngredient(ingredientModel))
            .ShouldRenderView("AddIngredient")
            .WithModel <AddIngredientViewModel>()
            .AndModelError("Name");
        }
示例#2
0
        public IActionResult Add(string type)
        {
            switch (type)
            {
            case "Dish":
                var model = new AddDishViewModel();
                this.SetValuesToDishViewModel(model);
                return(this.View("AddDish", model));

            case "Drink":
                var drinkViewModel = new AddDrinkViewModel();
                this.SetValuesToDrinkViewModel(drinkViewModel);
                return(this.View("AddDrink", drinkViewModel));

            case "Ingredient":
                var ingredientViewModel = new AddIngredientViewModel();
                this.SetValuesToIngredientViewModel(ingredientViewModel);
                return(this.View("AddIngredient", ingredientViewModel));

            case "Allergen":
                return(this.View("AddAllergen", new AllergenViewModel()));

            case "DishCategory":
                return(this.View("AddDishCategory", new AddCategoryViewModel()));

            case "DrinkCategory":
                return(this.View("AddDrinkCategory", new AddCategoryViewModel()));
            }

            return(this.View());
        }
示例#3
0
        public AddIngredientPage()
        {
            InitializeComponent();
            var viewModel = new AddIngredientViewModel();

            BindingContext = viewModel;
        }
        public void AddIngredientShouldWorkCorrectly()
        {
            var addIngredient = new AddIngredientViewModel()
            {
                Name        = "test",
                AllergensId = new List <int>()
                {
                    1, 2
                },
            };

            MyController <ManageController>
            .Calling(c => c.AddIngredient(addIngredient))
            .ShouldHave()
            .ValidModelState()
            .AndAlso()
            .ShouldReturn()
            .RedirectToAction("Index");

            addIngredient.Name = null;

            MyController <ManageController>
            .Calling(c => c.AddIngredient(addIngredient))
            .ShouldReturn()
            .View();
        }
示例#5
0
        public async Task <IActionResult> AddIngredient(int id)
        {
            var recipe = await _context.Recipes.SingleOrDefaultAsync(r => r.ID == id);

            var ingredientsAll = await _context.Ingredients.ToListAsync();

            var amounts = await _context.Amounts.Where(a => a.RecipeID == id).Include(a => a.Child).Include(a => a.Parent).ToListAsync();

            List <Ingredient> ingredients = new List <Ingredient>();

            foreach (Ingredient i in ingredientsAll)
            {
                ingredients.Add(i);
            }

            foreach (Ingredient i in ingredientsAll)
            {
                foreach (Amount a in amounts)
                {
                    if (a.Child == i)
                    {
                        ingredients.Remove(i);
                    }
                }
            }

            AddIngredientViewModel aivm = new AddIngredientViewModel {
                Recipe = recipe, Ingredients = ingredients
            };

            return(View(aivm));
        }
示例#6
0
        public ActionResult AddIngredient(AddIngredientViewModel addIngredientViewModel)
        {
            if (ModelState.IsValid)
            {
                var ingredient = repository.GetIngredientByName(addIngredientViewModel.Ingredient);
                if (ingredient == null)
                {
                    ingredient = new Ingredient()
                    {
                        Name = addIngredientViewModel.Ingredient
                    };
                    dbContext.Ingredients.Add(ingredient);
                    dbContext.SaveChanges();
                }

                var ingredientSize = new IngredientSize()
                {
                    Amount       = addIngredientViewModel.Amount,
                    IngredientID = ingredient.Id,
                    UnitID       = addIngredientViewModel.Unit
                };

                var recipe = repository.GetRecipe(addIngredientViewModel.IngredientRecipeID);

                recipe.Ingredients.Add(ingredientSize);

                repository.UpdateRecipe(recipe);

                TempData["Message"] = $"{addIngredientViewModel.Ingredient} added to {recipe.Title}";
            }

            return(RedirectToAction("Details", new { id = addIngredientViewModel.IngredientRecipeID }));
        }
        /*************** INGREDIENT HANDLERS ***************/

        public IActionResult GetIngredients()
        {
            AddIngredientViewModel model = new AddIngredientViewModel();

            model.ExistingIngredients = _tomasosContext.Produkt.ToList();

            return(PartialView("_AddIngredientPartial", model));
        }
        public IHttpActionResult Post(AddIngredientViewModel model)
        {
            var ingredient = new Ingredient {
                Name = model.Name
            };

            _ingredientRepository.Add(ingredient);
            return(Ok(ingredient));
        }
示例#9
0
        public IActionResult GetIngredients()
        {
            AddIngredientViewModel model = new AddIngredientViewModel
            {
                ListIngredients = _context.Produkt.ToList()
            };

            return(PartialView("_Ingredients", model));
            //return View(model);
        }
示例#10
0
        public async Task <IActionResult> AddIngredient(AddIngredientViewModel vm)
        {
            if (await _ingredientServices.IngredientWithThatNameExists(vm.Name))
            {
                ModelState.AddModelError(string.Empty, "Ingredient with that name already exists.");
                return(View());
            }
            await _ingredientServices.AddAsync(vm.Name, vm.Type);

            return(View());
        }
示例#11
0
        public async Task <IActionResult> AddIngredient(AddIngredientViewModel ingredient)
        {
            if (!this.ModelState.IsValid)
            {
                this.SetValuesToIngredientViewModel(ingredient);
                return(this.View(ingredient));
            }

            await this.ingredientService.AddIngredientAsync(ingredient);

            return(this.RedirectToAction("Index"));
        }
示例#12
0
        public async Task AddIngredientAsync(AddIngredientViewModel ingredient)
        {
            var ingredientToAdd = new Ingredient()
            {
                Name      = ingredient.Name,
                Allergens = this.allergenService.GetAllergensWithIds(ingredient.AllergensId.ToList()).ToList(),
            };

            await this.ingredientRepository.AddAsync(ingredientToAdd);

            await this.ingredientRepository.SaveChangesAsync();
        }
示例#13
0
        public async Task <IActionResult> AddIngredient(AddIngredientViewModel aivm)
        {
            Amount a = new Amount {
                Ounces = aivm.Amount, RecipeID = aivm.RecipeID, IngredientID = aivm.IngredientID, Core = true
            };

            _context.Add(a);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(List)));
        }
示例#14
0
        public IActionResult AddIngredient(AddIngredientViewModel form)
        {
            if (ModelState.IsValid)
            {
                _tomasosContext.Produkt.Add(form.NewIngredient);
                _tomasosContext.SaveChanges();
            }

            AddIngredientViewModel model = new AddIngredientViewModel();

            model.ExistingIngredients = _tomasosContext.Produkt.ToList();
            return(RedirectToAction("AlterMenu", "Admin"));
        }
示例#15
0
        public IActionResult AddIngredients(int DrinkId)
        {
            Drink drinkizzle            = data.Drinks.Find(DrinkId);
            AddIngredientViewModel AIVM = new AddIngredientViewModel
            {
                drinkOrder           = drinkizzle,
                drinkId              = DrinkId,
                custom               = new Customization(),
                customizationOptions = new string[] { "Make Double", "Add Juice", "Make Vegan", "Add Little Umbrella", "Add Frosty Mug", "Salt on the Rim" }
            };

            return(View(AIVM));
        }
示例#16
0
        private void AddIngredient()
        {
            var vm  = new AddIngredientViewModel(Recipe);
            var win = new AddIngredientWindow()
            {
                DataContext = vm
            };

            if (win.ShowDialog() ?? false)
            {
                Recipe.Ingredients.Add(vm.Ingredient);
            }
        }
示例#17
0
        private void AddIngredient()
        {
            var vm  = new AddIngredientViewModel(SelectedRecipe);
            var win = new AddIngredientWindow()
            {
                DataContext = vm
            };

            if (win.ShowDialog() ?? false)
            {
                SelectedRecipe.Ingredients.Add(vm.Ingredient);
                SqliteDBManager.Instance.SaveDBChanges();
            }
        }
示例#18
0
        public IActionResult RemoveIngredient(int id)
        {
            var produkt = _tomasosContext.Produkt.SingleOrDefault(x => x.ProduktId == id);

            if (produkt != null)
            {
                _tomasosContext.Produkt.Remove(produkt);
                _tomasosContext.SaveChanges();
            }

            AddIngredientViewModel model = new AddIngredientViewModel();

            model.ExistingIngredients = _tomasosContext.Produkt.ToList();
            return(PartialView("_IngredientListPartial", model));
        }
        public ActionResult AddIngredient()
        {
            var foodCategories = this.foodCategoriesService.GetAllFoodCategories()
                                 .Select(this.mappingService.Map <FoodCategoryViewModel>);
            var model = new AddIngredientViewModel();

            model.FoodCategories = foodCategories;

            var recipes = this.recipesService.GetAllRecipes()
                          .Select(this.mappingService.Map <RecipeViewModel>);

            model.Recipes = recipes;

            return(this.View(model));
        }
        public ActionResult AddIngredient(AddIngredientViewModel ingredientModel)
        {
            if (!this.ModelState.IsValid)
            {
                this.AddToastMessage(toastrFailureTitle, string.Format(toastrAddObjectFailureMessage, ingredientModel.Name), ToastType.Error);
                return(this.View(ingredientModel));
            }

            var foodCategoryId = ingredientModel.SelectedFoodCategoryId;
            var recipeId       = ingredientModel.SelectedRecipeId;

            this.ingredientsService.AddIngredient(ingredientModel.Name, foodCategoryId, ingredientModel.PricePerMeasuringUnit, ingredientModel.QuantityInMeasuringUnit, recipeId);

            this.AddToastMessage(toastrSuccessTitle, string.Format(toastrAddObjectSuccessMessage, ingredientModel.Name), ToastType.Success);
            return(this.RedirectToAction("Index", "Ingredients"));
        }
示例#21
0
        public IActionResult MakeOrder(AddIngredientViewModel AIVM)
        {
            Drink drink = data.Drinks.Find(AIVM.drinkId);

            data.Add(AIVM.custom);
            data.SaveChanges();
            decimal Price = drink.Price;

            if (AIVM.custom.FrostyMug == true)
            {
                Price += (decimal)1.50;
            }
            if (AIVM.custom.HasJuice == true)
            {
                Price += (decimal)2.50;
            }
            if (AIVM.custom.IsDouble == true)
            {
                Price += (decimal)4.75;
            }
            if (AIVM.custom.LittleUmbrella == true)
            {
                Price -= (decimal).75;
            }
            if (AIVM.custom.SaltyRim == true)
            {
                Price += (decimal).75;
            }
            if (AIVM.custom.Vegan == true)
            {
                Price += (decimal).15;
            }
            DrinkOrder order = new DrinkOrder
            {
                Customization   = AIVM.custom,
                OrderedDrink    = drink,
                CustomizationId = AIVM.custom.CustomizationId,
                DrinkId         = AIVM.drinkId,
                TimeOrdered     = DateTime.Now,
                TotalPrice      = Price
            };

            data.Add(order);
            data.SaveChanges();
            return(View("Index", data.Drinks));
        }
示例#22
0
        public IActionResult AddIngredient(AddIngredientViewModel product)
        {
            if (ModelState.IsValid)
            {
                var checkIngredient = _context.Produkt.Any(i => i.ProduktNamn.Equals(product.NewIngredient));
                if (!checkIngredient)
                {
                    _context.Produkt.Add(product.NewIngredient);
                    _context.SaveChanges();
                }
            }
            AddIngredientViewModel model = new AddIngredientViewModel
            {
                ListIngredients = _context.Produkt.ToList()
            };

            return(PartialView("_Ingredients", model));
        }
示例#23
0
        public async Task <IActionResult> RemoveIngredient(int id)
        {
            // Hämta Session Listan, filtrera bort ID, returera session
            var serializedValue = (HttpContext.Session.GetString("ingredients"));
            var produktList     = JsonConvert.DeserializeObject <List <Produkt> >(serializedValue);

            produktList = produktList.Where(p => p.ProduktId != id).ToList();

            var temp = JsonConvert.SerializeObject(produktList);

            HttpContext.Session.SetString("ingredients", temp);
            var vm = new AddIngredientViewModel
            {
                Ingredients     = produktList,
                IngredientsList = await _dishService.GetDishIngredientsAsync()
            };

            return(PartialView("_NewDishAddIngredient", vm));
        }
示例#24
0
        public async Task <PartialViewResult> OnPostAddIngredientModalPartialAsync(AddIngredientViewModel model)
        {
            Recipe = await recipeController.GetRecipeAsync(model.RecipeIngredient.RecipeId);

            ModelState.Remove("Name"); //AIrza Remove property from main model
            if (ModelState.IsValid)
            {
                Recipe.Ingredients.Add(model.RecipeIngredient);
                await recipeController.UpdateRecipeAsync(Recipe);
            }
            var ingredients = await ingredientController.GetIngredientsAsync();

            model.Ingredients = ingredients;
            return(new PartialViewResult
            {
                ViewName = "_AddIngredientModalPartial",
                ViewData = new ViewDataDictionary <AddIngredientViewModel>(ViewData, model)
            });
        }
示例#25
0
        public async Task <IActionResult> AddIngredient(AddIngredientViewModel vm)
        {
            List <Produkt> produktList;

            if (HttpContext.Session.GetString("ingredients") == null)
            {
                produktList = new List <Produkt>();
            }
            else
            {
                var serializedValue = (HttpContext.Session.GetString("ingredients"));
                produktList = JsonConvert.DeserializeObject <List <Produkt> >(serializedValue);
            }
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrWhiteSpace(vm.NewIngredient))
                {
                    var produkt = await _produktService.CreateProdukt(vm.NewIngredient);

                    if (produktList.All(p => p.ProduktNamn != produkt.ProduktNamn))
                    {
                        produktList.Add(produkt);
                    }
                }
                else
                {
                    var selectedProdukt = await _produktService.CreateProdukt(vm.SelectedIngredient);

                    if (produktList.All(p => p.ProduktNamn != selectedProdukt.ProduktNamn))
                    {
                        produktList.Add(selectedProdukt);
                    }
                }
                var temp = JsonConvert.SerializeObject(produktList);
                HttpContext.Session.SetString("ingredients", temp);
            }
            vm.Ingredients     = produktList;
            vm.IngredientsList = await _dishService.GetDishIngredientsAsync();

            ModelState.Clear();
            return(PartialView("_NewDishAddIngredient", vm));
        }
        public async Task AddIngredientAsyncWorksCorrectly()
        {
            await this.PopulateDB();

            var addIngredient = new AddIngredientViewModel()
            {
                Name        = "newIngredient",
                AllergensId = new List <int>()
                {
                    1, 2,
                },
            };

            await this.IngredientService.AddIngredientAsync(addIngredient);

            var ingredient            = this.DbContext.Ingredients.FirstOrDefault(x => x.Name == "newIngredient");
            var expectedAllergenCount = 2;

            Assert.NotNull(ingredient);
            Assert.Equal(expectedAllergenCount, ingredient.Allergens.Count);
        }
示例#27
0
        public async Task <PartialViewResult> OnGetAddIngredientModalPartialAsync(int recipeId)
        {
            var ingredients = await ingredientController.GetIngredientsAsync();

            var recipeIngredient = new RecipeIngredient
            {
                Amount   = 1,
                RecipeId = recipeId
            };
            var addIngredient = new AddIngredientViewModel
            {
                Ingredients      = ingredients,
                RecipeIngredient = recipeIngredient
            };

            return(new PartialViewResult
            {
                ViewName = "_AddIngredientModalPartial",
                ViewData = new ViewDataDictionary <AddIngredientViewModel>(ViewData, addIngredient)
            });
        }
示例#28
0
        public void RedirectToActionIndex_WithTheCorrectModel__WhenModelStateIsValid()
        {
            //Arrange
            var ingredientsServiceMock    = new Mock <IIngredientsService>();
            var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>();
            var recipesServiceMock        = new Mock <IRecipesService>();
            var mappingServiceMock        = new Mock <IMappingService>();
            var controller = new IngredientsController(ingredientsServiceMock.Object, foodCategoriesServiceMock.Object, recipesServiceMock.Object, mappingServiceMock.Object);

            AddIngredientViewModel ingredientModel = new AddIngredientViewModel();

            ingredientModel.Name = "Pink Tomato";
            var selectedFoodCategoryId = Guid.NewGuid();

            ingredientModel.SelectedFoodCategoryId  = selectedFoodCategoryId;
            ingredientModel.PricePerMeasuringUnit   = 1.80m;
            ingredientModel.QuantityInMeasuringUnit = 2;

            //Act & Assert
            controller.WithCallTo(x => x.AddIngredient(ingredientModel))
            .ShouldRedirectTo(x => x.Index());
        }
示例#29
0
        public async Task <IActionResult> AddIngredient(AddIngredientViewModel vm)
        {
            await _ingredientServices.AddAsync(vm.Name, vm.Type);

            return(View());
        }
示例#30
0
 private void SetValuesToIngredientViewModel(AddIngredientViewModel addIngredientViewModel)
 {
     addIngredientViewModel.Allergens = this.allergenService.GetAllergensWithId().Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList();
 }