Example #1
0
        public async Task <bool> Handle(RegisterIdentityResourceCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var savedClient = await _identityResourceRepository.GetByName(request.Resource.Name);

            if (savedClient != null)
            {
                await Bus.RaiseEvent(new DomainNotification("1", "Resource already exists"));

                return(false);
            }

            var irs = request.Resource.ToEntity();

            _identityResourceRepository.Add(irs);

            if (Commit())
            {
                await Bus.RaiseEvent(new IdentityResourceRegisteredEvent(irs.Name));

                return(true);
            }
            return(false);
        }