public void Post(Models.Task task) { if (task.task == null || task.task == string.Empty) { throw new WebException("Please provide a task description"); } string owner = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; task.owner = owner; task.completed = false; task.date = DateTime.UtcNow; db.Tasks.Add(task); db.SaveChanges(); }
private async Task AsyncItemUpdate(Guid taskId) { await Task.Run(() => { using (var dbContext = new TasksServiceContext()) { var processTask = dbContext.ProcessTasks .Where(t => t.TaskId == taskId) .FirstOrDefault(); processTask.StatusChangeDate = DateTime.UtcNow; processTask.Status = "running"; dbContext.SaveChanges(); Task.Delay(new TimeSpan(0, 2, 0)).Wait(); processTask.StatusChangeDate = DateTime.UtcNow; processTask.Status = "finished"; dbContext.SaveChanges(); } }); }