Esempio n. 1
0
 private void tvRation_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
 {
     if (tvRation.SelectedItem != null)
     {
         if ((tvRation.SelectedItem is MealProduct))
         {
             MealProduct product = (tvRation.SelectedItem as MealProduct);
             tvRation.ItemsSource  = service.RemoveProduct(product.ID);
             pbCalories.Value      = service.GetCaloriesSum();
             check1.Text           = service.GetCaloriesSum().ToString();
             infoPanel.DataContext = null;
             cmbMeals.Items.Refresh();
         }
         else
         {
             MealTime meal = (tvRation.SelectedItem as MealTime);
             tvRation.ItemsSource   = service.RemoveMealTime(meal.Name);
             cmbMeals.SelectedValue = service.GetDefaultMeal();
             pbCalories.Value       = service.GetCaloriesSum();
             check1.Text            = service.GetCaloriesSum().ToString();
             infoPanel.DataContext  = null;
             tvRation.Items.Refresh();
             cmbMeals.Items.Refresh();
         }
     }
 }
        public void ObjectNotTypeTest_BulkProductIsAbstractProduct()
        {
            var    obj     = new MealProduct();
            string message = "Problem";

            ValidationHelper.ObjectNotType <AbstractGood>(obj, message);
        }
Esempio n. 3
0
        public async Task <bool> AddProductToMealAsync(int mealId, int productId)
        {
            _logger.LogInformation("Entered in AddProductToMeal with mealId {}, productId {}", mealId, productId);
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            bool exists = await _ctx.MealProducts.AnyAsync(mp => mp.MealId == mealId && mp.ProductId == productId);

            if (!exists)
            {
                MealProduct mealProduct = new MealProduct
                {
                    MealId    = mealId,
                    ProductId = productId
                };
                await _ctx.AddAsync(mealProduct);

                await _ctx.SaveChangesAsync();

                stopWatch.Stop();

                _logger.LogInformation("Elapsed time in {0} ms", stopWatch.ElapsedMilliseconds);

                return(true);
            }

            _logger.LogWarning("Product with id {} is already present in the meal {}", productId, mealId);
            stopWatch.Stop();

            _logger.LogInformation("Elapsed time in {0} ms", stopWatch.ElapsedMilliseconds);
            return(false);
        }
Esempio n. 4
0
        public async Task <bool> RemoveProductFromMealAsync(int mealId, int productId)
        {
            _logger.LogInformation("Entered in RemoveProductFromMeal with mealId {}, productId {}", mealId, productId);
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            MealProduct mealProduct = await _ctx.MealProducts.FirstOrDefaultAsync(mp => mp.MealId == mealId && mp.ProductId == productId);

            if (mealProduct == null)
            {
                stopWatch.Stop();
                _logger.LogInformation("Elapsed time in {0} ms", stopWatch.ElapsedMilliseconds);

                _logger.LogError("No product with id {} is associated with meal {}", productId, mealId);

                return(false);
            }
            _ctx.Remove(mealProduct);

            await _ctx.SaveChangesAsync();

            stopWatch.Stop();

            _logger.LogInformation("Elapsed time in {0} ms", stopWatch.ElapsedMilliseconds);

            return(true);
        }
Esempio n. 5
0
        public IActionResult OnPost([FromRoute] int productId, [FromRoute] int mealId, [FromForm] decimal Weight)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Meal    = mealData.GetById(mealId);
            Meal    = mealData.LoadIngredients(Meal);
            Product = productData.GetById(productId);

            MealProduct = new MealProduct();
            var modMeal = Meal;

            if (Weight > 0)
            {
                MetaAddIngredientsAndStatistics(productId, mealId, Weight, modMeal);
            }
            else if (Weight == 0)
            {
                MetaRemoveIngredientsAndStatistics(mealId, productId, modMeal);
            }

            mealData.Update(Meal);
            mealData.Commit();

            TempData["Message"] = "Meal saved!";
            return(RedirectToPage("./UpdateMeal", new { mealId = Meal.MealId }));
        }
