예제 #1
0
        public string CodeLookup(string employeeid)
        {
            Employee employee = new Employee();
            XElement xEmployee = employee.GPQue(employeeid);

            //here is where its breaking
            employee = employee.MakeOneModel(xEmployee);
            string employeeDept = employee.Department;
            Dictionary<string, string> deptDictionary = employee.DeptCode("7700", "6700");
            string deptCode = deptDictionary[employeeDept];

            return deptCode;
        }
        public Employee MakeOneModel(XElement blob)
        {
            try
            {
                XElement blob2 = blob.Element("eConnect").Element("Employee");
                Employee e = new Employee();
                Func<string, string> middleinitialize = s =>
                {
                    if (blob2.Element("MIDLNAME").Value == "")
                    {
                        s = "";
                        return s;
                    }
                    else
                    {
                        s = blob2.Element("MIDLNAME").Value.Substring(0, 1) + ".";
                        return s;
                    }
                };

                e.Department = blob2.Element("DEPRTMNT").Value;
                e.EmployeeID = blob2.Element("EMPLOYID").Value;
                e.FirstName = blob2.Element("FRSTNAME").Value;
                e.LastName = blob2.Element("LASTNAME").Value;

                e.MiddleInitial = middleinitialize(blob2.Element("MIDLNAME").Value);
                e.LastFirstMIName = blob2.Element("LASTNAME").Value + ", " +
                              blob2.Element("FRSTNAME").Value + " " +
                                middleinitialize(blob2.Element("MIDLNAME").Value);
                e.TaosCell = blob2.Element("Address").Element("PHONE3").Value;

                e.SalesForceID = blob2.Element("USERDEF2").Value;
                return e;
            }
            catch
            {
                Employee e = new Employee();
                e.Department = "ACCT";
                return e;
            }
        }
        public IEnumerable<Employee> MakeModel(XElement blob)
        {
            foreach (XElement employee in blob.Elements("eConnect").Elements("Employee"))
            {
                Employee xEmployee = new Employee();
                Func<string, string> middleinitialize = s =>
                {
                    if (employee.Element("MIDLNAME").Value == "")
                    {
                        s = "";
                        return s;
                    }
                    else
                    {
                        s = employee.Element("MIDLNAME").Value.Substring(0, 1) + ".";
                        return s;
                    }
                };

                xEmployee.Department = employee.Element("DEPRTMNT").Value;
                xEmployee.EmployeeID = employee.Element("EMPLOYID").Value;
                xEmployee.FirstName = employee.Element("FRSTNAME").Value;
                xEmployee.LastName = employee.Element("LASTNAME").Value;

                xEmployee.MiddleInitial = middleinitialize(employee.Element("MIDLNAME").Value);
                xEmployee.LastFirstMIName = employee.Element("LASTNAME").Value + ", " +
                               employee.Element("FRSTNAME").Value + " " +
                                middleinitialize(employee.Element("MIDLNAME").Value);
                xEmployee.TaosCell = employee.Element("Address").Element("PHONE3").Value;

                xEmployee.SalesForceID = employee.Element("USERDEF2").Value;
                yield return xEmployee;

            }
        }