private TimeSpan CalculateTotalTime() { if (_taskTimeTrackingView.Count == 0) { return(TimeSpan.Zero); } var totalTime = new TimeSpan(); totalTime = _taskTimeTrackingView.Cast <DataRowView>().Select(dataRow => TimeIntervalCountConverter.CalculateTimeInterval( (TimeSpan)dataRow["TimeStart"], (TimeSpan)dataRow["TimeEnd"])) .Aggregate(totalTime, (current, interval) => current.Add(interval)); return(totalTime); }
private void SaveButton_Click(object sender, RoutedEventArgs e) { // Don't save if information is empty if (_taskTimeTrackingView.Count == 0) { CancelButton_Click(null, null); return; } // Save confirm and edited information var totalTime = new TimeSpan(); foreach (var dataRow in _taskTimeTrackingView.Cast <DataRowView>()) { var taskTimeTrackingId = Convert.ToInt32(dataRow["TaskTimeTrackingID"]); var timeStart = (TimeSpan)dataRow["TimeStart"]; var timeEnd = (TimeSpan)dataRow["TimeEnd"]; var interval = TimeIntervalCountConverter.CalculateTimeInterval(timeStart, timeEnd); totalTime = totalTime.Add(interval); _taskClass.TaskTimeTracking.SetTimeInterval(taskTimeTrackingId, timeStart, timeEnd); if (Convert.ToBoolean(dataRow["IsVerificated"])) { var verificationDate = Convert.ToDateTime(dataRow["VerificationDate"]); var verificationWorkerId = Convert.ToInt32(dataRow["VerificationWorkerID"]); _taskClass.TaskTimeTracking.Confirm(taskTimeTrackingId, verificationWorkerId, verificationDate, false); } } _taskClass.Performers.SetTimeSpend(_performerId, totalTime); CancelButton_Click(null, null); }