예제 #1
0
        /// <summary>
        /// Deletes the selected ingredient from the <see cref="RecipeIngredientListBox"/> from the <see cref="Recipe.Ingredients"/>
        /// of the selected recipe from the <see cref="RecipeIngredientDelete"/>.
        /// </summary>
        /// <param name="sender"><see cref="ApparatusListBox"/></param>
        /// <param name="e">Event Arguments</param>
        private void RecipeIngredientDelete_Click(object sender, RoutedEventArgs e)
        {
            Recipe recipe = this.RecipesListBox.SelectedItem as Recipe;
            QuantifiedIngredient quantifiedIngredient = this.RecipeIngredientListBox.SelectedItem as QuantifiedIngredient;

            recipe.Ingredients.Remove(quantifiedIngredient);
        }
예제 #2
0
        /// <summary>
        /// Executes when the <see cref="SubmitButton"/> for the <see cref="NewIngredientDialog"/> is clicked.
        /// Generates ingredient, with quantity and units, from the form and executes the <see cref="dialogClosingHandler"/>.
        /// </summary>
        /// <param name="sender"> <see cref="SubmitButton"/></param>
        /// <param name="e"> event arguments</param>
        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            QuantifiedIngredient ingredient = new QuantifiedIngredient(this.NameTextBox.Text)
            {
                Quantity = this.QuantityTextBox.Text,
                Units    = this.UnitsComboBox.Text
            };

            this.dialogClosingHandler(false, ingredient);
            this.dialogClosingHandler = null;
        }
예제 #3
0
 /// <summary>
 /// Handles dialog closing for an already existing ingredient that is double clicked
 /// which results in a prompt for <see cref="QuantifiedIngredient.Quantity"/> and <see cref="QuantifiedIngredient.Units"/> before adding it to the
 /// <see cref="RecipeIngredientListBox"/>
 /// </summary>
 /// <param name="isCancelled">TRUE if dialog is cancelled.</param>
 /// <param name="outIngredient">Ingredient created by the closing dialog.</param>
 private void HandleQuantityDialogClosing(bool isCancelled, QuantifiedIngredient outIngredient)
 {
     if (!isCancelled)
     {
         if (this.RecipesListBox.SelectedItem is Recipe recipe)
         {
             recipe.Ingredients.Add(outIngredient);
         }
     }
     CloseDialog();
 }
예제 #4
0
 public void CleanUp()
 {
     controller                = new DrinkController();
     TestVodka                 = null;
     TestJuice                 = null;
     TestVodkaJuice            = null;
     TestVodkaIngre            = null;
     TestJuiceIngre            = null;
     bar                       = null;
     quantifiedIngredientVodka = null;
     quantifiedIngredientJuice = null;
     TestHelper.DeleteAllInDB();
 }
예제 #5
0
        public void CheckIfDrinkNameExists()
        {
            //setup
            DrinkDB       drinkDB = new DrinkDB();
            List <String> names   = new List <string>();

            names.Add("testJuiceVodka");

            Ingredient testVodka = new Ingredient("testVodka", true, 37);
            Ingredient testJuice = new Ingredient("testJuice", true, 0);

            IngredientDB ingredientDB = new IngredientDB();

            ingredientDB.Insert(testVodka);
            ingredientDB.Insert(testJuice);

            MeasurementDB measurementDB = new MeasurementDB();

            Measurement measurement = measurementDB.Find("cl");

            QuantifiedIngredient quantifiedIngredientVodka = new QuantifiedIngredient(8, testVodka, measurement);
            QuantifiedIngredient quantifiedIngredientJuice = new QuantifiedIngredient(16, testJuice, measurement);

            List <QuantifiedIngredient> quantifiedIngredientsList = new List <QuantifiedIngredient>();

            quantifiedIngredientsList.Add(quantifiedIngredientVodka);
            quantifiedIngredientsList.Add(quantifiedIngredientJuice);

            Drink drink = new Drink(names, quantifiedIngredientsList, "Bland");

            Drink drinkWithId = drinkDB.Insert(drink);

            drinkDB.InsertDrinkNames(names.First(), drinkWithId.Id);

            QuantifiedIngredientDB quantifiedIngredientDB = new QuantifiedIngredientDB();

            quantifiedIngredientDB.Insert(quantifiedIngredientsList, drinkWithId.Id);

            //act
            bool drinkNameExists = drinkDB.CheckDrinkName(drinkWithId.Names.First());

            //assert
            Assert.AreEqual(drinkNameExists, true);
        }