Esempio n. 6
0
        public async Task RemoveProductFromMeal(int mealId, int productId)
        {
            MealProduct mealProduct = await _ctx.MealProducts.FirstOrDefaultAsync(mp => mp.MealId == mealId && mp.ProductId == productId);

            _ctx.Remove(mealProduct);

            await _ctx.SaveChangesAsync();
        }
        public void MakePurchaseTest_BadBuyOneProductCallIDException2()
        {
            var name1 = new MealProduct("Bread", 5, 90);
            var prod2 = new MealProduct("Cucumber", 1, 60);

            _repository.Register(name1);

            var cast = _repository.MakePurchase(prod2);
        }
        public void MakePurchaseTest_BadBuyOneProductCallIDException()
        {
            var name1 = new MealProduct("Butter", 1, 30);
            var prod2 = new Clothes("White jeans", 2, 150);

            _repository.Register(name1);

            var cast = _repository.MakePurchase(prod2);
        }
Esempio n. 9
0
 private void tvRation_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
 {
     if (tvRation.SelectedItem is MealProduct)
     {
         MealProduct product = service.GetMealProduct((MealProduct)tvRation.SelectedItem);
         infoPanel.DataContext = product;
         sl.Value = product.Grams;
     }
 }
        public void MakePurchaseTest_GoodBuyOneProduct2()
        {
            var name1 = new MealProduct("Oil", 1, 100);

            _repository.Register(name1);

            var cast = _repository.MakePurchase(name1);

            Assert.AreEqual(name1.Price, cast);
        }
        public void AddTest_AddGoodProduct()
        {
            var name = new MealProduct("Pizza", 10, 20);

            _repository.Register(name);

            var result = _repository.GetProduct(int.MinValue + 5);

            Assert.IsNotNull(result);
            Assert.AreEqual(name, result);
            Assert.AreEqual(name.Name, result.Name);
        }
Esempio n. 12
0
 public static MealProductDTO MealProductToDto(MealProduct product, MealProductDTO dto = null)
 {
     if (product != null)
     {
         return(dto = dto ?? new MealProductDTO
         {
             MealId = product.MealId,
             ProductId = product.ProductId,
             ProductWeight = product.ProductWeight,
         });
     }
     return(null);
 }
Esempio n. 13
0
 public static MealProduct DtoToMealProduct(MealProductDTO product, MealProduct ent = null)
 {
     if (product != null)
     {
         return(ent = ent ?? new MealProduct
         {
             MealId = product.MealId,
             ProductId = product.ProductId,
             ProductWeight = product.ProductWeight,
         });
     }
     return(null);
 }
        public void AddTest_AddGoodProduct2()
        {
            var name1 = new MealProduct("Desk", 45, 200);
            var name2 = new MealProduct("Jogurt", 15, 150);

            _repository.Register(name1);
            _repository.Register(name2);

            var result = _repository.GetProduct(int.MinValue + 6);

            Assert.IsNotNull(result);
            Assert.AreEqual(name2, result);
            Assert.AreEqual(name2.Name, result.Name);
        }
 public MealProduct GetMealProduct(MealProduct product)
 {
     for (int i = 0; i < dailyRation.mealTimes.Count; i++)
     {
         for (int j = 0; j < dailyRation.mealTimes[i].Products.Count; j++)
         {
             if (product.ID == dailyRation.mealTimes[i].Products[j].ID)
             {
                 return(dailyRation.mealTimes[i].Products[j]);
             }
         }
     }
     return(null);
 }
        public void MakePurchaseTest_BadBuyManyProducts2()
        {
            var prod1 = new MealProduct("Fish", 2, 34);
            var prod3 = new MealProduct("Meat", 5, 210);
            var prod4 = new MealProduct("Toast", 3, 100);

            _repository.Register(prod1);

            IEnumerable <AbstractGood> abstractProduct = new List <AbstractGood>
            {
                prod4,
                prod3
            };

            var cast = _repository.MakePurchases(abstractProduct);
        }
        public void UpdateTest_GoodUpdateReturnTrue2()
        {
            var prod1 = new MealProduct("Fish", 2, 34);
            var prod3 = new MealProduct("Toast", 3, 100);

            _repository.Register(prod1);
            _repository.Register(prod3);

            var prod4 = new MealProduct("Meat", 5, 210);

            prod4.ID = prod3.ID;

            var b = _repository.Update(prod4);

            Assert.IsTrue(b);
        }
        public void UpdateTest_BabUpdateReturnFalse2()
        {
            var prod1 = new MealProduct("Fish", 2, 34);
            var prod3 = new MealProduct("Toast", 3, 100);

            _repository.Register(prod1);
            _repository.Register(prod3);

            var prod4 = new MealProduct("Meat", 5, 210);

            prod4.ID = -458;

            var b = _repository.Update(prod4);

            Assert.IsFalse(b);
        }
