public async Task <TaskAggregate> GetTaskAsync(string taskId)
        {
            var task = await _tasksRepository.GetTaskAsync(taskId);

            if (task == null)
            {
                throw new NotFoundException($"Task with id {taskId} not found");
            }
            return(task);
        }
        private async Task HandleListPreparedAsync(TransactionBase transaction, BaseTransactionMessage message, TransactionsRepository repository,
                                                   TasksRepository tasksRepository)
        {
            var listPreparedMessage = message as MoveTaskListPreparedMessage;

            if (transaction == null)
            {
                Console.WriteLine($"Transaction for prepared list {listPreparedMessage.ListId} not found");
                return;
            }

            var moveTaskTransaction = MoveTaskTransaction.CreateFromBase(transaction);

            string newListId = listPreparedMessage.ListId;

            moveTaskTransaction.ListId         = newListId;
            moveTaskTransaction.IsListPrepared = true;
            moveTaskTransaction.UpdateData();

            string taskId = moveTaskTransaction.ObjectId;

            IEnumerable <string> taskMembersIds = await tasksRepository.GetTaskMembersIdsAsync(taskId);

            OutboxMessageModel nextMessage = default(OutboxMessageModel);

            if (!taskMembersIds.IsNullOrEmpty())
            {
                var task = await tasksRepository.GetTaskAsync(taskId);

                moveTaskTransaction.Message = "Move members to project";

                nextMessage = OutboxMessageModel.Create(
                    new MoveTaskMoveMembersMessage()
                {
                    TransactionId   = transaction.Id,
                    TargetProjectId = moveTaskTransaction.ProjectId,
                    SourceProjectId = task.ProjectId,
                    TaskMembers     = taskMembersIds
                }, Topics.Tasks, TransactionMessageActions.MoveTask_MoveMembersRequested);
            }
            else
            {
                moveTaskTransaction.AreMembersPrepared = true;
                moveTaskTransaction.Message            = "Handle task hours with new project";

                nextMessage = OutboxMessageModel.Create(
                    new MoveTaskHandleHoursMessage()
                {
                    TransactionId = transaction.Id,
                    ProjectId     = moveTaskTransaction.ProjectId,
                    TaskId        = taskId
                }, Topics.Tasks, TransactionMessageActions.MoveTask_HandleHoursRequested);
            }

            await repository.CreateOrUpdateTransactionAsync(moveTaskTransaction, nextMessage);
        }
        public async Task <(TaskAggregate task, bool fromCache)> GetTaskAsync(string taskId)
        {
            string cacheKey   = string.Format(CacheSettings.TaskIdCacheKeyPattern, taskId);
            var    cachedTask = await _cache.TryGetCachedValueAsync <TaskAggregate>(cacheKey);

            if (cachedTask != null)
            {
                return(cachedTask, true);
            }

            var task = await _tasksRepository.GetTaskAsync(taskId);

            if (task == null)
            {
                throw new NotFoundException($"Task with id {taskId} not found");
            }

            await _cache.SetCacheValueAsync(cacheKey, task, CacheSettings.TaskIdCacheLifetime);

            return(task, false);
        }