public async Task <IActionResult> Edit(int id, [Bind("Id,Name,DeadlineDate,Description")] Todo.Model.Models.Task task) { if (id != task.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(task); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { if (!Utils.TaskExists(task.Id, _context)) { //RH: //return Conflict(); //return NotFound(); return(Conflict(new { message = $"Record '{id}' was not found." })); } else { throw ex; //RH: Pocyztaj o różnicy między throw a throw ex } } return(RedirectToAction(nameof(Index))); } return(View(task)); }
public async Task <IActionResult> Create([Bind("Id,Name,DeadlineDate,Description")] Todo.Model.Models.Task task) { if (ModelState.IsValid) { _context.Add(task); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); //RG: Duży plus za nameof! } return(View(task)); }
public void Put(int id, [FromBody] Todo.Model.Models.Task task) { var taskToUpdate = _context.Task.FirstOrDefault(x => x.Id == id); if (taskToUpdate != null) { taskToUpdate.Name = task.Name; taskToUpdate.Description = task.Description; taskToUpdate.DeadlineDate = task.DeadlineDate; _context.SaveChanges(); //RH: jw. } }
public void Post([FromBody] Todo.Model.Models.Task task) { _context.Task.Add(task); _context.SaveChanges(); //RH: To jest nigdzie nie awaitowany Async, w razie problemów nie złapiesz wyjątków w żaden sposób }