protected async void downloadEmployees_Click(object sender, EventArgs e) { List <TWP_Employee_Schema> eeSchema = await TWPSDK.listEESchema(siteId, returnAuthToken); IList <string> schemaState = eeSchema[0].States[0].Variables.Keys.ToList(); List <TWP_Employee> employees = await TWPSDK.ListEmployees(siteId, returnAuthToken); StringBuilder sb = new StringBuilder(); int idCount = 3; int statesCount = 0; string header = "RecordNumber,First Name,Middle Name,Last Name,Code,Designation,Phone,Email,Start Date,Separation Date," + "Export Block,WebClock Enabled,login1,login2,login3,"; foreach (TWP_Employee_Schema results in eeSchema) { foreach (TWP_State_Schema state in results.States) { foreach (KeyValuePair <string, string> kvp in state.Variables) { ++statesCount; header += $"{kvp.Key.ToString()},"; } } } sb.AppendLine(header); string body = ""; foreach (TWP_Employee emp in employees) { body = $"{emp.RecordNumber},{emp.FirstName},{emp.MiddleName},{emp.LastName},{emp.EmployeeCode},{emp.Designation},{emp.Phone},{emp.Email},{emp.StartDate},{emp.EndDate},{emp.ExportBlock},{emp.WebClockEnabled},"; try { foreach (TWP_Identifier id in emp.Identifiers) { if (!string.IsNullOrEmpty(id.Id)) { body += $"{id.Id},"; } } if (emp.Identifiers.Count < idCount) { body += string.Concat(Enumerable.Repeat(",", idCount - emp.Identifiers.Count)); } } catch { body += $",,,"; } try { foreach (TWP_State state in emp.States) { foreach (string varName in schemaState) { foreach (KeyValuePair <string, string> kvp in state.Variables) { if (kvp.Key == varName) { body += $"{kvp.Value}"; } } body += ","; } } } catch { body += string.Concat(Enumerable.Repeat(",", statesCount)); } sb.AppendLine(body); } downloadFile("EmployeeDetail", sb); }
protected async void getEmployeesSchema_Click(object sender, EventArgs e) { List <TWP_Employee> eeSchema = await TWPSDK.ListEmployees(siteId, returnAuthToken); }