/// <summary>
        /// Handles click on the button by displaying a message box.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private void Timer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                spinner.Visibility = Visibility.Visible;
                spinner.Refresh();
                if (textBox_apiKey.Text.Length == 0)
                {
                    MessageBox.Show("Please fill the Clockify API Key");
                }
                else if (comboBoxDesc.Text.Length == 0)
                {
                    MessageBox.Show("Please add description");
                }
                else if (comboBoxProject.SelectedValue.ToString().Length == 0)
                {
                    MessageBox.Show("Please select a project");
                }
                else if (!_timerStart)
                {
                    //progressbar.Value = 30;

                    var _res = ClockifyUtility.StartClockify(workspaceId, new TimeEntryRequest()
                    {
                        start       = DateTime.UtcNow,
                        description = comboBoxDesc.Text,
                        projectId   = comboBoxProject.SelectedValue.ToString()
                    });
                    //progressbar.Value = 90;
                    if (!string.IsNullOrEmpty(_res?.id))
                    {
                        _timerStart         = !_timerStart;
                        buttonTimer.Content = "Stop Timer";
                    }
                }
                else
                {
                    var _res = ClockifyUtility.StopClockify(workspaceId, _user.id, new StopTimeEntryRequest()
                    {
                        end = DateTime.UtcNow
                    });
                    if (!string.IsNullOrEmpty(_res?.id))
                    {
                        _timerStart         = !_timerStart;
                        buttonTimer.Content = "Start Timer";
                    }
                }

                //progressbar.Visibility = Visibility.Hidden;
            }
            catch (Exception ex)
            {
                //buttonApply.Content = !_timerStart ? "Start Timer" : "Stop Timer";
                //progressbar.Visibility = Visibility.Hidden;
                MethodLogger.SaveLogToFile("Timer_Click exception:" + ex.Message);
                MethodLogger.SaveLogToFile("Timer_Click exception:" + ex.StackTrace);
            }

            spinner.Visibility = Visibility.Hidden;
        }
        private async Task <bool> loadClockifyData()
        {
            _user = ClockifyUtility.GetUser();
            //progressbar.Value = 45;
            if (!string.IsNullOrEmpty(_user?.id))
            {
                labelTitle.Content           = _user.name;
                ExpanderTimePanel.IsExpanded = false;
                ExpanderTimeLog.IsExpanded   = true;
                expander.IsExpanded          = false;
                TimerPanel.Visibility        = Visibility.Visible;

                _projects = ClockifyUtility.GetProjects(workspaceId);
                // progressbar.Value = 80;
                if ((_projects?.Count ?? 0) > 0)
                {
                    //comboBoxProject.Items.Clear();
                    comboBoxProject.DisplayMemberPath = "name";
                    comboBoxProject.SelectedValuePath = "id";

                    var _proj = _projects.FindAll(a => !a.archived);
                    comboBoxProject.ItemsSource = _proj;

                    for (int i = 0; i < _proj.Count; i++)
                    {
                        if (ServiceUtility.ClockifyDefaultProject == _proj[i].id)
                        {
                            comboBoxProject.SelectedItem = _proj[i];
                            comboBoxProject.Text         = _proj[i].name;
                            //comboBoxProject.SelectedIndex = i;
                        }
                    }
                    if (comboBoxProject.SelectedIndex <= 0 && comboBoxProject.HasItems)
                    {
                        // comboBoxProject.SelectedIndex = 0;
                        comboBoxProject.SelectedItem = _proj[0];
                        comboBoxProject.Text         = _proj[0].name;
                    }
                    setDate();
                    LoadWeeklyTimeLog();
                }
            }
            else
            {
                //ExpanderTimePanel.Visibility = Visibility.Hidden;
                // TimerPanel.Visibility = Visibility.Hidden;
                ExpanderTimePanel.IsExpanded = false;
                ExpanderTimeLog.IsExpanded   = false;
                expander.IsExpanded          = true;
            }
            return(true);
        }
        private void LoadWeeklyTimeLog()
        {
            lblStatus.Content = "";

            var thisWeekStart = dpStart.SelectedDate;
            var thisWeekEnd   = dpEnd.SelectedDate;

            if (thisWeekStart.HasValue && thisWeekEnd.HasValue)
            {
                //ListTimeEntries.ItemsSource = dt;
                var res = ClockifyUtility.GetTimeEntries(workspaceId, _user.id, thisWeekStart.Value, thisWeekEnd.Value);
                dataGrid1.ItemsSource = res;
                lblTot.Content        = "Total: " + Math.Round(res.Sum(r => r.durationD), 2);
            }
        }
 private void buttonSync_Click(object sender, RoutedEventArgs e)
 {
     spinner.Visibility = Visibility.Visible;
     spinner.Refresh();
     if (dataGrid1.ItemsSource != null)
     {
         var count = 0;
         foreach (var itm in dataGrid1.ItemsSource)
         {
             var i = itm as TimeEntryResult;
             if (i != null && i.selected && !string.IsNullOrEmpty(i.taskId) && i.durationD > 0)
             {
                 var changes = new List <WorkItemChange>()
                 {
                     new WorkItemChange()
                     {
                         op = Constants.ActionType.ADD, path = Constants.Attributes.CompletedHours, value = i.durationD.ToString()
                     },
                     new WorkItemChange()
                     {
                         op = Constants.ActionType.ADD, path = Constants.Attributes.RemainingHours, value = i.remaining.ToString()
                     }
                 };
                 if (i.state != i.azureItem.State)
                 {
                     changes.Add(new WorkItemChange()
                     {
                         op = Constants.ActionType.ADD, path = Constants.Attributes.State, value = i.state.ToString()
                     });
                 }
                 var st = ClockifyUtility.PatchWorkItems(i.taskId, changes);
                 if (st)
                 {
                     count++;
                 }
             }
         }
         LoadWeeklyTimeLog();
         lblStatus.Content = count + " record/s has been updated";
     }
     spinner.Visibility = Visibility.Hidden;
 }
        private void comboTxtChanged(object sender, string txt)
        {
            ComboBox cmb = (ComboBox)sender;

            cmb.IsDropDownOpen = true;
            if (_timerStart)
            {
                _timerStart         = !_timerStart;
                buttonTimer.Content = "Start Timer";
            }
            var _txt = !string.IsNullOrEmpty(cmb.Text) ? cmb.Text : (!string.IsNullOrEmpty(txt) ? txt : "");

            if (!string.IsNullOrEmpty(_txt) && _txt.Length >= 3)
            {
                var res = ClockifyUtility.GetWorkItems(_txt, _user.name, _user.email);
                if (res != null)
                {
                    cmb.ItemsSource = res.OrderByDescending(a => Int32.Parse(a.Id)).ToList();
                    //cmb.DisplayMemberPath = "Desc";
                    //cmb.SelectedValuePath = "Title";
                }
            }
        }
 private void setDate()
 {
     dpStart.SelectedDate = ClockifyUtility.GetWeekStart();
     dpEnd.SelectedDate   = ClockifyUtility.GetWeekEnd();
 }