Esempio n. 1
0
 // удаление записи из таблицы истории
 public void RemoveEatingHistoryItem(EatingHistoryItem item)
 {
     using (_context = new Context())
     {
         var request = from eh in _context.EatingHistory
                       where eh.ID == item.ID
                       select eh;
         _context.EatingHistory.Remove(request.Single());
         _context.SaveChanges();
     }
 }
Esempio n. 2
0
        // добавление записи в таблицу истории
        public void AddEatingHistoryItem(Dish dish, float quantity)
        {
            EatingHistoryItem eatingHistoryItem = new EatingHistoryItem
            {
                Date          = DateTime.Now.Date,
                Dish          = dish,
                Quantity      = quantity,
                Calories      = dish.Calories / 100 * quantity,
                Fats          = dish.Fats / 100 * quantity,
                Proteins      = dish.Proteins / 100 * quantity,
                Carbohydrates = dish.Carbohydrates / 100 * quantity
            };

            using (_context = new Context())
            {
                _context.Dishes.Attach(dish);
                _context.EatingHistory.Add(eatingHistoryItem);
                _context.SaveChanges();
            }
        }