// Returns the first page of root level assignments for the employee specified public static string GetAssignments(CDovicoID idEmployee, ref APIRequestResult aRequestResult) { // Build up the URI for a request of assignments for the specified employee and then call our overloaded function to do the rest of // the work. aRequestResult.SetRequestURI(("Assignments/Employee/" + idEmployee.ToString() + "/"), ""); return GetAssignments("", ref aRequestResult); }
// Returns the first page of root level assignments for the employee specified public static string GetAssignments(CDovicoID idEmployee, ref APIRequestResult aRequestResult) { // Build up the URI for a request of assignments for the specified employee and then call our overloaded function to do the rest of // the work. aRequestResult.SetRequestURI(("Assignments/Employee/" + idEmployee.ToString() + "/"), "ForTimeEntry=T"); return(GetAssignments("", ref aRequestResult)); }
// Method used to insert a time entry via the API. // // NOTE: StartTime, StopTime, and Description are optional and can be left out by passing in 'null' // // If successful, returns the inserted time entry data from the API. // If there is an error, the return value will be null. public static CTimeEntry DoInsert(CDovicoID idProject, CDovicoID idTask, CDovicoID idEmployee, DateTime dtDate, string sStartTimeHHMM, string sStopTimeHHMM, double dTotalHours, string sDescription, ref APIRequestResult aRequestResult) { // Start off the XML needed for the POST call to the API CStringBuilderXML sbXML = new CStringBuilderXML(false); sbXML.AppendStartTag("TimeEntries"); sbXML.AppendStartTag("TimeEntry"); sbXML.AppendTagsWithValue("ProjectID", idProject); sbXML.AppendTagsWithValue("TaskID", idTask); sbXML.AppendTagsWithValue("EmployeeID", idEmployee); sbXML.AppendTagsWithValue("Date", dtDate); // If the StartTime has been provided then...(it's optional) if (sStartTimeHHMM != null) { sbXML.AppendTagsWithValue("StartTime", sStartTimeHHMM); } // If the StopTime has been provided then...(it's optional) if (sStopTimeHHMM != null) { sbXML.AppendTagsWithValue("StopTime", sStopTimeHHMM); } sbXML.AppendTagsWithValue("TotalHours", dTotalHours); // If the Description has been provided then...(it's optional) if (sDescription != null) { sbXML.AppendTagsWithValue("Description", sDescription); } // Close off the XML needed for the POST call sbXML.AppendEndTag("TimeEntry"); sbXML.AppendEndTag("TimeEntries"); // Configure our request object with the necessary data for the POST aRequestResult.SetRequestURI("TimeEntries/", ""); aRequestResult.RequestHttpMethod = "POST"; aRequestResult.RequestPostPutData = sbXML; // Execute the request and get the list of time entries back. If we have a list then return the first item in the list (there should // only be the one item) List <CTimeEntry> lstTimeEntries = ProcessRequest(ref aRequestResult); if (lstTimeEntries != null) { return(lstTimeEntries[0]); } // An error happened so just return null. return(null); }
// Handles the work of making a request and pulling Employee(s) from the result of a request (if there was an error the return value will // be null) protected static List <CEmployee> ProcessRequest(APIRequestResult aRequestResult) { // Make sure the Prev/Next Page URI, if there was an error, etc are reset in the event the user is re-using an object that has already // been used for a different call (don't want a previous call's results giving the caller false information) aRequestResult.ResetResultData(); // Pass the request on to the REST API. If there was an error then exit now CRestApiHelper.MakeAPIRequest(aRequestResult); if (aRequestResult.HadRequestError) { return(null); } // Load in the XML returned from the API call XmlDocument xdDoc = new XmlDocument(); xdDoc.LoadXml(aRequestResult.RequestResult); // Will hold the list of employees that will be returned to the calling function List <CEmployee> lstEmployees = new List <CEmployee>(); // Grab the root element and get the Previous/Next Page URIs from it (when requesting a specific employee there will be no paging // information returned since a single record is all that is ever returned. If that's the case we want our Previous/Next Page URIs to // hold 'N/A' rather than "" which is why we pass in the URI_NOT_AVAILABLE constant) XmlElement xeDocElement = xdDoc.DocumentElement; aRequestResult.ResultPrevPageURI = CXMLHelper.GetChildNodeValue(xeDocElement, Constants.PREV_PAGE_URI, Constants.URI_NOT_AVAILABLE); aRequestResult.ResultNextPageURI = CXMLHelper.GetChildNodeValue(xeDocElement, Constants.NEXT_PAGE_URI, Constants.URI_NOT_AVAILABLE); XmlElement xeEmployee = null; // Grab the list of Employee nodes and loop through the elements... XmlNodeList xnlEmployees = xeDocElement.GetElementsByTagName("Employee"); int iCount = xnlEmployees.Count; for (int iIndex = 0; iIndex < iCount; iIndex++) { // Grab the current element xeEmployee = (XmlElement)xnlEmployees[iIndex]; // Add the current item to our list lstEmployees.Add(new CEmployee( CDovicoID.Parse(CXMLHelper.GetChildNodeValue(xeEmployee, "ID")), CXMLHelper.GetChildNodeValue(xeEmployee, "LastName"), CXMLHelper.GetChildNodeValue(xeEmployee, "FirstName") // NOTE: If this is an Employee/Me/ request, the rest of the fields may not be available )); } // End of the for(int iIndex = 0; iIndex < iCount; iIndex++) loop. // Return the list of Employees to the caller return(lstEmployees); }
//===================================================================== // STATIC METHODS: For use when interacting with the DOVICO Hosted API //--------------------------------------------------------------------- // A request for a specific employee by ID (If there was an error the return value will be null) public static CEmployee GetInfo(CDovicoID idEmployee, APIRequestResult aRequestResult) { // Set the URI for the Employee/{ID}/ request. Process the request and if the returned list is not null (no errors) then return the // first item in the list (there should only ever be the one item) aRequestResult.SetRequestURI(("Employees/" + idEmployee.ToString() + "/"), ""); List<CEmployee> lstEmployees = ProcessRequest(aRequestResult); if (lstEmployees != null) { return lstEmployees[0]; } // An error happened so just return null. return null; }
//===================================================================== // STATIC METHODS: For use when interacting with the DOVICO Hosted API //--------------------------------------------------------------------- //get list options are: // - all time (no filters) // - all time (filtered by date range) // - all time by employee //------------------------------------------------- // ALL TIME by EMPLOYEE (filtered by date range) //------------------------------------------------- public static List <CTimeEntry> GetListForEmployee(CDovicoID idEmployeeID, DateTime dtDateRangeStart, DateTime dtDateRangeEnd, ref APIRequestResult aRequestResult) { // If the Request URI has not been set then set it to return the first page of time entries (if it's already set we may have been called to get a next/previous // page) if (aRequestResult.GetRequestURI() == "") { aRequestResult.SetRequestURI(("TimeEntries/Employee/" + idEmployeeID + "/"), BuildDateRangeQueryString(dtDateRangeStart, dtDateRangeEnd)); } return(ProcessRequest(ref aRequestResult)); }
//===================================================================== // STATIC METHODS: For use when interacting with the DOVICO Hosted API //--------------------------------------------------------------------- // A request for a specific employee by ID (If there was an error the return value will be null) public static CEmployee GetInfo(CDovicoID idEmployee, APIRequestResult aRequestResult) { // Set the URI for the Employee/{ID}/ request. Process the request and if the returned list is not null (no errors) then return the // first item in the list (there should only ever be the one item) aRequestResult.SetRequestURI(("Employees/" + idEmployee.ToString() + "/"), ""); List <CEmployee> lstEmployees = ProcessRequest(aRequestResult); if (lstEmployees != null) { return(lstEmployees[0]); } // An error happened so just return null. return(null); }
// Overloaded constructor // NOTE: Specify Start/Stop time in HHMM format public CTimeEntry(string sTimeEntryID, CDovicoID idClient, string sClientName, CDovicoID idProject, string sProjectName, CDovicoID idTask, string sTaskName, DateTime dtDate, string sStartTime, string sStopTime, double dTotalHours, string sDescription) { TimeEntryID = sTimeEntryID; ClientID = idClient; ClientName = sClientName; ProjectID = idProject; ProjectName = sProjectName; TaskID = idTask; TaskName = sTaskName; m_dtDate = dtDate; StartTime = sStartTime; StopTime = sStopTime; TotalHours = dTotalHours; Description = sDescription; }
// Overloaded constructor public CEmployee(CDovicoID idEmployee, string sLastName, string sFirstName) { ID = idEmployee; LastName = sLastName; FirstName = sFirstName; }
//===================================================================== // STATIC METHODS: For use when interacting with the DOVICO Hosted API //--------------------------------------------------------------------- //get list options are: // - all time (no filters) // - all time (filtered by date range) // - all time by employee //------------------------------------------------- // ALL TIME by EMPLOYEE (filtered by date range) //------------------------------------------------- public static List<CTimeEntry> GetListForEmployee(CDovicoID idEmployeeID, DateTime dtDateRangeStart, DateTime dtDateRangeEnd, ref APIRequestResult aRequestResult) { // If the Request URI has not been set then set it to return the first page of time entries (if it's already set we may have been called to get a next/previous // page) if (aRequestResult.GetRequestURI() == "") { aRequestResult.SetRequestURI(("TimeEntries/Employee/" + idEmployeeID + "/"), BuildDateRangeQueryString(dtDateRangeStart, dtDateRangeEnd)); } return ProcessRequest(ref aRequestResult); }
// Method used to insert a time entry via the API. // // NOTE: StartTime, StopTime, and Description are optional and can be left out by passing in 'null' // // If successful, returns the inserted time entry data from the API. // If there is an error, the return value will be null. public static CTimeEntry DoInsert(CDovicoID idProject, CDovicoID idTask, CDovicoID idEmployee, DateTime dtDate, string sStartTimeHHMM, string sStopTimeHHMM, double dTotalHours, string sDescription, ref APIRequestResult aRequestResult) { // Start off the XML needed for the POST call to the API CStringBuilderXML sbXML = new CStringBuilderXML(false); sbXML.AppendStartTag("TimeEntries"); sbXML.AppendStartTag("TimeEntry"); sbXML.AppendTagsWithValue("ProjectID", idProject); sbXML.AppendTagsWithValue("TaskID", idTask); sbXML.AppendTagsWithValue("EmployeeID", idEmployee); sbXML.AppendTagsWithValue("Date", dtDate); // If the StartTime has been provided then...(it's optional) if (sStartTimeHHMM != null) { sbXML.AppendTagsWithValue("StartTime", sStartTimeHHMM); } // If the StopTime has been provided then...(it's optional) if (sStopTimeHHMM != null) { sbXML.AppendTagsWithValue("StopTime", sStopTimeHHMM); } sbXML.AppendTagsWithValue("TotalHours", dTotalHours); // If the Description has been provided then...(it's optional) if (sDescription != null) { sbXML.AppendTagsWithValue("Description", sDescription); } // Close off the XML needed for the POST call sbXML.AppendEndTag("TimeEntry"); sbXML.AppendEndTag("TimeEntries"); // Configure our request object with the necessary data for the POST aRequestResult.SetRequestURI("TimeEntries/", ""); aRequestResult.RequestHttpMethod = "POST"; aRequestResult.RequestPostPutData = sbXML; // Execute the request and get the list of time entries back. If we have a list then return the first item in the list (there should // only be the one item) List<CTimeEntry> lstTimeEntries = ProcessRequest(ref aRequestResult); if (lstTimeEntries != null) { return lstTimeEntries[0]; } // An error happened so just return null. return null; }
public CStringBuilderSQL(string sSQL, CDovicoID idValue) { base.Append(sSQL, idValue); }
// Helper that fires off the request to the REST API and processes the results protected static List <CTimeEntry> ProcessRequest(ref APIRequestResult aRequestResult) { // Make sure the Prev/Next Page URI, if there was an error, etc are reset in the event the user is re-using an object that has already // been used for a different call (don't want a previous call's results giving the caller false information) aRequestResult.ResetResultData(); // Pass the request on to the REST API. If there was an error then exit now CRestApiHelper.MakeAPIRequest(aRequestResult); if (aRequestResult.HadRequestError) { return(null); } // Load in the XML returned from the API call XmlDocument xdDoc = new XmlDocument(); xdDoc.LoadXml(aRequestResult.RequestResult); // Will hold the list of Time Entries that will be returned to the calling function List <CTimeEntry> lstTimeEntries = new List <CTimeEntry>(); // Grab the root element and get the Previous/Next Page URIs from it (when requesting a specific time entry there will be no paging // information returned since a single record is all that is ever returned. If that's the case we want our Previous/Next Page URIs to // hold 'N/A' rather than "" which is why we pass in the URI_NOT_AVAILABLE constant) XmlElement xeDocElement = xdDoc.DocumentElement; aRequestResult.ResultPrevPageURI = CXMLHelper.GetChildNodeValue(xeDocElement, Constants.PREV_PAGE_URI, Constants.URI_NOT_AVAILABLE); aRequestResult.ResultNextPageURI = CXMLHelper.GetChildNodeValue(xeDocElement, Constants.NEXT_PAGE_URI, Constants.URI_NOT_AVAILABLE); XmlElement xeTimeEntry = null, xeClient = null, xeProject = null, xeTask = null; DateTime dtDate = DateTime.Now; // Grab the list of Time Entry nodes and loop through the elements... XmlNodeList xnlTimeEntries = xeDocElement.GetElementsByTagName("TimeEntry"); int iCount = xnlTimeEntries.Count; for (int iIndex = 0; iIndex < iCount; iIndex++) { // Grab the current element and the required sub-elements xeTimeEntry = (XmlElement)xnlTimeEntries[iIndex]; xeClient = (XmlElement)xeTimeEntry.GetElementsByTagName("Client")[0]; xeProject = (XmlElement)xeTimeEntry.GetElementsByTagName("Project")[0]; xeTask = (XmlElement)xeTimeEntry.GetElementsByTagName("Task")[0]; // Parse the date CDateHelper.GetDateFromAPIDateString(CXMLHelper.GetChildNodeValue(xeTimeEntry, "Date"), out dtDate); // Add the current item to our list lstTimeEntries.Add(new CTimeEntry( CXMLHelper.GetChildNodeValue(xeTimeEntry, "ID"), CDovicoID.Parse(CXMLHelper.GetChildNodeValue(xeClient, "ID")), CXMLHelper.GetChildNodeValue(xeClient, "Name"), CDovicoID.Parse(CXMLHelper.GetChildNodeValue(xeProject, "ID")), CXMLHelper.GetChildNodeValue(xeProject, "Name"), CDovicoID.Parse(CXMLHelper.GetChildNodeValue(xeTask, "ID")), CXMLHelper.GetChildNodeValue(xeTask, "Name"), dtDate, CXMLHelper.GetChildNodeValue(xeTimeEntry, "StartTime"), CXMLHelper.GetChildNodeValue(xeTimeEntry, "StopTime"), double.Parse(CXMLHelper.GetChildNodeValue(xeTimeEntry, "TotalHours"), Constants.CULTURE_US_ENGLISH), CXMLHelper.GetChildNodeValue(xeTimeEntry, "Description") )); } // End of the for(int iIndex = 0; iIndex < iCount; iIndex++) loop. // Return the list of Employees to the caller return(lstTimeEntries); }
// A CDovicoID public void Append(string sString, CDovicoID idValue) { Append(sString); Append(idValue.ToString()); }
// Overload to handle values of TRACKIT_ID public void AppendTagsWithValue(string sTagName, CDovicoID idValue) { AppendStartTag(sTagName); Append("", idValue); AppendEndTag(sTagName); }