Esempio n. 1
0
        /// <summary>
        /// Adding the new food and weight of the food
        /// </summary>
        /// <param name="food"></param>
        /// <param name="weight"></param>
        public void Add(Food food, double weight)
        {
            var product = Foods.SingleOrDefault(f => f.Name.Equals(food.Name));

            if (product == null)
            {
                Foods.Add(food);
            }
        }
        public bool Add(string foodName, double weight)
        {
            var food = Foods.SingleOrDefault(f => f.Name == foodName);

            if (food != null)
            {
                Eating.Add(food, weight);
                Save();
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Add to meal and to product and all new of what use eat then save.
        /// </summary>
        /// <param name="food"></param>
        /// <param name="weight"></param>
        public void Add(Food food, double weight)
        {
            var product = Foods.SingleOrDefault(f => f.Name == food.Name);//because we return default(T);

            if (product == null)
            {//new product
                Foods.Add(food);
                Eating.Add(food, weight);
            }
            else
            {
                Eating.Add(product, weight);
            }
            Save();
        }
        /// <summary>
        /// Добавление продукта.
        /// </summary>
        /// <param name="foodName">Наименование продукта.</param>
        /// <param name="wieght">Вес продукта.</param>

        public void AddFood(Food food, float weight)
        {
            var product = Foods.SingleOrDefault(f => f.Name == food.Name);

            if (product == null)
            {
                Foods.Add(food);
                Eating.AddFoodToEating(food, weight);
            }
            else
            {
                Eating.AddFoodToEating(product, weight);
            }
            SetAll();
        }
Esempio n. 5
0
        /// <summary>
        /// Добавление нового продукта/занесение в прием пищи
        /// </summary>
        /// <param name="food"></param>
        /// <param name="weight"></param>
        public void Add(Food food, double weight)
        {
            var product = Foods.SingleOrDefault(x => x.Name == food.Name);

            if (product == null)
            {
                Foods.Add(food);
                Eating.Add(food, weight);
            }
            else
            {
                Eating.Add(food, weight);
            }
            Save();
        }
Esempio n. 6
0
 void ButtonModifyFoodCount_Click(object sender, RoutedEventArgs e)
 {
     if (dataGridFoods.SelectedItem != null)
     {
         object food = null;
         lock (Foods)
             food = Foods.SingleOrDefault(f => (int)ZooClient.GetProperty(f, "ID") == (int)ZooClient.GetProperty(dataGridFoods.SelectedItem, "ID"));
         ModifyFoodWindow modifyFoodWindow = new ModifyFoodWindow(this, food);
         bool?            isModified       = modifyFoodWindow.ShowDialog();
         if (isModified.HasValue && isModified.Value)
         {
             UpdateFoods();
         }
     }
 }
Esempio n. 7
0
 public FoodsViewModel(
     IFoodRepository foodRepository,
     INavigationService navigationService)
 {
     _foodRepository    = foodRepository;
     _navigationService = navigationService;
     this.WhenAnyValue(x => x.SelectedFood)
     .Where(x => x != null)
     .Subscribe(async food =>
     {
         var selectedFood = Foods.SingleOrDefault(f => f.Id == food.Id);
         var viewModel    = App.Container.Resolve <FoodDetailViewModel>(new NamedParameter("selectedFood", selectedFood));
         await _navigationService.NavigateAsync(viewModel);
     });
 }
Esempio n. 8
0
        public void Add(Food food, double weight)
        {
            var product = Foods.SingleOrDefault(f => f.Name == food.Name);

            if (product is null)
            {
                Foods.Add(food);
                Eating.AddFood(food, weight);
                SaveFood();
            }
            else
            {
                Eating.AddFood(product, weight);
                SaveFood();
            }
        }
Esempio n. 9
0
        public void Add(Food food, double weight)
        {
            var product = Foods.SingleOrDefault(f => f.FoodName == food.FoodName);

            if (product == null)
            {
                Foods.Add(food);
                Meal.Add(food, weight);
                Save();
            }
            else
            {
                Meal.Add(product, weight);
                Save();
            }
        }
        public void Add(Food food, decimal weight)
        {
            var product = Foods.SingleOrDefault(f => f.Name == food.Name);

            if (product == null)
            {
                Foods.Add(food);
                Eating.Add(food, (double)weight);
                Save();
            }
            else
            {
                Eating.Add(product, (double)weight);
                Save();
            }
        }
Esempio n. 11
0
        public void Add(Food food, double weight)
        {
            var product = Foods.SingleOrDefault(n => n.Name == food.ToString());

            if (product == null)
            {
                Foods.Add(food);
                Eating.Add(food, weight);
                Save();
            }
            else
            {
                Eating.Add(product, weight);
                Save();
            }
        }
Esempio n. 12
0
        public void AddEating(Food food, double quantity)
        {
            var product = Foods.SingleOrDefault(f => f.Name == food.Name);

            if (product == null)
            {
                Foods.Add(food);
                UserEating.AddProduct(food, quantity);
                SaveFoodData();
            }
            else
            {
                UserEating.AddProduct(product, quantity);
                SaveFoodData();
            }
        }
Esempio n. 13
0
        public void Add(Food food, double wieght)
        {
            Food product = Foods.SingleOrDefault((f) => f.Name == food.Name);

            if (product == null)
            {
                Foods.Add(food);
                Eating.Add(food, wieght);
                Save();
            }
            else
            {
                Eating.Add(product, wieght);
                Save();
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Добавление продукта в справочник продуктов, добавление в базу съеденного.
        /// </summary>
        /// <param name="food">Параметр - продукт.</param>
        /// <param name="weight">Параметр - вес продукта.</param>
        public void Add(Food food, double weight)
        {
            var product = Foods.SingleOrDefault(f => f.Name == food.Name);

            if (product == null)          // Новый продукт.
            {
                Foods.Add(food);          // Пополняем справочник продуктов.
                Eating.Add(food, weight); // Пополняем базу съеденного.
                Save();
            }
            else // Такой продукт уже когда-то ели.
            {
                Eating.Add(product, weight);
                Save();
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Метод добавления еды, если такого продукта нет было ранее, то добавляем новый.
        /// </summary>
        /// <param name="food"></param>
        /// <param name="calorie"></param>
        public void Add(Food food, double calorie)
        {
            var product = Foods.SingleOrDefault(f => f.Name == food.Name);

            if (product == null)
            {
                Foods.Add(food);
                Eating.Add(food, calorie);
                Save();
            }
            else
            {
                Eating.Add(product, calorie);
                Save();
            }
        }
Esempio n. 16
0
        public bool Add(Food food, double weight)
        {
            var product = Foods.SingleOrDefault(f => f.Name == food.Name);

            if (product == null) // request all food details
            {
                Foods.Add(food);
                Eating.Add(food, weight);
                Save();
            }
            else
            {
                Eating.Add(product, weight);
                Save();
            }
            return(false);
        }
        public virtual Tuple <bool, byte> DeleteFood(int id)
        {
            Food food    = Foods.SingleOrDefault(w => w.ID == id);
            bool success = false;

            if (food != null)
            {
                if (food.Animals.Count > 0)
                {
                    return(new Tuple <bool, byte>(false, (byte)ModelType.Animal));
                }
                Foods.Remove(food);
                try
                {
                    SaveChanges();
                    success = true;
                }
                catch (Exception e)
                {
                    Logger.LogError($"Exception removing food! Exception: {e.ToString()}", GetType(), $"DeleteFood(id: {id})");
                }
            }
            return(new Tuple <bool, byte>(success, (byte)ModelType.Model));
        }