public async Task <IActionResult> DeleteTaskAsync(int taskId, [FromServices] IDeleteTaskCommand command) { //TODO: think of a way to require confirmation on server side //TODO: check if user is owner of tasks project await command.ExecuteAsync(taskId); return(NoContent()); }
public async Task <IActionResult> DeleteTaskAsync(int taskId, [FromServices] IDeleteTaskCommand command, [FromServices] IGetTaskQuery query) { var task = await query.RunAsync(taskId); if ((await _authorizationService.AuthorizeAsync(User, task, Operations.Delete)).Succeeded) { await command.ExecuteAsync(taskId); return(NoContent()); } return(StatusCode(403, "Вы не можете удалить эту задачу!")); }
public async Task <IActionResult> DeleteTaskAsync(int taskId, [FromServices] IDeleteTaskCommand command) { try { await command.ExecuteAsync(taskId); return(Ok("Успешно")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult> DeleteTask(Guid id, [FromBody] DeleteTaskRequest request, [FromServices] IDeleteTaskCommand command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != request.Id) { return(BadRequest("URL ID and body's ID should be the same")); } if (!request.Confirmed) { return(BadRequest("Confirmation is required")); } var result = await command.ExecuteAsync(request); if (result.TotalItemsCount > 0) { return(Ok(result)); } return(NotFound(result)); }