public async Task <IActionResult> Create([Bind("Id,ToDoListId,Name,Description,Done")] Task task) { if (!ModelState.IsValid) { return(View( new TaskCreateEditViewModel { TodoListId = task.ToDoListId, Name = task.Name, Description = task.Description })); } await _taskService.CreateTask(task); this.AddAlertSuccess($"{task.Name} created."); return(RedirectToAction(nameof(Index), new { listId = task.ToDoListId })); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ToDoListId,Name,Description,Done")] Task task) { if (id != task.Id) { return(NotFound()); } if (!ModelState.IsValid) { return(View( new TaskCreateEditViewModel { Id = task.Id, TodoListId = task.ToDoListId, Name = task.Name, Description = task.Description, Done = task.Done })); } try { await _taskService.UpdateTask(task); } catch (DbUpdateConcurrencyException) { var taskExists = await _taskService.TaskExists(task.Id); if (!taskExists) { return(NotFound()); } throw; } this.AddAlertSuccess($"{task.Name} updated."); return(RedirectToAction(nameof(Index), new { listId = task.ToDoListId })); }
public System.Threading.Tasks.Task RemoveTask(Task task) { _context.Task.Remove(task); return(_context.SaveChangesAsync()); }
public System.Threading.Tasks.Task UpdateTask(Task task) { _context.Update(task); return(_context.SaveChangesAsync()); }