public async Task <HumanTaskDefResult> Handle(AddHumanTaskDefCommand request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(request.Name))
            {
                _logger.LogError("the parameter 'name' is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "name"));
            }

            var result = await _humanTaskDefQueryRepository.Search(new SearchHumanTaskDefParameter
            {
                Name = request.Name
            }, cancellationToken);

            if (result != null && result.Content.Count() > 0)
            {
                _logger.LogError($"the human task '{request.Name}' already exists");
                throw new BadRequestException(string.Format(Global.HumanTaskDefExists, request.Name));
            }

            var res = HumanTaskDefinitionAggregate.New(request.Name);
            await _humanTaskDefCommandRepository.Add(res, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"the human task definition '{request.Name}' has been added");
            return(HumanTaskDefResult.ToDto(res));
        }
        public async Task<bool> Handle(UpdateHumanTaskDefInfoCommand request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(request.Name))
            {
                _logger.LogError("the parameter 'name' is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "name"));
            }

            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);
            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            var r = await _humanTaskDefQueryRepository.Search(new SearchHumanTaskDefParameter
            {
                Name = request.Name
            }, cancellationToken);
            r.Content = r.Content.Where(_ => _.AggregateId != request.Id).ToList();
            if (r != null && r.Content.Count() > 0)
            {
                _logger.LogError($"the human task '{request.Name}' already exists");
                throw new BadRequestException(string.Format(Global.HumanTaskDefExists, request.Name));
            }

            result.UpdateInfo(request.Name, request.Priority);
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);
            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);
            _logger.LogInformation($"Human task definition '{result.Name}', information has been updated");
            return true;
        }
Example #3
0
        public async Task <SearchResult <HumanTaskDefResult> > Handle(SearchHumanTaskDefQuery request, CancellationToken cancellationToken)
        {
            var result = await _humanTaskDefQueryRepository.Search(new SearchHumanTaskDefParameter
            {
                Count      = request.Count,
                Order      = request.Order,
                OrderBy    = request.OrderBy,
                StartIndex = request.StartIndex
            }, cancellationToken);

            return(new SearchResult <HumanTaskDefResult>
            {
                Count = result.Count,
                StartIndex = result.StartIndex,
                TotalLength = result.TotalLength,
                Content = result.Content.Select(_ => HumanTaskDefResult.ToDto(_))
            });
        }