public void UserUpdate(User user, FoodNote food)
        {
            XDocument doc  = XDocument.Load($@"{dirPath}\Users\{user.Name}.xml");
            XElement  root = doc.Element("User").Element("EatenFood");

            if (!Checker.IsToday((XElement)root.LastNode))
            {
                root.Add(new XElement("Day",
                                      new XAttribute("Date", food.Date.ToShortDateString()),
                                      new XElement("Food",
                                                   new XAttribute("Name", food.EatenFood.Name),
                                                   new XElement("Mass", food.Mass))));

                ((XElement)root.LastNode).AddFirst(new XElement("Summary",
                                                                new XElement("Calories", food.EatenFood.Calories * (food.Mass / 100)),
                                                                new XElement("Proteins", food.EatenFood.Proteins * (food.Mass / 100)),
                                                                new XElement("Fats", food.EatenFood.Fats * (food.Mass / 100)),
                                                                new XElement("Carbohidrates", food.EatenFood.Carbohidrates * (food.Mass / 100))
                                                                ));
            }
            else
            {
                root = (XElement)root.LastNode;
                root.Add(new XElement("Food",
                                      new XAttribute("Name", food.EatenFood.Name),
                                      new XElement("Mass", food.Mass)
                                      ));

                ChangeSummary(food, root.Element("Summary"));
            }

            doc.Save($@"{dirPath}\Users\{user.Name}.xml");
        }
        public void AddFoodNote(string foodName, decimal foodMass)
        {
            FoodNote food = new FoodNote
            {
                EatenFood = _db.GetFoodByName(foodName),
                Date      = DateTime.Today,
                Mass      = foodMass
            };

            _updater.UserUpdate(currentUser, food);
        }
 private void ChangeSummary(FoodNote food, XElement root)
 {
     root.Element("Calories").Value =
         (ParseFromXml(root.Element("Calories").Value) + (food.EatenFood.Calories)
          * (food.Mass / 100)).ToString();
     root.Element("Proteins").Value =
         (ParseFromXml(root.Element("Proteins").Value) + (food.EatenFood.Proteins)
          * (food.Mass / 100)).ToString();
     root.Element("Fats").Value =
         (ParseFromXml(root.Element("Fats").Value) + (food.EatenFood.Fats)
          * (food.Mass / 100)).ToString();
     root.Element("Carbohidrates").Value =
         (ParseFromXml(root.Element("Carbohidrates").Value) + (food.EatenFood.Carbohidrates)
          * (food.Mass / 100)).ToString();
 }