Пример #1
0
        public void Add(int id, string nome, string email, string senha, long cpf)
        {
            UsuData user = new UsuData();

            user.Id    = id;
            user.Nome  = nome;
            user.Email = email;
            user.Senha = senha;
            user.Cpf   = cpf;

            XElement usu =
                new XElement("usuario",
                             new XElement("id", user.Id),
                             new XElement("nome", user.Nome),
                             new XElement("email", user.Email),
                             new XElement("senha", user.Senha),
                             new XElement("cpf", user.Cpf),
                             new XElement("ativo", "true"));

            XDocument doc = XDocument.Load(caminho);

            doc.Root.Add(usu);
            doc.Save(caminho);

            //usado para adicionar um usuario ao xml

            /*
             * xmlli.Add(11, "jhonn", "jhon@gmail", "19374", 32859734);
             */
        }
Пример #2
0
        public void Adicionar()
        {
            lod.Listar();

            Console.WriteLine("ID: ");
            UZ.Id = int.Parse(Console.ReadLine());
            Console.WriteLine("Nome: ");
            UZ.Nome = (Console.ReadLine());
            Console.WriteLine("Email: ");
            UZ.Email = (Console.ReadLine());
            Console.WriteLine("Senha: ");
            UZ.Senha = (Console.ReadLine());
            Console.WriteLine("CPF: ");
            UZ.Cpf = long.Parse(Console.ReadLine());


            UsuData usud = new UsuData();



            XDocument docadd = XDocument.Load(caminho);
            XElement  usu    = new XElement("usuario",
                                            new XAttribute("id", UZ.Id),
                                            new XElement("nome", UZ.Nome),
                                            new XElement("email", UZ.Email),
                                            new XElement("senha", UZ.Senha),
                                            new XElement("cpf", UZ.Cpf));

            docadd.Root.Add(usu);
            docadd.Save(caminho);
            Console.ReadLine();
        }