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);
        }
示例#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);
        }