public async Task <IActionResult> Edit(int id, [Bind("Priority,Type,Id,Title,Description,Status")] todoModels.Task task) { if (id != task.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(task); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskExists(task.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(task)); }
public async Task <bool> UpdateAsync(Entities.Task task) { try { _dbContext.Update(task); await _dbContext.SaveChangesAsync(); return(true); } catch (DbUpdateConcurrencyException) { //todo: log somewhere the exception return(false); } }
public IActionResult MarkComplete(int id) { Tasks found = _context.Task.Find(id); if (found != null) { //change the things (we're changing the completed status) found.Completed = !found.Completed; //modify the state of this entry in the database _context.Entry(found).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.Update(found); _context.SaveChanges(); } return(RedirectToAction("TasksIndex", new { id = found.Id })); }
Task <ActionResult> UpdateTask(int id, Task newTask) { if (!ModelState.IsValid) { return(BadRequest("Model not matching requirements")); } newTask.Id = id; _context.Entry(newTask).State = EntityState.Modified; var taskToUpdate = await _context.Tasks. SingleOrDefaultAsync(x => x.Id == id); if (taskToUpdate == null) { return(NotFound("Task not found")); } _context.Update(taskToUpdate); await _context.SaveChangesAsync(); return(Ok("Task successfully Updated")); }
public async Task <ActionResult> UpdateTask(int id, ToDoTask newToDoTask) { if (!ModelState.IsValid) { return(BadRequest("Model not matching requirements")); } newToDoTask.Id = id; _context.Entry(newToDoTask).State = EntityState.Modified; var taskToUpdate = await _context.ToDoTasks.FindAsync(id); if (taskToUpdate == null) { return(NotFound("Task not found.")); } _context.Update(taskToUpdate); await _context.SaveChangesAsync(); return(Ok("Task updated.")); }