예제 #6
0
        public void TestFindDrinkPrice()
        {
            FillDataToTheDataBase();
            //setup

            DrinkController dc = new DrinkController();
            BarController   bc = new BarController();


            bc.AddStockToBar(bar, new Stock()
            {
                Ingredient = TestVodkaIngre, Quantity = 100
            });
            bc.AddStockToBar(bar, new Stock()
            {
                Ingredient = TestJuiceIngre, Quantity = 100
            });
            int vodkaSellingPrice = 50;
            int juiceSellingPrice = 10;

            controller.InsertDrinkPrice(bar, new Price()
            {
                BuyingPrice = 10, SellingPrice = vodkaSellingPrice, Ingredient = TestVodkaIngre
            });
            controller.InsertDrinkPrice(bar, new Price()
            {
                BuyingPrice = 2, SellingPrice = juiceSellingPrice, Ingredient = TestJuiceIngre
            });

            //act
            double priceForVodkaJuice        = controller.FindDrinkPriceById(TestVodkaJuice.Id, bar.ID);
            double ActualPriceVodkaJuice     = 0;
            QuantifiedIngredient QIngreVodka = TestVodkaJuice.Ingredients.Where(e => e.Ingredient.Id == TestVodkaIngre.Id).First();
            QuantifiedIngredient QIngreJuice = TestVodkaJuice.Ingredients.Where(e => e.Ingredient.Id == TestJuiceIngre.Id).First();

            ActualPriceVodkaJuice += vodkaSellingPrice * QIngreVodka.Quantity;
            ActualPriceVodkaJuice += juiceSellingPrice * QIngreJuice.Quantity;

            //Assert
            Assert.AreEqual(ActualPriceVodkaJuice, priceForVodkaJuice);
        }
예제 #7
0
        public async Task <IActionResult> PutSupplies(string userId, QuantifiedIngredient quantifiedIngredient)
        {
            var currentUserId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (userId != currentUserId)
            {
                return(Unauthorized());
            }

            var query = from s in _context.Supplies where s.IngrName == quantifiedIngredient.Ingredient.Name select s;

            foreach (var s in query)
            {
                _context.Entry(s).State = EntityState.Deleted;
            }
            var updatedSupplies = new Supplies()
            {
                Quantity = quantifiedIngredient.Quantity,
                UnitName = quantifiedIngredient.Unit.Name,
                IngrName = quantifiedIngredient.Ingredient.Name,
                UserId   = userId
            };

            await _context.Supplies.AddAsync(updatedSupplies);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SuppliesExists(updatedSupplies))
                {
                    return(NotFound());
                }

                throw;
            }

            return(NoContent());
        }
예제 #8
0
        private void FillDataToTheDataBase()
        {
            #region Make bar
            BarController     bc      = new BarController();
            ManagerController mc      = new ManagerController();
            Manager           manager = new Manager("TestName", "TestPhonenumber", "TestEmail", "TestUsername", null);
            Manager           m       = mc.CreateManager(manager, "TestPassword");

            Country country = LocationDB.Instance.getCountryById(1);
            if (country is null)
            {
                Assert.Fail("Country is null");
            }
            Zipcode zip = LocationDB.Instance.findZipById(1);
            Address a   = new Address("TestVej", zip);
            zip.Country = country;
            a.Zipcode   = zip;

            Bar bar = new Bar
            {
                Address     = a,
                Email       = "TestBarEmail",
                Name        = "TestBarName",
                PhoneNumber = "TestBarP",
                Username    = "******"
            };
            this.bar = bc.Create(bar, m.Id, "TestPassword");
            #endregion

            IngredientController ingredientController = new IngredientController();

            List <Drink> drinks = new List <Drink>();


            Ingredient vodka = new Ingredient
            {
                Name       = "TestVodka",
                Measurable = true,
                Alch       = 37.5
            };

            Ingredient juice = new Ingredient
            {
                Name       = "TestJuice",
                Measurable = true,
                Alch       = 0
            };

            TestVodkaIngre = ingredientController.Create(vodka);
            TestJuiceIngre = ingredientController.Create(juice);


            quantifiedIngredientVodka = new QuantifiedIngredient
            {
                Quantity    = 6,
                Ingredient  = ingredientController.Find("TestVodka").First(), //We would like it to throw an exception here, as it's a test
                Measurement = ingredientController.FindMeasurement("cl")
            };

            quantifiedIngredientJuice = new QuantifiedIngredient
            {
                Quantity    = 2,
                Ingredient  = ingredientController.Find("TestJuice").First(), //We would like it to throw an exception here, as it's a test
                Measurement = ingredientController.FindMeasurement("cl")
            };

            Drink drinkVodkaJuice = new Drink
            {
                Recipe = "TestVodkaJuiceRecipe",
                Names  = new List <string>()
                {
                    "TestName1", "TestName2"
                },
                Ingredients = new List <QuantifiedIngredient>()
                {
                    quantifiedIngredientJuice, quantifiedIngredientVodka
                }
            };

            Drink drinkVodka = new Drink
            {
                Recipe = "TestVodkaRecipe",
                Names  = new List <string>()
                {
                    "TestNameVodka"
                },
                Ingredients = new List <QuantifiedIngredient>()
                {
                    quantifiedIngredientVodka
                }
            };

            Drink drinkJuice = new Drink
            {
                Recipe = "TestJuiceRecipe",
                Id     = 3,
                Names  = new List <string>()
                {
                    "TestJuice", "TestAppelsinjuice"
                },
                Ingredients = new List <QuantifiedIngredient>()
                {
                    quantifiedIngredientJuice
                }
            };

            TestVodka      = controller.Create(drinkVodka);
            TestJuice      = controller.Create(drinkJuice);
            TestVodkaJuice = controller.Create(drinkVodkaJuice);
        }