public async Task <IActionResult> Edit(Task task) { if (ModelState.IsValid) { try { task.UserId = _workContext.UserId; _context.Update(task); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskExists(task.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index), new { projectId = task.ProjectId })); } return(View(task)); }
/// <summary> /// Callback for when a task is started. /// </summary> /// <param name="asyncTask"></param> /// <param name="task"></param> private void OnActiveTaskStartComplete(Task <TimeEntry> asyncTask, Task task) { task.IsActive = true; ActiveTask = task; ActiveTimeEntry = asyncTask.Result; Timer = GetTime(ActiveTask, ActiveTimeEntry); IsFooterTrayVisible = true; }
/// <summary> /// Callback for when the current task's timer is stopped. /// </summary> /// <param name="asyncTask"></param> /// <param name="callback"></param> private void OnEndActiveTaskComplete(Task <TimeEntry> asyncTask, Action <System.Threading.Tasks.Task> callback) { TimeEntry t = asyncTask.Result; ActiveTask.TimeEntries.Add(t); callback(asyncTask); ResetActiveTask(); }
/// <summary> /// Sends request to service to start a timer for the given task. /// </summary> /// <param name="task"></param> private void ActivateTask(Task task) { var asyncTask = System.Threading.Tasks.Task.Run(() => _taskService.StartTask(task)); asyncTask.ContinueWith((t) => { OnActiveTaskStartComplete(t, task); }, TaskScheduler.FromCurrentSynchronizationContext()); }
public async Task <IActionResult> Create(Task task) { if (ModelState.IsValid) { task.Status = "Not solved"; task.UserId = _workContext.UserId; _context.Add(task); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { task.ProjectId })); } return(View(task)); }
/// <summary> /// Set the current task to be timed. /// </summary> /// <param name="task"></param> public void SetActiveTask(Task task) { if (ActiveTask != null) { //Disable the current task before starting a new one. ActiveTask.IsActive = false; EndActiveTask(o => { ActivateTask(task); }); } else { //No task is already active. Start the new task. ActivateTask(task); } }
/// <summary> /// Calculates the duration of the current task, then builds a string /// representation of the task's timer. /// </summary> /// <param name="t"></param> /// <param name="activeTimeEntry"></param> /// <returns></returns> public string GetTime(Task t, TimeEntry activeTimeEntry) { if (t == null) { return(""); } TimeSpan timeDifference; if (activeTimeEntry == null) { timeDifference = new TimeSpan(); } else { timeDifference = DateTime.Now - activeTimeEntry.Start; } var span = t.CalculateSpan(); var totalSeconds = (timeDifference + span).TotalSeconds; var time = TimeSpan.FromSeconds(totalSeconds); var str = ""; if (time.Hours > 0) { str += time.Hours + " hrs "; } if (time.Minutes > 0) { str += time.Minutes + " min "; } if (time.Seconds > 0) { str += time.Seconds + " sec"; } else { str += "0 sec"; } return(str); }