private async Task <double> GetCurrentDuration() { double durationInSeconds = 0; if (UserTaskTimeList != null) { var userTaskTimeHistory = UserTaskTimeList.Where(c => c.EndTime != DateTime.MinValue); foreach (var item in userTaskTimeHistory) { durationInSeconds = (item.EndTime - item.StartTime).TotalSeconds; } if (UserTask.Status == UserTaskStatus.Active) { var currentTasktime = UserTaskTimeList.FirstOrDefault(c => c.EndTime == DateTime.MinValue); if (currentTasktime != null) { durationInSeconds = durationInSeconds + (DateTime.Now - currentTasktime.StartTime).TotalSeconds; } } } return(durationInSeconds); }
private async Task <UserTaskTime> RecordUserTaskTime(bool isStartTimer) { UserTaskTime usertaskTime = null; if (UserTaskTimeList != null) { usertaskTime = UserTaskTimeList.FirstOrDefault(userTasktime => userTasktime.EndTime == DateTime.MinValue); } if (usertaskTime == null) { usertaskTime = new UserTaskTime(); usertaskTime.UserTaskID = UserTask.UserTaskID; } if (isStartTimer) { usertaskTime.StartTime = DateTime.Now; usertaskTime = await _userTaskService.CreateUserTaskTime(usertaskTime); UserTaskTimeList.Add(usertaskTime); } else { usertaskTime.EndTime = DateTime.Now; await _userTaskService.UpdateUserTaskTime(usertaskTime); } return(usertaskTime); }