public async Task <IActionResult> AddClient([FromBody] NewClientDto newClient)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (await _clientRepository.IsDuplicateClientAsync(newClient))
                {
                    ModelState.AddModelError("client", "Client already exists");
                    return(BadRequest(ModelState));
                }

                var clientId = await _clientRepository.AddClientAsync(newClient);

                if (clientId > 0)
                {
                    return(Ok(clientId));
                }

                return(StatusCode(500, "An error ocurred in server"));
            }
            catch (Exception e)
            {
                _logger.LogCritical($"POST {Route} - {e.GetType().Name} - {e.Message} - {e.StackTrace}");
                return(StatusCode(500, "An error ocurred in server"));
            }
        }
Exemple #2
0
        /// <summary>
        /// Add new client, this method doesn't save client secrets, client claims, client properties
        /// </summary>
        /// <param name="client"></param>
        /// <returns>This method return new client id</returns>
        public virtual async Task <int> AddClientAsync(ClientDto client)
        {
            var canInsert = await CanInsertClientAsync(client);

            if (!canInsert)
            {
                throw new UserFriendlyViewException(string.Format(ClientServiceResources.ClientExistsValue().Description, client.ClientId), ClientServiceResources.ClientExistsKey().Description, client);
            }

            PrepareClientTypeForNewClient(client);
            var clientEntity = client.ToEntity();

            try
            {
                var added = await ClientRepository.AddClientAsync(clientEntity);

                if (client.EncryptionKey?.Length > 0)
                {
                    var encryptionKey = await EncryptionKeyRepository.AddEncryptionKeyAsync(new EncryptionKey { ClientId = clientEntity.Id, EncryptionSecret = client.EncryptionKey, Enable = true });
                }
                await AuditEventLogger.LogEventAsync(new ClientAddedEvent(client));

                return(added);
            }
            catch
            {
                throw;
            }
        }
Exemple #3
0
        public async Task <CreateClientPayload> CreateClientAsync(
            CreateClientInput input,
            [Service] IClientRepository repository,
            [Service] IIdSerializer idSerializer,
            [DataLoader] SchemaByIdDataLoader dataLoader,
            CancellationToken cancellationToken)
        {
            IdValue deserializedId = idSerializer.Deserialize(input.SchemaId);

            if (!deserializedId.TypeName.Equals(nameof(Schema), StringComparison.Ordinal))
            {
                throw new GraphQLException("The specified id type is invalid.");
            }

            Schema schema = await dataLoader.LoadAsync(
                (Guid)deserializedId.Value, cancellationToken)
                            .ConfigureAwait(false);

            var client = new Client(schema.Id, input.Name, input.Description);

            await repository.AddClientAsync(
                client, cancellationToken)
            .ConfigureAwait(false);

            return(new CreateClientPayload(schema, client, input.ClientMutationId));
        }
Exemple #4
0
        public async Task <IActionResult> AddClient([FromBody] ClientToBeAdded clientToAdd)
        {
            var createClient = _mapper.Map <Client>(clientToAdd);

            var result = await _clientRepo.AddClientAsync(createClient);

            if (result != null)
            {
                return(CreatedAtRoute("getclient", new { controller = "client", clientId = result.Id }, result));
            }

            return(BadRequest(new ApiResponse(400, "Something went wrong while adding the client")));
        }
        /// <summary>
        /// Add new client, this method doesn't save client secrets, client claims, client properties
        /// </summary>
        /// <param name="client"></param>
        /// <returns>This method return new client id</returns>
        public async Task <int> AddClientAsync(ClientDto client)
        {
            var canInsert = await CanInsertClientAsync(client);

            if (!canInsert)
            {
                throw new UserFriendlyViewException(string.Format(_clientServiceResources.ClientExistsValue().Description, client.ClientId), _clientServiceResources.ClientExistsKey().Description, client);
            }

            PrepareClientTypeForNewClient(client);
            var clientEntity = client.ToEntity();

            return(await _clientRepository.AddClientAsync(clientEntity));
        }
Exemple #6
0
        public async Task <ClientResponse> SaveClientAsync(Client client)
        {
            try
            {
                await _clientRepository.AddClientAsync(client);

                await _unitOfWork.CompleteAsync();

                return(new ClientResponse(client));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ClientResponse($"An error has occurred while saving the client: {e.Message}"));
            }
        }
Exemple #7
0
        /// <summary>
        /// Add new client, this method doesn't save client secrets, client claims, client properties
        /// </summary>
        /// <param name="client"></param>
        /// <returns>This method return new client id</returns>
        public virtual async Task <int> AddClientAsync(ClientDto client)
        {
            var canInsert = await CanInsertClientAsync(client);

            if (!canInsert)
            {
                throw new UserFriendlyViewException(string.Format(ClientServiceResources.ClientExistsValue().Description, client.ClientId), ClientServiceResources.ClientExistsKey().Description, client);
            }

            PrepareClientTypeForNewClient(client);
            var clientEntity = client.ToEntity();

            var added = await ClientRepository.AddClientAsync(clientEntity);

            await AuditEventLogger.LogEventAsync(new ClientAddedEvent(client));

            return(added);
        }
Exemple #8
0
        public async Task <ActionResult <Client> > PostClient(ClientDto client)
        {
            if (ModelState.IsValid)
            {
                Client newClient = mapper.Map <Client>(client);
                var    clientId  = await clientRepository.AddClientAsync(newClient);

                if (clientId > 0)
                {
                    return(Ok(clientId));
                }
                else
                {
                    return(NotFound());
                }
            }
            return(BadRequest());
        }
Exemple #9
0
 public async Task <IActionResult> AddClientAsync([FromBody, Required] ClientDto clientDto)
 {
     return(Created(nameof(User), await _repo.AddClientAsync(clientDto)));
 }
Exemple #10
0
 Task <ClientModel> IClientUsecase.AddClientAsync(ClientModel client)
 {
     client.SetStatus(true);
     return(_clientRepository.AddClientAsync(client));
 }
Exemple #11
0
        public async Task <bool> AddClientAsync(Client client)
        {
            var results = await _repo.AddClientAsync(client);

            return(results > 0);
        }
        public async Task AddClient(Client client)
        {
            await _repository.AddClientAsync(client.ToEntity());

            await _repository.SaveAllChangesAsync();
        }