private async void BtnSave_Click(object sender, RoutedEventArgs e) { DateTime dayIn = DateTimeHelper.Parse(DateIn.SelectedDate); DateTime timeIn = new DateTime(dayIn.Year, dayIn.Month, dayIn.Day, CmbAMPMIn.Text == "AM" ? CmbHourIn.SelectedIndex : CmbHourIn.SelectedIndex + 12, Int32Helper.Parse(CmbMinuteIn.SelectedItem), Int32Helper.Parse(CmbSecondIn.SelectedItem)); TimeSpan tsIn = TimeSpanHelper.Parse(TxtInOffset.Text); DateTime dayOut = DateTimeHelper.Parse(DateOut.SelectedDate); DateTime timeOut = CmbHourOut.SelectedIndex >= 0 ? new DateTime(dayOut.Year, dayOut.Month, dayOut.Day, CmbAMPMOut.Text == "AM" ? CmbHourOut.SelectedIndex : CmbHourOut.SelectedIndex + 12, Int32Helper.Parse(CmbMinuteOut.SelectedItem), Int32Helper.Parse(CmbSecondOut.SelectedItem)) : DateTime.MinValue; TimeSpan tsOut = TxtOutOffset.Text.Length > 0 ? TimeSpanHelper.Parse(TxtOutOffset.Text) : TimeSpan.Zero; Shift newShift = new Shift(AppState.CurrentUser.ID, CmbRole.SelectedItem.ToString(), timeIn - tsIn, tsIn, timeOut - tsOut, tsOut, true); bool save = false; if (tsIn != TimeSpan.Zero || (tsIn == TimeSpan.Zero && (string.IsNullOrWhiteSpace(TxtInOffset.Text) || TxtInOffset.Text == "00:00:00"))) { if (tsOut != TimeSpan.Zero) { save = true; } else if (tsOut == TimeSpan.Zero && (string.IsNullOrWhiteSpace(TxtOutOffset.Text) || TxtOutOffset.Text == "00:00:00")) { save = true; } } if (save) { if (!_newTime) { await AppState.ModifyShift(_selectedShift, newShift).ConfigureAwait(false); } else { await AppState.AddShift(newShift).ConfigureAwait(false); } AppState.CurrentUser.LoggedIn = AppState.CurrentUser.GetMostRecentShift().EndTimeUtc == DateTime.MinValue; Dispatcher.Invoke(() => { Clear(); RefreshItemsSource(); }); } else { AppState.DisplayNotification("Please ensure that valid UTC offsets are entered in the TextBoxes, e.g. \"-05:00:00\" or \"08:45:00\". The clock in and out offsets should be the same unless a time zone transition occurred.", "Time Clock"); } }