Ejemplo n.º 1
0
 public bool EditById(uint id, string newValue, byte[] photo)
 {
     try
     {
         var     root  = XMLProvider.XmlConnect(path);
         XmlNode xRoot = root.DocumentElement;
         XmlNode node  = xRoot.SelectSingleNode(string.Format("award[@id = '{0}']", id));
         node.SelectSingleNode("name").InnerText = newValue;
         if (!XMLProvider.XmlSave(root, path))
         {
             return(false);
         }
         _edited = true;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
 public bool DeleteById(uint id)
 {
     try
     {
         var     root  = XMLProvider.XmlConnect(path);
         XmlNode xRoot = root.DocumentElement;
         XmlNode node  = xRoot.SelectSingleNode(string.Format("user[@id = '{0}']", id));
         XmlNode outer = node.ParentNode;
         outer.RemoveChild(node);
         if (!XMLProvider.XmlSave(root, path))
         {
             return(false);
         }
         _edited = true;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
        public bool Add(User user)
        {
            if (_edited)
            {
                GetAll();
            }
            try
            {
                var lastId = _users.Keys.Count > 0
                ? _users.Keys.Max()
                : 0;
                user.Id = lastId + 1;
                _users.Add(user.Id, user);
                var          root            = XMLProvider.XmlConnect(path);
                XmlNode      xRoot           = root.DocumentElement;
                XmlNode      newRecord       = root.CreateElement("user");
                XmlAttribute recordAttribute = root.CreateAttribute("id");
                XmlNode      recordName      = root.CreateElement("name");
                XmlNode      recordBirthday  = root.CreateElement("birthday");
                XmlText      newName         = root.CreateTextNode(user.Name);
                XmlText      newBirthday     = root.CreateTextNode(user.DateOfBirth.ToShortDateString());
                XmlText      newId           = root.CreateTextNode(user.Id.ToString());


                recordName.AppendChild(newName);
                recordAttribute.AppendChild(newId);
                recordBirthday.AppendChild(newBirthday);
                newRecord.AppendChild(recordName);
                newRecord.AppendChild(recordBirthday);
                newRecord.Attributes.Append(recordAttribute);
                xRoot.AppendChild(newRecord);
                XMLProvider.XmlSave(root, path);
                _edited = false;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
 public bool GrantUserAwards(uint idUser, uint idAward)
 {
     try
     {
         var     root        = XMLProvider.XmlConnect(path);
         XmlNode xRoot       = root.DocumentElement;
         XmlNode node        = xRoot.SelectSingleNode(string.Format("user[@id = '{0}']", idUser));
         XmlNode outer       = node.ParentNode;
         XmlNode recordAward = root.CreateElement("award");
         XmlText newAward    = root.CreateTextNode(idAward.ToString());
         recordAward.AppendChild(newAward);
         node.AppendChild(recordAward);
         if (!XMLProvider.XmlSave(root, path))
         {
             return(false);
         }
         _edited = true;
         return(true);
     }
     catch
     {
         return(false);
     }
 }