public async Task <IActionResult> CreateTimeEntry(TimeEntryClockify timeEntry) { HttpClient client = new HttpClient(); var RedmineUserID = Dictionarys.CloclifyToRedmineUserId[timeEntry.UserId]; var RedmineAPiKey = Dictionarys.RedmineUserIdApi[RedmineUserID]; client.DefaultRequestHeaders.Add("X-Redmine-API-Key", RedmineAPiKey); var timeEntryToSend = new TimeEntryRedmine(); var timeSpan = timeEntry.TimeInterval.Start - timeEntry.TimeInterval.End; timeEntryToSend.hours = timeSpan.TotalHours; //name of activity to id if (timeEntry.Tags.FirstOrDefault() != null) { timeEntryToSend.activity_id = Convert.ToInt32(Dictionarys.TimeActivitysClockifyRedmine[timeEntry.Tags.First().Id]); } timeEntryToSend.comments = timeEntry.Description?.Take(250).ToString(); //issue_id = timeEntry.task.TaskID -> issueId|| ..task.name -> issueId timeEntryToSend.issue_id = 142;// Convert.ToInt32(timeEntry.Task.Id); timeEntryToSend.spent_on = timeEntry.TimeInterval.Start; var s = XmlConverter.XmlConvert(timeEntryToSend); var data = new StringContent(s, Encoding.UTF8, "application/xml"); var response = await client.PostAsync("https://task.powerbooks.xyz/time_entries.xml", data); return(Ok(timeEntry)); }
public static string XmlConvert(TimeEntryRedmine timeEntryRedmine) { var s = "<?xml version='1.0' encoding='utf-16'?>" + "<time_entry xmlns:xsi = 'http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd = 'http://www.w3.org/2001/XMLSchema' >" + $"<issue_id>{timeEntryRedmine.issue_id}</issue_id>" + $"<spent_on>{timeEntryRedmine.spent_on.ToString("yyyy-MM-dd")}</spent_on>" + $"<hours>{timeEntryRedmine.hours}</hours>" + $"<activity_id>{timeEntryRedmine.activity_id}</activity_id>" + "</time_entry>"; return(s); }