Esempio n. 19
0
        public void UpdateTest_GoodUpdateMealProduct()
        {
            var obj = new MealProduct(_good.Name, _good.Amount, _good.Price)
            {
                ID = _good.ID
            };

            var service = new Service(_repositoryMoq.Object);

            service.Update(_good);

            Assert.AreNotEqual(_good.Name, obj.Name);

            _repositoryMoq
            .Verify(r => r.Update(It.IsAny <AbstractGood>()), () => Times.AtLeastOnce());    //---- as Moq test
        }
        public void MakePurchaseTest_GoodBuyManyProducts2()
        {
            var prod1 = new MealProduct("Fish", 2, 34);
            var prod2 = new MealProduct("Toast", 3, 100);

            _repository.Register(prod1);
            _repository.Register(prod2);

            IEnumerable <AbstractGood> abstractProduct = new List <AbstractGood>
            {
                prod1,
                prod2,
            };

            var cast = _repository.MakePurchases(abstractProduct);

            Assert.AreEqual(134, cast);
        }
Esempio n. 21
0
        public async Task <bool> AddProductToMeal(int mealId, int productId)
        {
            bool exists = await _ctx.MealProducts.AnyAsync(mp => mp.MealId == mealId && mp.ProductId == productId);

            if (!exists)
            {
                MealProduct mealProduct = new MealProduct
                {
                    MealId    = mealId,
                    ProductId = productId
                };
                await _ctx.AddAsync(mealProduct);

                await _ctx.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
Esempio n. 22
0
        private void sl_MouseLeave(object sender, MouseEventArgs e)
        {
            if (tvRation.SelectedItem is MealProduct && tvRation.SelectedItem != null)
            {
                MealProduct product = service.GetMealProduct((MealProduct)tvRation.SelectedItem);
                double      temp    = service.TestCalories(product.ID, sl.Value, product.Name);
                if (temp > pbCalories.Maximum)
                {
                    MessageBox.Show("Переполнение рациона");
                }
                else
                {
                    service.ChangeWeight(product.ID, sl.Value, product.Name);
                    pbCalories.Value      = service.GetCaloriesSum();
                    check1.Text           = service.GetCaloriesSum().ToString();
                    infoPanel.DataContext = product;

                    //tvRation.Items.Refresh();
                }
            }
        }
 public List <MealTime> AddProduct(Product product, string name)
 {
     for (int i = 0; i < dailyRation.mealTimes.Count; i++)
     {
         if (dailyRation.mealTimes[i].Name == name)
         {
             MealProduct mealProduct = new MealProduct
             {
                 Name     = product.Name,
                 Fats     = product.Fats,
                 Proteins = product.Proteins,
                 Carbs    = product.Carbs,
                 Calories = product.Calories,
                 Grams    = product.Grams,
                 ID       = ID
             };
             ID++;
             dailyRation.mealTimes[i].Products.Add(mealProduct);
             return(dailyRation.mealTimes);
         }
     }
     return(null);
 }
        public void ProductValidationTest_BadBulkProductCallValidationException()
        {
            var obj = new MealProduct("Chalk", 1, -891);

            ValidationHelper.ProductValidation(obj);
        }
        public void AddTest_AddBadProduct2()
        {
            var name1 = new MealProduct("Mask", 1, -56);

            _repository.Register(name1);
        }
        public void ProductValidationTest_GoodBulkProduct()
        {
            var obj = new MealProduct("Chalk", 1, 1);

            ValidationHelper.ProductValidation(obj);
        }
Esempio n. 27
0
 public MealProduct GetMealProduct(MealProduct product)
 {
     return(dailyRationDao.GetMealProduct(product));
 }