private async void AddButton(object sender, RoutedEventArgs e) { var selected = DataModel.LockedTimers.Where(x => x.IsSelected).ToList(); if (selected.Count == 0) { await modelHelpers.ShowMessageAsync("Nothing Selected", "You Have Not Selected Any Locked Time To Add"); Focus(); return; } var selectedTimers = selected.Select(x => modelHelpers.Gallifrey.IdleTimerCollection.GetTimer(x.UniqueId)).Where(x => x != null).ToList(); if (selected.Count != selectedTimers.Count) { await modelHelpers.ShowMessageAsync("Out Of Date", "The Timer Window Is Out Of Date And Needs To Be Refreshed"); DataModel.RefreshLockedTimers(modelHelpers.Gallifrey.IdleTimerCollection.GetUnusedIdleTimers()); Focus(); return; } var selectedTime = new TimeSpan(); var lockedTimerDate = DateTime.MinValue; foreach (var lockedTimerModel in selected) { if (lockedTimerDate == DateTime.MinValue || lockedTimerDate.Date == lockedTimerModel.DateForTimer) { lockedTimerDate = lockedTimerModel.DateForTimer; selectedTime = selectedTime.Add(lockedTimerModel.IdleTime); } else { await modelHelpers.ShowMessageAsync("Invalid Selection", "All Timers Must Be On The Same Date!"); Focus(); return; } } JiraTimer runningTimer = null; var runningTimerId = modelHelpers.Gallifrey.JiraTimerCollection.GetRunningTimerId(); if (runningTimerId.HasValue) { runningTimer = modelHelpers.Gallifrey.JiraTimerCollection.GetTimer(runningTimerId.Value); if (runningTimer.DateStarted.Date != lockedTimerDate.Date) { runningTimer = null; } } var dialog = (BaseMetroDialog)Resources["TimeLocation"]; await modelHelpers.ShowDialogAsync(dialog); var message = dialog.FindChild <TextBlock>("TimeLocateMessage"); var runningTimerButton = dialog.FindChild <Button>("RunningTimerButton"); if (runningTimer != null) { message.Text = $"Where Would You Like To Add The Time Worth {selectedTime.FormatAsString(false)}?\n\nNote:- Running Timer Is\n{runningTimer.JiraReference} - {runningTimer.JiraName}"; runningTimerButton.Visibility = Visibility.Visible; } else { message.Text = $"Where Would You Like To Add The Time Worth {selectedTime.FormatAsString(false)}?"; runningTimerButton.Visibility = Visibility.Collapsed; } await dialog.WaitUntilUnloadedAsync(); }
private async void ExportButton(object sender, RoutedEventArgs e) { var timersToExport = DataModel.BulkExports.Where(x => x.ShouldExport).Reverse().ToList(); foreach (var exportModel in timersToExport) { if (exportModel.Timer.TimeToExport < exportModel.ToExport) { await modelHelpers.ShowMessageAsync($"Invalid Export Timer - {exportModel.JiraRef}", $"You Cannot Export More Than The Timer States Un-Exported\nThis Value Is {exportModel.ToExport:hh\\:mm}!"); return; } } try { modelHelpers.HideFlyout(this); await progressDialogHelper.Do(controller => DoExport(controller, timersToExport), "Exporting Selected Timers", false, true); } catch (BulkExportException ex) { await modelHelpers.ShowMessageAsync("Error Exporting", $"{ex.Message}"); foreach (var timer in timersToExport.Where(x => !x.Timer.FullyExported)) { timer.Timer.ClearLastJiraCheck(); } var timersToShow = DataModel.BulkExports.Where(bulkExportModel => !bulkExportModel.Timer.FullyExported).ToList(); DataModel.BulkExports.Clear(); SetupContext(timersToShow.Select(x => x.Timer).ToList(), timersToShow); Focus(); return; } var changeStatusExports = timersToExport.Where(x => x.ChangeStatus).ToList(); if (changeStatusExports.Any()) { await modelHelpers.OpenFlyout(this); foreach (var timer in changeStatusExports) { while (!string.IsNullOrWhiteSpace(currentChangeStatusJiraRef)) { await Task.Delay(TimeSpan.FromSeconds(1)); } currentChangeStatusJiraRef = timer.JiraRef; try { var transitionsAvailable = modelHelpers.Gallifrey.JiraConnection.GetTransitions(timer.JiraRef); var timeSelectorDialog = (BaseMetroDialog)Resources["TransitionSelector"]; await modelHelpers.ShowDialogAsync(timeSelectorDialog); var comboBox = timeSelectorDialog.FindChild <ComboBox>("Items"); comboBox.ItemsSource = transitionsAvailable.Select(x => x.name).ToList(); var messageBox = timeSelectorDialog.FindChild <TextBlock>("Message"); messageBox.Text = $"Please Select The Status Update You Would Like To Perform To {timer.JiraRef}"; } catch (Exception) { await modelHelpers.ShowMessageAsync("Status Update Error", "Unable To Change The Status Of This Issue"); } } lastChangeStatusSent = true; } modelHelpers.CloseFlyout(this); }
private async void AddButton(object sender, RoutedEventArgs e) { if (!DataModel.StartDate.HasValue) { await modelHelpers.ShowMessageAsync("Missing Date", "You Must Enter A Start Date"); Focus(); return; } if (DataModel.StartDate.Value.Date < DataModel.MinDate.Date || DataModel.StartDate.Value.Date > DataModel.MaxDate.Date) { await modelHelpers.ShowMessageAsync("Invalid Date", $"You Must Enter A Start Date Between {DataModel.MinDate.ToShortDateString()} And {DataModel.MaxDate.ToShortDateString()}"); Focus(); return; } var seedTime = DataModel.TimeEditable ? new TimeSpan(DataModel.StartHours ?? 0, DataModel.StartMinutes ?? 0, 0) : new TimeSpan(); Issue jiraIssue = null; var jiraRef = string.Empty; if (!DataModel.LocalTimer) { jiraRef = DataModel.JiraReference; void GetIssue() { if (modelHelpers.Gallifrey.JiraConnection.DoesJiraExist(jiraRef)) { jiraIssue = modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(jiraRef); } } var jiraDownloadResult = await progressDialogHelper.Do(GetIssue, "Searching For Jira Issue", true, false); if (jiraDownloadResult.Status == ProgressResult.JiraHelperStatus.Cancelled) { Focus(); return; } if (jiraIssue == null) { await modelHelpers.ShowMessageAsync("Invalid Jira", $"Unable To Locate The Jira '{jiraRef}'"); Focus(); return; } if (DataModel.JiraReferenceEditable) { var result = await modelHelpers.ShowMessageAsync("Correct Jira?", $"Jira found!\n\nRef: {jiraIssue.key}\nName: {jiraIssue.fields.summary}\n\nIs that correct?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Affirmative }); if (result == MessageDialogResult.Negative) { Focus(); return; } } } if (DataModel.DatePeriod) { AddedTimer = await AddPeriodTimer(jiraIssue, seedTime); } else { AddedTimer = await AddSingleTimer(jiraIssue, seedTime, DataModel.StartDate.Value); } if (!AddedTimer) { Focus(); return; } var stillDoingThings = false; if (!DataModel.LocalTimer) { if (DataModel.AssignToMe) { try { await progressDialogHelper.Do(() => modelHelpers.Gallifrey.JiraConnection.AssignToCurrentUser(jiraRef), "Assigning Issue", false, true); } catch (JiraConnectionException) { await modelHelpers.ShowMessageAsync("Assign Jira Error", "Unable To Locate Assign Jira To Current User"); } } if (DataModel.ChangeStatus) { try { var transitionResult = await progressDialogHelper.Do(() => modelHelpers.Gallifrey.JiraConnection.GetTransitions(jiraRef), "Getting Transitions To Change Status", false, true); if (transitionResult.Status == ProgressResult.JiraHelperStatus.Success) { var transitionsAvailable = transitionResult.RetVal; var timeSelectorDialog = (BaseMetroDialog)Resources["TransitionSelector"]; await modelHelpers.ShowDialogAsync(timeSelectorDialog); var comboBox = timeSelectorDialog.FindChild <ComboBox>("Items"); comboBox.ItemsSource = transitionsAvailable.Select(x => x.name).ToList(); var messageBox = timeSelectorDialog.FindChild <TextBlock>("Message"); messageBox.Text = $"Please Select The Status Update You Would Like To Perform To {DataModel.JiraReference}"; stillDoingThings = true; } } catch (Exception) { await modelHelpers.ShowMessageAsync("Status Update Error", "Unable To Change The Status Of This Issue"); } } } if (!stillDoingThings) { modelHelpers.CloseFlyout(this); modelHelpers.RefreshModel(); } }