Esempio n. 1
0
        public static Employee XmlEmployeeToEmployee(IModelEmployee xemployee, Employee employee)
        {
            Employee emp = XMLActions.ToEmployee(xemployee);

            if (emp.Experience == -1)
            {
                emp.Experience = employee.Experience;
            }
            if (emp.Name == null)
            {
                emp.Name = employee.Name;
            }
            if (emp.Position == null)
            {
                emp.Position = employee.Position;
            }
            if (emp.Specialization == null)
            {
                emp.Specialization = employee.Specialization;
            }
            if (emp.Salary == -1)
            {
                emp.Salary = employee.Salary;
            }

            return(emp);
        }
Esempio n. 2
0
        public static void CorrectXMLIDs()
        {
            XDocument xdoc  = ReadXML();
            var       items = (from xe in xdoc.Descendants("Employee")
                               select new XMLEmployee
            {
                Name = xe.Element("Name").Value,
                Experience = xe.Element("Experience").Value,
                Position = xe.Element("Position").Value,
                Salary = xe.Element("Salary").Value,
                Specialization = xe.Element("Specialization").Value,
                ID = (string)xe.Element("ID")
            }).ToList();
            int largestID = 0;

            try
            {
                largestID = items.Where(x => x.ID != null).Select(x => int.Parse(x.ID)).OrderBy(x => x).Last();
            }
            catch
            {
                largestID = 1;
            }

            //int counter = 1;
            var xitems = from item in xdoc.Descendants("Employee")
                         select item;

            foreach (XElement item in xitems)
            {
                if ((string)item.Element("ID") == null)
                {
                    item.SetElementValue("ID", largestID.ToString());
                }
                largestID++;
            }
            XMLActions.UpdateXML(xdoc);
        }