示例#1
0
        ///<inheritdoc/>
        public override async Task <UserDto> AddAsync(UserDto dto, CancellationToken cancellationToken = default)
        {
            IList <Scope> scopes = new List <Scope>();

            foreach (ScopeDto item in dto.Scopes)
            {
                Scope scope = await _scopeDomain.GetByKeyAsync(item.Id, cancellationToken);

                if (scope == null)
                {
                    dto.AddNotification("Scopes", string.Format(_localizer["SCOPE_ID_NOT_FOUND"], item.Id));
                }
                else
                {
                    scopes.Add(scope);
                }
            }

            if (dto.Notifications.Count > 0)
            {
                return(dto);
            }

            dto.Scopes = scopes.Select(s => s.Map(false)).ToList();

            UserDto result = await base.AddAsync(dto, cancellationToken);

            if (result.Valid)
            {
                UserCreatedEvent message = new(result.Id, result.Name.FirstName, result.Name.LastName, result.Email, result.BornDate, result.Type.Value, result.IsActive);
                await _bus.Publish(message, cancellationToken);
            }
            return(result);
        }
示例#2
0
 ///<inheritdoc/>
 protected override void ValidateEntity(Role entity)
 {
     base.ValidateEntity(entity);
     if (entity.Valid)
     {
         if (_scopeDomain.GetByKeyAsync(entity.Scope.Id).GetAwaiter().GetResult() == null)
         {
             entity.AddNotification("Scope", _localizer["SCOPE_NOT_FOUND"]);
         }
     }
 }