private void PrepareClientTypeForNewClient(SaveClientCommand command) { switch (command.ClientType) { case ClientType.Empty: break; case ClientType.WebImplicit: command.Client.AllowedGrantTypes = GrantTypes.Implicit; command.Client.AllowAccessTokensViaBrowser = true; break; case ClientType.WebHybrid: command.Client.AllowedGrantTypes = GrantTypes.Hybrid; break; case ClientType.Spa: command.Client.AllowedGrantTypes = GrantTypes.Implicit; command.Client.AllowAccessTokensViaBrowser = true; break; case ClientType.Native: command.Client.AllowedGrantTypes = GrantTypes.Hybrid; break; case ClientType.Machine: command.Client.AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials; break; default: throw new ArgumentOutOfRangeException(); } }
public async Task <bool> Handle(SaveClientCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(false); } var savedClient = await _clientRepository.GetByClientId(request.Client.ClientId); if (savedClient != null) { await Bus.RaiseEvent(new DomainNotification("Client", "Client already exists")); return(false); } var client = request.ToEntity(); _clientRepository.Add(client); if (await Commit()) { await Bus.RaiseEvent(new NewClientEvent(request.Client.ClientId, request.ClientType, request.Client.ClientName)); return(true); } return(false); }
public async Task Handle(SaveClientCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return; } var savedClient = await _clientRepository.GetByClientId(request.Client.ClientId); if (savedClient != null) { await Bus.RaiseEvent(new DomainNotification("1", "Client already exists")); return; } PrepareClientTypeForNewClient(request); var client = request.Client.ToEntity(); client.Description = request.Description; _clientRepository.Add(client); if (Commit()) { await Bus.RaiseEvent(new NewClientEvent(request.Client.ClientId, request.ClientType, request.Client.ClientName)); } }