/// <summary> /// Method to authenticate user /// </summary> /// <param name="consumerSecretToken"></param> /// <param name="version"></param> /// <param name="company"></param> /// <param name="username"></param> /// <param name="password"></param> /// <returns>string</returns> public string Authenticate(string consumerSecretToken, string version, string company, string username, string password) { string dataAccessToken = string.Empty; // Create Post Data CStringBuilder postData = new CStringBuilder(); postData.Append("{"); postData.Append(string.Concat("\"CompanyName\":\"", company, "\",")); postData.Append(string.Concat("\"UserName\":\"", username, "\",")); postData.Append(string.Concat("\"Password\":\"", password, "\"")); postData.Append("}"); // Make request using Dovico.CommonLibrary CRestApiHelper.MakeAPIRequest method string result = CRestApiHelper.MakeAPIRequest(CRestApiHelper.BuildURI("Authenticate", null, version), "Post", CRestApiHelper.MIME_TYPE_APPLICATION_JSON, postData, consumerSecretToken, null); // Check for errors in return value UtilityService.CheckErrorsInDovicoAPI(result); // Fetch DataAccessToken from CommonLibrary result JavaScriptSerializer objJavaScriptSerializer = new JavaScriptSerializer(); objJavaScriptSerializer.MaxJsonLength = int.MaxValue; dynamic objJsonResultRootObject = objJavaScriptSerializer.DeserializeObject(result); Dictionary <string, object> dictionary = objJsonResultRootObject; dataAccessToken = dictionary["DataAccessToken"].ToString(); return(dataAccessToken); }
/// <summary> /// Submit the time entries /// </summary> /// <param name="consumerSecretToken"></param> /// <param name="dataAccessToken"></param> /// <param name="version"></param> /// <param name="employeeId"></param> /// <param name="startDateOfWeek"></param> /// <param name="endDateOfWeek"></param> /// <returns>IList<TimeEntryBO></returns> public IList <TimeEntryBO> SubmitWeekTimeEntryForApproval(string consumerSecretToken, string dataAccessToken, string version, int employeeId, DateTime startDateOfWeek, DateTime endDateOfWeek) { // Create parameters and uri string dateRangeParameter = string.Concat(startDateOfWeek.ToString("yyyy-MM-dd"), " ", endDateOfWeek.ToString("yyyy-MM-dd")); string employeeParameter = string.Format("TimeEntries/Employee/{0}/Submit", Convert.ToString(employeeId)); string queryString = string.Concat("daterange=", dateRangeParameter); string uri = CRestApiHelper.BuildURI(employeeParameter, queryString, version); CStringBuilder postData = new CStringBuilder(); postData.Append("{"); postData.Append("}"); // Make request using Dovico.CommonLibrary CRestApiHelper.MakeAPIRequest method string result = CRestApiHelper.MakeAPIRequest(uri, "POST", CRestApiHelper.MIME_TYPE_APPLICATION_JSON, postData, consumerSecretToken, dataAccessToken); UtilityService.CheckErrorsInDovicoAPI(result); IList <TimeEntryBO> timeEntries = DeserializeObject(result).TimeEntries; return(timeEntries); }
/// <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); }