public async Task <NotificationDefResult> Handle(AddNotificationDefCommand 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 _notificationDefQueryRepository.Search(new SearchNotificationDefParameter
            {
                Name = request.Name
            }, cancellationToken);

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

            var res = NotificationDefinitionAggregate.New(request.Name);
            await _notificationDefCommandRepository.Add(res, cancellationToken);

            await _notificationDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"the notification definition '{request.Name}' has been added");
            return(NotificationDefResult.ToDto(res));
        }
Example #2
0
        public Task <bool> Update(NotificationDefinitionAggregate notificationDefinition, CancellationToken token)
        {
            var r = _notificationDefs.First(_ => _.AggregateId == notificationDefinition.AggregateId);

            _notificationDefs.Remove(r);
            _notificationDefs.Add((NotificationDefinitionAggregate)notificationDefinition.Clone());
            return(Task.FromResult(true));
        }
 private NotificationDefBuilder(string name)
 {
     _notification = new NotificationDefinitionAggregate
     {
         AggregateId = name,
         Name        = name
     };
 }
 public static NotificationDefResult ToDto(NotificationDefinitionAggregate notif)
 {
     return(new NotificationDefResult
     {
         Name = notif.Name,
         OperationParameters = notif.OperationParameters.Select(_ => ParameterResult.ToDto(_)).ToList(),
         PeopleAssignments = notif.PeopleAssignments.Select(_ => PeopleAssignmentDefinitionResult.ToDto(_)).ToList(),
         PresentationElements = notif.PresentationElements.Select(_ => PresentationElementDefinitionResult.ToDto(_)).ToList(),
         PresentationParameters = notif.PresentationParameters.Select(_ => PresentationParameterResult.ToDto(_)).ToList(),
         Priority = notif.Priority,
         Rendering = notif.Rendering
     });
 }
 public static NotificationDefResult ToDto(NotificationDefinitionAggregate notificationDef)
 {
     return(new NotificationDefResult
     {
         CreateDateTime = notificationDef.CreateDateTime,
         Id = notificationDef.AggregateId,
         Name = notificationDef.Name,
         NbInstances = notificationDef.NbInstances,
         Priority = notificationDef.Priority,
         UpdateDateTime = notificationDef.UpdateDateTime,
         Version = notificationDef.Version,
         OperationParameters = notificationDef.OperationParameters.Select(_ => ParameterResult.ToDto(_)).ToList(),
         PeopleAssignments = notificationDef.PeopleAssignments.Select(_ => PeopleAssignmentDefinitionResult.ToDto(_)).ToList(),
         PresentationElements = notificationDef.PresentationElements.Select(_ => PresentationElementDefinitionResult.ToDto(_)).ToList(),
         PresentationParameters = notificationDef.PresentationParameters.Select(_ => PresentationParameterResult.ToDto(_)).ToList()
     });
 }
Example #6
0
 public Task <bool> Add(NotificationDefinitionAggregate notificationDefinition, CancellationToken token)
 {
     _notificationDefs.Add(notificationDefinition);
     return(Task.FromResult(true));
 }
 public Task <bool> Update(NotificationDefinitionAggregate notificationDef, CancellationToken token)
 {
     _dbContext.Entry(notificationDef).State = EntityState.Modified;
     return(Task.FromResult(true));
 }
 public Task <bool> Add(NotificationDefinitionAggregate notificationDef, CancellationToken token)
 {
     _dbContext.NotificationDefinitions.Add(notificationDef);
     return(Task.FromResult(true));
 }