Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public async Task <Unit> Handle(DeleteJobTaskCommand request, CancellationToken cancellationToken)
        {
            var jobTask = await _repo.GetById(request.Id);

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

            return(Unit.Value);
        }
Exemplo n.º 3
0
        public async Task <bool> IsAssigned(string username, int taskId)
        {
            var jobTask = await jobTaskRepository.GetById(taskId);

            if (jobTask == null)
            {
                return(false);
            }

            return(jobTask.AssignedUsers
                   .Any(user => user.UserName.Equals(username)));
        }
Exemplo n.º 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);
        }