public async Task <IActionResult> GetTaskAsync([FromRoute] string taskId, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (!Guid.TryParse(taskId, out var modeltaskId)) { return(this.NotFound()); } Models.Tasks.MyTask modelTask = null; try { modelTask = await this.tasks.GetAsync(modeltaskId, cancellationToken); } catch (Models.Tasks.TaskNotFoundException) { return(this.NotFound()); } if (!UserHaveTaskAccess(modelTask)) { return(Forbid()); } var clientTask = TaskConverter.Convert(modelTask); return(this.Ok(clientTask)); }
public async Task <IActionResult> RemoveTaskAsync([FromRoute] string taskId, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (!Guid.TryParse(taskId, out var taskGuid)) { return(NotFound()); } Models.Tasks.MyTask task = null; try { task = await this.tasks.GetAsync(taskGuid, cancellationToken); } catch (Models.Tasks.TaskNotFoundException) { return(this.NotFound()); } if (!UserHaveTaskAccess(task)) { return(Forbid()); } try { await tasks.RemoveAsync(taskGuid, cancellationToken); } catch (Models.Tasks.TaskNotFoundException) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> PatchTaskAsync([FromRoute] string taskId, ClientModels.Tasks.TaskPatchInfo clientPatchInfo, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (clientPatchInfo == null) { return(BadRequest()); } if (!Guid.TryParse(taskId, out var taskGuid)) { return(NotFound()); } Models.Tasks.MyTask task = null; try { task = await this.tasks.GetAsync(taskGuid, cancellationToken); } catch (Models.Tasks.TaskNotFoundException) { return(this.NotFound()); } if (!UserHaveTaskAccess(task)) { return(Forbid()); } var modelPatchInfo = TaskPatchConverter.Convert(taskGuid, clientPatchInfo); MyTask patchTask = null; try { patchTask = await tasks.PatchAsync(modelPatchInfo, cancellationToken); } catch (Models.Tasks.TaskNotFoundException) { return(NotFound()); } return(Ok(patchTask)); }