Exemplo n.º 1
0
        public async Task <IActionResult> UpdateTaskAsync(int taskId, [FromBody] UpdateTaskRequest request, [FromServices] IUpdateTaskCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                TaskResponse response = await command.ExecuteAsync(request, taskId);

                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> UpdateTaskAsync(int taskId, [FromBody] UpdateTaskRequest request, [FromServices] IUpdateTaskCommand command, [FromServices] IGetTaskQuery query)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var task = await query.RunAsync(taskId);

            if ((await _authorizationService.AuthorizeAsync(User, task, Operations.Update)).Succeeded)
            {
                TaskResponse response = await command.ExecuteAsync(taskId, request);

                return(response == null
                    ? (IActionResult)NotFound("Task Not Found")
                    : Ok(response));
            }
            return(StatusCode(403, "Вы не можете изменить эту задачу!"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdateTask(Guid id, [FromBody] UpdateTaskRequest request, [FromServices] IUpdateTaskCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != request.Id)
            {
                return(BadRequest("URL ID and body's ID should be the same"));
            }

            var result = await command.ExecuteAsync(request);

            if (result != null)
            {
                return(Ok(result));
            }

            return(NotFound());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> UpdateTaskAsync(int taskId, [FromBody] UpdateTaskRequest request, [FromServices] IUpdateTaskCommand command)
        {
            var response = await command.ExecuteAsync(taskId, request);

            return(response == null ? (IActionResult)NotFound() : Ok(response));
        }