/// <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); }
/// <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(CreateTrigger command) { var domainModel = new Trigger(command.ApplicationId) { Description = command.Description, LastTriggerAction = DtoToDomainConverters.ConvertLastAction(command.LastTriggerAction), Id = command.Id, Name = command.Name, RunForExistingIncidents = command.RunForExistingIncidents, RunForReopenedIncidents = command.RunForReOpenedIncidents, RunForNewIncidents = command.RunForNewIncidents }; foreach (var action in command.Actions) { domainModel.AddAction(DtoToDomainConverters.ConvertAction(action)); } foreach (var rule in command.Rules) { domainModel.AddRule(DtoToDomainConverters.ConvertRule(rule)); } await _repository.CreateAsync(domainModel); }