Пример #1
0
        public async Task <IActionResult> PutRule(string app, Guid id, [FromBody] UpdateRuleDto request)
        {
            var command = request.ToCommand(id);

            await CommandBus.PublishAsync(command);

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutRule(string app, DomainId id, [FromBody] UpdateRuleDto request)
        {
            var command = request.ToCommand(id);

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
Пример #3
0
 public UpdateRule Convert(Guid tenantId, Guid id, UpdateRuleDto updateRuleDto)
 {
     return(new UpdateRule
     {
         DateEnd = updateRuleDto.DateEnd,
         Id = id,
         Priority = updateRuleDto.Priority,
         TenantId = tenantId
     });
 }
Пример #4
0
        public static UpdateRule ToCommand(this UpdateRuleDto dto, Guid id)
        {
            var command = new UpdateRule {
                RuleId = id
            };

            if (dto.Action != null)
            {
                command.Action = dto.Action.ToAction();
            }

            if (dto.Trigger != null)
            {
                command.Trigger = dto.Trigger.ToTrigger();
            }

            return(command);
        }
Пример #5
0
        public async Task <RuleResultDto> Update(Guid tenantId, Guid id, UpdateRuleDto updateRuleDto)
        {
            RuleKey ruleKey = RuleKey.New(tenantId, id);
            Rule    rule    = await this.ruleRepository.GetById(ruleKey);

            if (rule == null)
            {
                throw new NotFoundException(FormattableString.Invariant($"{nameof(Rule)} was not found. TenantId = {tenantId} | Id = {id}"));
            }

            UpdateRule updateRule = this.updateRuleConversionProfile.Convert(tenantId, id, updateRuleDto);

            RuleResult ruleResult = await this.updateRuleService.UpdateRule(updateRule);

            return(new RuleResultDto
            {
                AffectedRule = ruleResult.AffectedRule != null?this.ConvertToDto(ruleResult.AffectedRule) : null,
                                   ErrorMessages = ruleResult.ErrorMessages.Select(m => new { m.Code, m.Message })
            });
        }
Пример #6
0
        public async Task <IActionResult> Update([FromRoute] Guid tenantId, [FromRoute] Guid id, [FromBody] UpdateRuleDto updateRuleDto)
        {
            try
            {
                RuleResultDto ruleResultDto = await this.ruleService.Update(tenantId, id, updateRuleDto);

                if (ruleResultDto.AffectedRule != null)
                {
                    return(this.Ok(ruleResultDto.AffectedRule));
                }

                return(this.BadRequest(ruleResultDto.ErrorMessages));
            }
            catch (NotFoundException)
            {
                return(this.NotFound("A rule w/ the given tenant id and id was not found"));
            }
        }