Exemplo n.º 1
0
        public DeleteTaskCommandTests()
        {
            _fixture            = new Fixture();
            _taskRepositoryMock = Substitute.For <ITaskRepository>();

            _deleteTaskCommand = new DeleteTaskCommand(_taskRepositoryMock);
        }
Exemplo n.º 2
0
        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 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> 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, "Вы не можете удалить эту задачу!"));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> DeleteTaskAsync(int taskId, [FromServices] IDeleteTaskCommand command)
        {
            try
            {
                await command.ExecuteAsync(taskId);

                return(Ok("Успешно"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        public IActionResult Delete(int id, [FromServices] IDeleteTaskCommand command)
        {
            _executor.ExecuteCommand(command, id);

            return(NoContent());
        }