/// <summary> /// Get Time Entries data for employee /// </summary> /// <param name="consumerSecretToken"></param> /// <param name="dataAccessToken"></param> /// <param name="version"></param> /// <param name="employeeId"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns>IList<TimeEntryBO></returns> public IList <TimeEntryBO> GetTimeEntries(string consumerSecretToken, string dataAccessToken, string version, int employeeId, DateTime startDate, DateTime?endDate = null) { // Create date variables string fromDate = startDate.ToString("yyyy-MM-dd"); string toDate = endDate == null ? fromDate : ((DateTime)endDate).ToString("yyyy-MM-dd"); // Create query parameters and query string string datetimeParamter = string.Concat(fromDate, " ", toDate); string employeeParameter = string.Concat("Employee/", employeeId.ToString(CultureInfo.InvariantCulture)); string queryString = string.IsNullOrEmpty(datetimeParamter) ? string.Empty : string.Concat("daterange=", datetimeParamter); // Create uri to hit and make request using Dovico.CommonLibrary CRestApiHelper.MakeAPIRequest method string uri = CRestApiHelper.BuildURI(string.Concat("TimeEntries/", employeeParameter, "/"), queryString, version); string result = CRestApiHelper.MakeAPIRequest(uri, "GET", CRestApiHelper.MIME_TYPE_APPLICATION_JSON, String.Empty, consumerSecretToken, dataAccessToken); // Check for errors in return value UtilityService.CheckErrorsInDovicoAPI(result); // Convert data to TimeEntryBO IList <TimeEntryBO> timeEntires = DeserializeObject(result).TimeEntries; return(timeEntires); }
/// <summary> /// For Updating time entry /// </summary> /// <param name="consumerSecretToken"></param> /// <param name="dataAccessToken"></param> /// <param name="version"></param> /// <param name="timeEntrySubmissionDetails"></param> /// <returns>IList<TimeEntryBO></returns> public IList <TimeEntryBO> UpdateTimeEntry(string consumerSecretToken, string dataAccessToken, string version, TimeEntrySubmissionBO timeEntrySubmissionDetails) { string fromDate = timeEntrySubmissionDetails.StartDate.ToString("yyyy-MM-dd"); timeEntrySubmissionDetails.Description = timeEntrySubmissionDetails.Description.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\"", "'"); // Create Post Data CStringBuilder postData = new CStringBuilder(); postData.Append("{"); if (!string.IsNullOrEmpty(timeEntrySubmissionDetails.ClientId)) { postData.Append(string.Concat("\"ClientID\":\"", timeEntrySubmissionDetails.ClientId, "\",")); } postData.Append(string.Concat("\"ProjectID\":\"", timeEntrySubmissionDetails.ProjectId, "\",")); postData.Append(string.Concat("\"TaskID\":\"", timeEntrySubmissionDetails.TaskId, "\",")); postData.Append(string.Concat("\"EmployeeID\":\"", timeEntrySubmissionDetails.EmployeeId, "\",")); postData.Append(string.Concat("\"Date\":\"", fromDate, "\",")); // Convert start/stop time to 24 hours format if (!string.IsNullOrEmpty(timeEntrySubmissionDetails.StartTime)) { postData.Append(string.Concat("\"StartTime\":\"", Convert.ToDateTime(timeEntrySubmissionDetails.StartTime).ToString("HHmm"), "\",")); } if (!string.IsNullOrEmpty(timeEntrySubmissionDetails.StopTime)) { postData.Append(string.Concat("\"StopTime\":\"", Convert.ToDateTime(timeEntrySubmissionDetails.StopTime).ToString("HHmm"), "\",")); } postData.Append(string.Concat("\"Description\":\"", timeEntrySubmissionDetails.Description, "\",")); postData.Append(string.Concat("\"Billable\":\"", timeEntrySubmissionDetails.Billable ? "T" : "F", "\",")); postData.Append(string.Concat("\"TotalHours\":\"", timeEntrySubmissionDetails.Hours, "\",")); postData.Append("\"CustomFields\":"); postData.Append("["); StringBuilder innerPostData = new StringBuilder(); // For Custom Fields if (timeEntrySubmissionDetails.CustomFields != null && timeEntrySubmissionDetails.CustomFields.Count > 0) { foreach (CustomFieldSubmissionBO customField in timeEntrySubmissionDetails.CustomFields) { innerPostData.Append("{"); if (String.IsNullOrEmpty(customField.ID)) { innerPostData.Append(string.Concat("\"ID\":\"", "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", "\",")); } else { innerPostData.Append(string.Concat("\"ID\":\"", customField.ID, "\",")); } innerPostData.Append(string.Concat("\"TemplateID\":\"", customField.TemplateID, "\",")); innerPostData.Append("\"Values\":"); innerPostData.Append("["); if (customField.Values != null) { foreach (ValueItemsSubmission item in customField.Values) { innerPostData.Append(string.Concat("\"", item.Value, "\",")); } innerPostData.Remove(innerPostData.Length - 1, 1); } innerPostData.Append("]"); innerPostData.Append("},"); } innerPostData.Remove(innerPostData.Length - 1, 1); } postData.Append(innerPostData.ToString()); postData.Append("]"); postData.Append("}"); // Create uri to hit and make request using Dovico.CommonLibrary CRestApiHelper.MakeAPIRequest method string uri = CRestApiHelper.BuildURI(string.Concat("TimeEntries/", timeEntrySubmissionDetails.TimeEntryId), null, version); string result = CRestApiHelper.MakeAPIRequest(uri, "PUT", CRestApiHelper.MIME_TYPE_APPLICATION_JSON, postData, consumerSecretToken, dataAccessToken); UtilityService.CheckErrorsInDovicoAPI(result); IList <TimeEntryBO> timeEntries = DeserializeObject(result).TimeEntries; return(timeEntries); }