public async Task <ActionResult> Update([Required] int id, string?title, string?description) { if (string.IsNullOrWhiteSpace(title) && description == null) { return(BadRequest("You have to provide title or desciption!")); } var taskToUpdate = await _taskDatabase.FindOrDefault(id); if (taskToUpdate == null) { return(NotFound("Task with this id doesn't exists!")); } if (!string.IsNullOrWhiteSpace(title)) { taskToUpdate.Title = title; } if (description != null) { taskToUpdate.Description = description; } await _taskDatabase.AddOrUpdate(taskToUpdate); return(NoContent()); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } await _taskContext.AddOrUpdate(Task); return(Redirect("./Details?id=" + Task.Id)); }