Example #1
0
        public UpdateTaskCommandTests()
        {
            _fixture            = new Fixture();
            _taskRepositoryMock = Substitute.For <ITaskRepository>();

            _updateTaskCommand = new UpdateTaskCommand(_taskRepositoryMock);
        }
Example #2
0
        public IActionResult Put(int id, [FromBody] TaskDTO dto, [FromServices] IUpdateTaskCommand command)
        {
            dto.Id = id;

            _executor.ExecuteCommand(command, dto);

            return(NoContent());
        }
 public TodoController(ICreateTaskCommand createTaskCommand, IUpdateTaskCommand updateTaskCommand,
                       IDeleteTaskCommand deleteTaskCommand, IGetTaskQuery getTaskQuery, IGetTaskListQuery getTaskListQuery)
 {
     _createTaskCommand = createTaskCommand;
     _updateTaskCommand = updateTaskCommand;
     _deleteTaskCommand = deleteTaskCommand;
     _getTaskQuery      = getTaskQuery;
     _getTaskListQuery  = getTaskListQuery;
 }
Example #4
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));
            }
        }
Example #5
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());
        }
        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, "Вы не можете изменить эту задачу!"));
        }
Example #7
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));
        }