-
-
Save MikeWills/528dac8511b9295cdb16 to your computer and use it in GitHub Desktop.
We use WebAPI to pull the data into our application. The speed issue in here as calling the directly from Poster in Firefox takes 3 minutes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Gets the data from the IBM i. | |
/// </summary> | |
/// <param name="connString">The connection string</param> | |
/// <param name="sqlStatement">The SQL statement</param> | |
/// <param name="parameters">The parameters (iDB2Parameter)</param> | |
/// <returns>DataTable</returns> | |
public DataTable GetData(string sqlStatement, Action<iDB2ParameterCollection> parameters) | |
{ | |
DataTable dt = new DataTable(); | |
using (iDB2Command cmd = new iDB2Command(sqlStatement, conn)) | |
{ | |
if (parameters != null) { parameters(cmd.Parameters); } | |
try | |
{ | |
using (iDB2DataAdapter da = new iDB2DataAdapter(cmd)) { da.Fill(dt); } | |
} | |
catch (iDB2SQLErrorException e) | |
{ | |
if (!EventLog.SourceExists(_LOG_SOURCE)) | |
EventLog.CreateEventSource(_LOG_SOURCE, _LOG_APPLICATION); | |
EventLog.WriteEntry(_LOG_SOURCE, "**ERROR** on da.Fill(dt): " + e.Message, EventLogEntryType.Error); | |
throw e; | |
} | |
catch (Exception e) | |
{ | |
if (!EventLog.SourceExists(_LOG_SOURCE)) | |
EventLog.CreateEventSource(_LOG_SOURCE, _LOG_APPLICATION); | |
EventLog.WriteEntry(_LOG_SOURCE, "**ERROR** on da.Fill(dt): " + e.Message, EventLogEntryType.Error); | |
throw e; | |
} | |
} | |
return dt; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GET api/<controller>/5 | |
public IEnumerable<LeaveRequest> Get(string supervisorId) | |
{ | |
return lrRepository.GetLeaveRequestHistory(supervisorId); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Gets the leave requests by supervisor. This list will only bring requests in the past. | |
/// </summary> | |
/// <param name="supervisorId">The supervisor id.</param> | |
/// <returns></returns> | |
public IEnumerable<LeaveRequest> GetLeaveRequestHistory(string supervisorId) | |
{ | |
/* | |
SELECT REQUEST_ID, EMPLOYEE_ID, EMPLOYEE_NAME, FIRST_DATE, TOTAL_HOURS, EMPLOYEE_SIGNATURE, EMPLOYEE_SIGNED_DATE, | |
EMPLOYEE_SIGNED_TIME, WORKSTATION, EMPLOYEE_COMMENT, SIGNED_BY, SUPERVISOR_ID, SUPERVISOR_SIGNED_DATE, SUPERVISOR_SIGNED_TIME, | |
SUPERVISOR_WORKSTATION, SUPERVISOR_COMMENT, HR_SIGNED_DATE, HR_SIGNED_TIME, HR_WORKSTATION, HR_COMMENT, NEED_HR_APPROVAL | |
FROM MPRLRREQP, MPRTCSP | |
WHERE MPRLRREQP.EMPLOYEE_ID = MPRTCSP.EM_UNIQUE_KEY AND UPPER(EM_SUPV_USERID) = UPPER(@id) AND SUPERVISOR_SIGNED_DATE <> '0001-01-01' | |
ORDER BY FIRST_DATE | |
*/ | |
StringBuilder sb = new StringBuilder(); | |
sb.Append("SELECT REQUEST_ID, EMPLOYEE_ID, EMPLOYEE_NAME, FIRST_DATE, TOTAL_HOURS, EMPLOYEE_SIGNATURE, EMPLOYEE_SIGNED_DATE, "); | |
sb.Append("EMPLOYEE_SIGNED_TIME, WORKSTATION, EMPLOYEE_COMMENT, SIGNED_BY, SUPERVISOR_ID, SUPERVISOR_SIGNED_DATE, SUPERVISOR_SIGNED_TIME, "); | |
sb.Append("SUPERVISOR_WORKSTATION, SUPERVISOR_COMMENT, HR_SIGNED_DATE, HR_SIGNED_TIME, HR_WORKSTATION, HR_COMMENT, NEED_HR_APPROVAL "); | |
sb.Append("FROM MPRLRREQP, MPRTCSP "); | |
sb.Append("WHERE MPRLRREQP.EMPLOYEE_ID = MPRTCSP.EM_UNIQUE_KEY AND UPPER(EM_SUPV_USERID) = UPPER(@id) AND SUPERVISOR_SIGNED_DATE <> '0001-01-01' "); | |
sb.Append("ORDER BY FIRST_DATE DESC"); | |
//iSql.OpenConn(); | |
var leaveRequests = from i in iSql.GetData(sb.ToString(), p => p.Add("@id", iDB2DbType.iDB2Decimal).Value = supervisorId).AsEnumerable() | |
select new LeaveRequest() | |
{ | |
RequestId = Convert.ToInt32(i.Field<decimal>("REQUEST_ID")), | |
EmployeeId = Convert.ToInt32(i.Field<decimal>("EMPLOYEE_ID")), | |
EmployeeName = i.Field<string>("EMPLOYEE_NAME"), | |
FirstDateOfRequest = i.Field<DateTime>("FIRST_DATE"), | |
EmployeeSignature = i.Field<string>("EMPLOYEE_SIGNATURE"), | |
EmployeeSignedDateTime = | |
Convert.ToDateTime(String.Format("{0} {1}", | |
i.Field<DateTime>("EMPLOYEE_SIGNED_DATE").ToShortDateString(), | |
i.Field<DateTime>("EMPLOYEE_SIGNED_TIME").ToShortTimeString())), | |
Workstation = i.Field<string>("WORKSTATION"), | |
EmployeeComment = i.Field<string>("EMPLOYEE_COMMENT"), | |
SupervisorId = i.Field<string>("SUPERVISOR_ID"), | |
SupervisorSignedDateTime = | |
Convert.ToDateTime(String.Format("{0} {1}", | |
i.Field<DateTime>("SUPERVISOR_SIGNED_DATE").ToShortDateString(), | |
i.Field<DateTime>("SUPERVISOR_SIGNED_TIME").ToShortTimeString())), | |
SupervisorComment = i.Field<string>("SUPERVISOR_COMMENT"), | |
SignedByUser = i.Field<string>("SIGNED_BY"), | |
TotalHours = i.Field<decimal>("TOTAL_HOURS"), | |
SupervisorWorkstation = i.Field<string>("SUPERVISOR_WORKSTATION"), | |
HrSignedDateTime = | |
Convert.ToDateTime(String.Format("{0} {1}", | |
i.Field<DateTime>("HR_SIGNED_DATE").ToShortDateString(), | |
i.Field<DateTime>("HR_SIGNED_TIME").ToShortTimeString())), | |
HrWorkstation = i.Field<string>("HR_WORKSTATION"), | |
HrComment = i.Field<string>("HR_COMMENT"), | |
IsHrApprovalRequired = Convert.ToBoolean(i.Field<decimal>("NEED_HR_APPROVAL")), | |
LeaveType = GetLeaveType(i.Field<decimal>("REQUEST_ID")) | |
}; | |
iSql.CloseConn(); | |
return leaveRequests; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment