Exemplo n.º 1
0
        private static Department HandleDepartment(XElement xml)
        {
            var d = new Department();
            var name = xml.Elements("Name").First().Value;
            d.Name = name;
            d.Manager = HandleEmployee(xml.Elements("Manager").FirstOrDefault());

            var xmlEmployees = xml.Elements("Employees");
            if (xmlEmployees.Elements().Count() > 0)
            {
                foreach (var xmlEmployee in xmlEmployees.Elements("Employee"))
                {
                    d.Employees.Add(HandleEmployee(xmlEmployee));
                }
            }

            var xmlSubUnits = xml.Elements("SubDepartments");
            if (xmlSubUnits.Elements().Count() > 0)
            {
                foreach (var xmlSubUnit in xmlSubUnits.Elements("Department"))
                {
                    d.SubDepartments.Add(HandleDepartment(xmlSubUnit));
                }
            }

            return d;
        }
Exemplo n.º 2
0
        private List<DepartmentDto> FillSubDepartments(Department d)
        {
            var res = new List<DepartmentDto>();

            foreach (var subDepartment in d.SubDepartments)
            {
                var subDept = new DepartmentDto
                                  {
                                      Details =
                                          {
                                              Id = subDepartment.Id,
                                              Name = subDepartment.Name,
                                              Manager = new EmployeeDto
                                                            {
                                                                Address = subDepartment.Manager.Person.Address,
                                                                Id = subDepartment.Manager.Id,
                                                                Name = subDepartment.Manager.Person.Name,
                                                                Salary = subDepartment.Manager.Salary
                                                            }
                                          }
                                  };

                subDept.Employees = subDepartment.Employees.Select(e =>
                        new EmployeeDto
                            {
                                Id = e.Id,
                                Address = e.Person.Address,
                                Name = e.Person.Name,
                                Salary = e.Salary
                            }).ToList();

                subDept.SubDepartments = FillSubDepartments(subDepartment);
                res.Add(subDept);
            }

            return res;
        }