public static string PutPostTimeEntry(MainActivity.IssuesContainer.TimeEntry timeEntry, bool isNew = false) { RestRequest request; if (isNew) { request = new RestRequest("/time_entries.json", Method.POST); } else { request = new RestRequest("/issues/" + timeEntry.issue.id + "/time_entries/" + timeEntry.id + ".json", Method.PUT); } request.AddHeader("content-type", "application/json"); request.RequestFormat = DataFormat.Json; request.RootElement = "time_entries"; request.AddJsonBody(new { time_entry = new { issue_id = timeEntry.issue.id, hours = timeEntry.hours, activity_id = 9, comments = timeEntry.comments } }); var response = client.Execute(request); return(response.Content); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.time_entry_layout); toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); toolbar.SetTitle(Resource.String.TimeEntries); SetSupportActionBar(toolbar); pd = new ProgressDialog(this); issue = RedMineManager.Get <IssuesContainer.Issue>("/issues/" + Intent.GetIntExtra("IssueID", 0) + ".json", "issue"); issue.timeEntries = RedMineManager.Get <List <IssuesContainer.TimeEntry> >("/issues/" + Intent.GetIntExtra("IssueID", 0) + "/time_entries.json?nometa=1", "time_entries"); PBProgress = FindViewById <ProgressBar>(Resource.Id.progress); TVSpentTime = FindViewById <TextView>(Resource.Id.spent_time); TVEstimatedTime = FindViewById <TextView>(Resource.Id.estimated_time); BPlay = FindViewById <ImageView>(Resource.Id.play); BStop = FindViewById <ImageView>(Resource.Id.stop); BPause = FindViewById <ImageView>(Resource.Id.pause); LLRoot = FindViewById <LinearLayout>(Resource.Id.root); RLConfirm = FindViewById <RelativeLayout>(Resource.Id.confirm); RLConfirm.Visibility = ViewStates.Gone; ETComment = FindViewById <EditText>(Resource.Id.comment); BSubmit = FindViewById <Button>(Resource.Id.submit); spentTime = TimeSpan.FromHours(issue.spent_hours); newSpentTime = new TimeSpan(); estimatedTime = TimeSpan.FromHours(issue.estimated_hours); float r = (float)spentTime.Ticks / (float)estimatedTime.Ticks; PBProgress.Progress = Convert.ToInt32((float)r * (float)100); ShowTimeEntries(); progress = new Thread(() => { HandleSpentTime(); }); BPlay.Click += delegate { progress.Start(); BPlay.Visibility = ViewStates.Gone; BStop.Visibility = ViewStates.Visible; }; BPause.Click += delegate { if (progress.IsAlive) { progress.Suspend(); } else { progress.Resume(); } }; BStop.Click += delegate { RLConfirm.Visibility = ViewStates.Visible; progress.Abort(); }; BSubmit.Click += delegate { IssuesContainer.TimeEntry t = new IssuesContainer.TimeEntry(); t.issue = issue; t.comments = ETComment.Text; t.hours = newSpentTime.TotalHours; BPlay.Visibility = ViewStates.Visible; BStop.Visibility = ViewStates.Gone; Toast.MakeText(this, RedMineManager.PutPostTimeEntry(t, true), ToastLength.Short).Show(); Recreate(); }; TVSpentTime.Text = spentTime.ToString(); TVEstimatedTime.Text = estimatedTime.ToString(); }