Beispiel #1
0
        private ProductMeal MakeProductMeal(Double amount)
        {
            Product     product        = (Product)productsComboBox.SelectedItem;
            var         currentProduct = (from p in dieterDBM.Products where p.Id == product.Id select p).First();
            ProductMeal productMeal    = new ProductMeal();

            if (currentProduct.IsUnit == 1)
            {
                productMeal.Amount       = amount;
                productMeal.Product      = currentProduct;
                productMeal.Kcal         = Convert.ToInt32(currentProduct.Kcal * amount);
                productMeal.Protein      = Convert.ToDouble(currentProduct.Protein * amount);
                productMeal.Fat          = Convert.ToDouble(currentProduct.Fat * amount);
                productMeal.Carbohydrate = Convert.ToDouble(currentProduct.Carbohydrate * amount);
            }
            else
            {
                productMeal.Amount       = amount;
                productMeal.Product      = currentProduct;
                productMeal.Kcal         = Convert.ToInt32(currentProduct.Kcal * (amount / 100));
                productMeal.Protein      = Convert.ToDouble(currentProduct.Protein * (amount / 100));
                productMeal.Fat          = Convert.ToDouble(currentProduct.Fat * (amount / 100));
                productMeal.Carbohydrate = Convert.ToDouble(currentProduct.Carbohydrate * (amount / 100));
            }
            return(productMeal);
        }
Beispiel #2
0
        private void AddProductToMeal(double amount)
        {
            dieterDBM = new DieterDBM();
            ProductMeal productMeal = MakeProductMeal(amount);
            var         currentMeal = (from meal in dieterDBM.Meals where meal.Id == mealId select meal).First();

            currentMeal.ProductMeals.Add(productMeal);
            SumNutritionalContents(currentMeal);
            dieterDBM.SubmitChanges();
            dieterDBM.Dispose();
            Clear();
            InitProductMealsList();
        }
Beispiel #3
0
        private void DeleteProductFromMealClick(object sender, RoutedEventArgs e)
        {
            int id = Utils.GetIdFromUGrid((UniformGrid)((Button)sender).Parent);

            dieterDBM = new DieterDBM();
            ProductMeal removedProductMeal = (from productMeal in dieterDBM.ProductMeal where productMeal.Id == id select productMeal).Single();

            dieterDBM.ProductMeal.DeleteOnSubmit(removedProductMeal);
            dieterDBM.SubmitChanges();

            var currentMeal = (from meal in dieterDBM.Meals where meal.Id == mealId select meal).First();

            SumNutritionalContents(currentMeal);
            dieterDBM.SubmitChanges();
            dieterDBM.Dispose();
            InitProductMealsList();
        }