public async Task <DeleteAssignmentByIdResponse> Handle(DeleteAssignmentByIdRequest request, CancellationToken cancellationToken)
        {
            if (request.AuthenticatorRole == AppRole.Employee)
            {
                return(new DeleteAssignmentByIdResponse()
                {
                    Error = new ErrorModel(ErrorType.Unauthorized)
                });
            }

            var query = new GetAssignmentQuery()
            {
                Id = request.AssignmentId
            };
            var assignment = await queryExecutor.Execute(query);

            if (assignment == null)
            {
                return(new DeleteAssignmentByIdResponse()
                {
                    Error = new ErrorModel(ErrorType.NotFound)
                });
            }

            var command = new DeleteAssignmentCommand()
            {
                Parameter = assignment
            };
            var deletedAssignment = await commandExecutor.Execute(command);

            return(new DeleteAssignmentByIdResponse
            {
                Data = deletedAssignment
            });
        }
Example #2
0
        public async Task <ActionResult> Delete(Guid id)
        {
            try {
                var command = new DeleteAssignmentCommand {
                    Id = id
                };
                await _commandHandler.HandleAsync(command);

                return(NoContent());
            } catch (Exception) {
                return(BadRequest());
            }
        }
Example #3
0
        public async Task HandleAsync(DeleteAssignmentCommand command)
        {
            var assignment = await _repository.GetById(command.Id);

            if (assignment == null)
            {
                throw new EntityNotFoundException($"Assignment with ID '{command.Id}' Not Found.");
            }

            await _repository.Remove(assignment);

            await _commandStoreService.PushAsync(command);
        }