public async Task <bool> Handle(UpdateIdentityResourceCommand 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 not found")); return(false); } var irs = request.Resource.ToEntity(); irs.Id = savedClient.Id; await _identityResourceRepository.UpdateWithChildrens(irs); if (Commit()) { await Bus.RaiseEvent(new IdentityResourceUpdatedEvent(request.Resource)); return(true); } return(false); }
public async Task <bool> Handle(UpdateIdentityResourceCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(false); } var name = request.OldIdentityResourceName != request.IdentityResource.Name ? request.OldIdentityResourceName : request.IdentityResource.Name; var resource = await _identityResourceRepository.FirstOrDefaultAsync(r => r.Name == name); if (resource == null) { await _bus.RaiseEvent(new DomainNotification("key_not_found", $"IdentityResource named {name} could not be found")); return(false); } var vm = request.IdentityResource.ToEntity(); resource.Name = vm.Name; resource.DisplayName = vm.DisplayName; resource.Description = vm.Description; resource.Enabled = vm.Enabled; resource.Emphasize = vm.Emphasize; resource.ShowInDiscoveryDocument = vm.ShowInDiscoveryDocument; resource.Properties = vm.Properties; resource.Required = vm.Required; resource.Updated = DateTime.UtcNow; resource.UserClaims = vm.UserClaims; await _identityResourceRepository.UpdateWithChildrensAsync(resource); if (Commit()) { await _bus.RaiseEvent(new IdentityResourceUpdatedEvent(resource.Id, request.IdentityResource.Name, request.OldIdentityResourceName)); return(true); } return(false); }