コード例 #1
0
        public async Task <bool> Handle(UpdateJobTaskRequest message, IOutputPort <UpdateJobTaskResponse> outputPort)
        {
            var taskEntity = await taskRepository.GetById(message.TaskId);

            if (taskEntity == null)
            {
                outputPort.Handle(new UpdateJobTaskResponse(new[]
                                                            { applicationErrorFactory.ResourceNotFound }));
                return(false);
            }

            bool isOwner = await jobOwnerShipValidator.IsJobOwner(message.CallerId, taskEntity.JobEntityId);

            if (!isOwner)
            {
                outputPort.Handle(new UpdateJobTaskResponse(new[]
                                                            { applicationErrorFactory.ResourceNotOwned }));
                return(false);
            }

            mapper.Map(message, taskEntity);
            await taskRepository.Update(taskEntity);

            outputPort.Handle(new UpdateJobTaskResponse());
            return(true);
        }
コード例 #2
0
        public async Task <bool> Handle(UnAssignJobTaskRequest message, IOutputPort <UnAssignJobTaskResponse> outputPort)
        {
            var taskEntity = await jobTaskRepository.GetSingleBySpec(new GetJobTaskSpecification(message.TaskId));

            if (taskEntity == null)
            {
                outputPort.Handle(new UnAssignJobTaskResponse(new[]
                                                              { applicationErrorFactory.ResourceNotFound }));
                return(false);
            }

            bool isOwner = await jobOwnerShipValidator.IsJobOwner(message.CallerId, taskEntity.JobEntityId);

            if (!isOwner)
            {
                outputPort.Handle(new UnAssignJobTaskResponse(new[]
                                                              { applicationErrorFactory.ResourceNotOwned }));
                return(false);
            }

            taskEntity.UnAssignUser(message.AssignUsername);
            await jobTaskRepository.Update(taskEntity);

            outputPort.Handle(new UnAssignJobTaskResponse());
            return(true);
        }
コード例 #3
0
        public async Task <bool> Handle(FinishJobTaskRequest message, IOutputPort <FinishJobTaskResponse> outputPort)
        {
            var taskEntity = await jobTaskRepository
                             .GetSingleBySpec(new GetJobTaskSpecification(message.TaskId));

            bool isAssigned = await taskAssignedValidator.IsAssigned(message.CallerId, message.TaskId);

            if (taskEntity == null)
            {
                outputPort.Handle(new FinishJobTaskResponse(new[]
                                                            { applicationErrorFactory.ResourceNotFound }));
                return(false);
            }

            if (!isAssigned)
            {
                outputPort.Handle(new FinishJobTaskResponse(new[]
                                                            { applicationErrorFactory.ChangeNotAllowed }));
                return(false);
            }

            taskEntity.Finished = true;
            await jobTaskRepository.Update(taskEntity);

            outputPort.Handle(new FinishJobTaskResponse());
            return(true);
        }
コード例 #4
0
        public async Task <Unit> Handle(EditJobTaskCommand request, CancellationToken cancellationToken)
        {
            var jobTask = await _repo.GetById(request.Id);

            if (jobTask is null)
            {
                throw new NotFoundException(nameof(JobTask), request.Id);
            }

            jobTask.Description = request.Description;
            jobTask.TaskPeriod  = new DateTimeRange(request.Start, request.End);

            await _repo.Update(jobTask);

            return(Unit.Value);
        }