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); }
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); }
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))); }
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); }