예제 #1
0
        public GetTaskQueryTests()
        {
            _fixture            = new Fixture();
            _taskRepositoryMock = Substitute.For <ITaskRepository>();

            _getTaskQuery = new GetTaskQuery(_taskRepositoryMock);
        }
 public TodoController(ICreateTaskCommand createTaskCommand, IUpdateTaskCommand updateTaskCommand,
                       IDeleteTaskCommand deleteTaskCommand, IGetTaskQuery getTaskQuery, IGetTaskListQuery getTaskListQuery)
 {
     _createTaskCommand = createTaskCommand;
     _updateTaskCommand = updateTaskCommand;
     _deleteTaskCommand = deleteTaskCommand;
     _getTaskQuery      = getTaskQuery;
     _getTaskListQuery  = getTaskListQuery;
 }
        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, "Вы не можете изменить эту задачу!"));
        }
        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, "Вы не можете удалить эту задачу!"));
        }
예제 #5
0
 public IActionResult Get([FromQuery] SearchTaskDTO dto, [FromServices] IGetTaskQuery query)
 {
     return(Ok(_executor.ExecuteQuery(query, dto)));
 }