Example #1
0
        /// <summary>
        ///     Execute a command asynchronously.
        /// </summary>
        /// <param name="command">Command to execute.</param>
        /// <returns>
        ///     Task which will be completed once the command has been executed.
        /// </returns>
        public async Task ExecuteAsync(UpdateTrigger command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            var domainEntity = await _triggerRepository.GetAsync(command.Id);

            domainEntity.Description       = command.Description;
            domainEntity.LastTriggerAction = DtoToDomainConverters.ConvertLastAction(command.LastTriggerAction);
            domainEntity.Name = command.Name;
            domainEntity.RunForExistingIncidents = command.RunForExistingIncidents;
            domainEntity.RunForReopenedIncidents = command.RunForReOpenedIncidents;
            domainEntity.RunForNewIncidents      = command.RunForNewIncidents;

            domainEntity.RemoveActions();
            foreach (var action in command.Actions)
            {
                domainEntity.AddAction(DtoToDomainConverters.ConvertAction(action));
            }

            domainEntity.RemoveRules();
            foreach (var rule in command.Rules)
            {
                domainEntity.AddRule(DtoToDomainConverters.ConvertRule(rule));
            }

            await _triggerRepository.UpdateAsync(domainEntity);
        }
Example #2
0
        /// <summary>
        ///     Method used to execute the query
        /// </summary>
        /// <param name="query">Query to execute.</param>
        /// <returns>
        ///     Task which will contain the result once completed.
        /// </returns>
        public async Task <GetTriggerDTO> HandleAsync(IMessageContext context, GetTrigger query)
        {
            var trigger = await _repository.GetAsync(query.Id);

            return(new GetTriggerDTO
            {
                ApplicationId = trigger.ApplicationId,
                Actions = trigger.Actions.Select(DomainToDtoConverters.ConvertAction).ToArray(),
                Description = trigger.Description,
                LastTriggerAction = DomainToDtoConverters.ConvertLastAction(trigger.LastTriggerAction),
                Id = trigger.Id,
                Name = trigger.Name,
                Rules = trigger.Rules.Select(DomainToDtoConverters.ConvertRule).ToArray(),
                RunForExistingIncidents = trigger.RunForExistingIncidents,
                RunForReOpenedIncidents = trigger.RunForReopenedIncidents,
                RunForNewIncidents = trigger.RunForNewIncidents
            });
        }