Exemplo n.º 1
0
 // 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);
 }
Exemplo n.º 2
0
        // 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));
        }
Exemplo n.º 3
0
        // Returns the assignments for the URI requested (if there are multiple pages of data, pass in the NextPageURI. If you are trying to get
        // the child assignment items, pass in the GetAssignmentsURI value of the item you wish to drill down on)
        public static string GetAssignments(string sAssignmentsURI, ref APIRequestResult aRequestResult)
        {
            // Set the URI if one was specified
            if (sAssignmentsURI != "") { aRequestResult.SetRequestURI(sAssignmentsURI); }

            // Request the list of child assignments
            CRestApiHelper.MakeAPIRequest(aRequestResult);
            return (aRequestResult.HadRequestError ? aRequestResult.GetRequestErrorMessage() : aRequestResult.RequestResult);
        }
Exemplo n.º 4
0
        // 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);
        }
Exemplo n.º 5
0
        //=====================================================================
        // 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;
        }
Exemplo n.º 6
0
        // A request for the logged in Employee's info (this information is quite limited but may be the only employee information you can obtain
        // if the logged in user has no employee access permissions. this will return the employee's ID, Last Name, and First Name - with the ID,
        // you can call getInfo and 'try' to get the rest of the info if desired)
        //
        // If there was an error the return value will be null
        public static CEmployee GetInfoMe(APIRequestResult aRequestResult)
        {
            // Set the URI for the Employee/Me/ 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/Me/", "");
            List<CEmployee> lstEmployees = ProcessRequest(aRequestResult);
            if (lstEmployees != null) { return lstEmployees[0]; }

            // An error happened so just return null.
            return null;
        }
Exemplo n.º 7
0
        //=====================================================================
        // 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));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns if the Employee is Billable
        /// </summary>
        /// <param name="consumerSecretToken"></param>
        /// <param name="dataAccessToken"></param>
        /// <param name="version"></param>
        /// <returns>string</returns>
        public string ShowEmployeeBillable(string consumerSecretToken, string dataAccessToken, string version)
        {
            // Calls Dovico.CommonLibrary CEmployee.GetInfoMeOptions method
            APIRequestResult apiRequestResult = new APIRequestResult(consumerSecretToken, dataAccessToken, version)
            {
                ContentType = CRestApiHelper.MIME_TYPE_APPLICATION_JSON
            };
            string result = CEmployee.GetInfoMeOptions(ref apiRequestResult);

            return(result);
        }
Exemplo n.º 9
0
        // Returns the assignments for the URI requested (if there are multiple pages of data, pass in the NextPageURI. If you are trying to get
        // the child assignment items, pass in the GetAssignmentsURI value of the item you wish to drill down on)
        public static string GetAssignments(string sAssignmentsURI, ref APIRequestResult aRequestResult)
        {
            // Set the URI if one was specified
            if (sAssignmentsURI != "")
            {
                aRequestResult.SetRequestURI(sAssignmentsURI);
            }

            // Request the list of child assignments
            CRestApiHelper.MakeAPIRequest(aRequestResult);
            return(aRequestResult.HadRequestError ? aRequestResult.GetRequestErrorMessage() : aRequestResult.RequestResult);
        }
Exemplo n.º 10
0
        //=====================================================================
        // 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);
        }
Exemplo n.º 11
0
        public static string GetInfoMeOptions(ref APIRequestResult aRequestResult)
        {
            // Set the URI for the Employee/Me/ 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/Me/Options/", "");
            aRequestResult.ContentType = "text/xml";
            CRestApiHelper.MakeAPIRequest(aRequestResult);

            XmlDocument xdDoc = new XmlDocument();

            xdDoc.LoadXml(aRequestResult.RequestResult);
            string ShowBillable = CXMLHelper.GetChildNodeValue(xdDoc.DocumentElement, "ShowBillable");

            return(ShowBillable);
        }
Exemplo n.º 12
0
        // A request for the logged in Employee's info (this information is quite limited but may be the only employee information you can obtain
        // if the logged in user has no employee access permissions. this will return the employee's ID, Last Name, and First Name - with the ID,
        // you can call getInfo and 'try' to get the rest of the info if desired)
        //
        // If there was an error the return value will be null
        public static CEmployee GetInfoMe(APIRequestResult aRequestResult)
        {
            // Set the URI for the Employee/Me/ 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/Me/", "");
            List <CEmployee> lstEmployees = ProcessRequest(aRequestResult);

            if (lstEmployees != null)
            {
                return(lstEmployees[0]);
            }

            // An error happened so just return null.
            return(null);
        }
Exemplo n.º 13
0
        // 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;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets the employee data
        /// </summary>
        /// <param name="consumerSecretToken"></param>
        /// <param name="dataAccessToken"></param>
        /// <param name="version"></param>
        /// <returns>EmployeeBO</returns>
        public EmployeeBO GetEmployeeData(string consumerSecretToken, string dataAccessToken, string version)
        {
            EmployeeBO employee = null;

            // Calls Dovico.CommonLibrary CEmployee.GetInfoMe method
            APIRequestResult apiRequestResult = new APIRequestResult(consumerSecretToken, dataAccessToken, version);
            CEmployee        cEmployee        = CEmployee.GetInfoMe(apiRequestResult);

            // Convert data to EmployeeBO
            if (cEmployee != null)
            {
                employee = new EmployeeBO()
                {
                    ID        = Convert.ToString(cEmployee.ID.ID),
                    FirstName = cEmployee.FirstName,
                    LastName  = cEmployee.LastName
                };
            }

            return(employee);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets data for Assignments (Client, Project, Task) based on employeeId
        /// </summary>
        /// <param name="consumerSecretToken"></param>
        /// <param name="dataAccessToken"></param>
        /// <param name="version"></param>
        /// <param name="employeeId"></param>
        /// <returns>IList<AssignmentBO></returns>
        public IList <AssignmentBO> GetAssignments(string consumerSecretToken, string dataAccessToken, string version, int employeeId)
        {
            IList <AssignmentBO> assignments = null;

            // Calls Dovico.CommonLibrary CAssignments.GetAssignments method
            APIRequestResult apiRequestResult = new APIRequestResult(consumerSecretToken, dataAccessToken, version)
            {
                ContentType = CRestApiHelper.MIME_TYPE_APPLICATION_JSON
            };
            string cAssignmentsResult = CAssignments.GetAssignments(employeeId, ref apiRequestResult);

            // Convert data to AssignmentBO
            if (Utility.IsJson(cAssignmentsResult))
            {
                assignments = DeserializeObject(cAssignmentsResult).Assignments;
            }
            else
            {
                throw new DovicoException(cAssignmentsResult);
            }

            return(assignments);
        }
Exemplo n.º 16
0
        // 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;
        }
Exemplo n.º 17
0
        // 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);
        }
Exemplo n.º 18
0
 //=====================================================================
 // 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);
 }
Exemplo n.º 19
0
        // 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);
        }
Exemplo n.º 20
0
        // 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;
        }