Пример #1
0
        public virtual async Task <int> UpdateClientAsync(ClientDto client)
        {
            var canInsert = await CanInsertClientAsync(client);

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

            var clientEntity = client.ToEntity();

            return(await ClientRepository.UpdateClientAsync(clientEntity));
        }
        /// <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));
        }
Пример #3
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);
        }
Пример #4
0
        public async Task <ApiResponse> UpdateClientAsync(ClientDto clientDto)
        {
            //ClientId is not the primary key, but a unique index and ClientDto does not contain the real key Id.
            //So in UI I have to use ClientId as a key and I make it read only.
            var client = await _configurationDbContext.Clients.SingleOrDefaultAsync(i => i.ClientId == clientDto.ClientId);

            if (client == null)
            {
                return(new ApiResponse(Status400BadRequest, L["The client {0} doesn't exist", clientDto.ClientId]));
            }

            _configurationDbContext.Clients.Remove(client);

            _configurationDbContext.Clients.Add(clientDto.ToEntity());
            await _configurationDbContext.SaveChangesAsync();

            return(new ApiResponse(Status200OK, L["Client {0} updated", clientDto.ClientId], clientDto));
        }
Пример #5
0
        public virtual async Task <int> UpdateClientAsync(ClientDto client)
        {
            var canInsert = await CanInsertClientAsync(client);

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

            var clientEntity = client.ToEntity();

            var originalClient = await GetClientAsync(client.Id);

            var updated = await ClientRepository.UpdateClientAsync(clientEntity);

            await AuditEventLogger.LogEventAsync(new ClientUpdatedEvent(originalClient, client));

            return(updated);
        }
Пример #6
0
        public async Task <ServiceResponse <int> > CreateAsync(ClientDto client, int userId)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var entity = client.ToEntity();

            entity.UpdateCreatedFields(userId).UpdateModifiedFields(userId);
            entity.Recommendations.UpdateCreatedFields(userId).UpdateModifiedFields(userId);
            entity.Attachments.UpdateCreatedFields(userId).UpdateModifiedFields(userId);

            var added = UnitOfWork.Get <Client>().Add(entity);

            await UnitOfWork.SaveAsync();

            return(new SuccessResponse <int>(added.ID));
        }
Пример #7
0
        public void AddClient(ClientDto clientDto)
        {
            Client client = clientDto.ToEntity();

            if (!CanInsertClient(client))
            {
                throw new Infrastructure.FluentValidation.FluentValidationException("客户端ID重复。");
            }
            var transaction = this.Session.BeginTransaction();

            try
            {
                this.Session.Save(client);

                transaction.Commit();
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }
        }
Пример #8
0
        public virtual Task <bool> CanInsertClientAsync(ClientDto client, bool isCloned = false)
        {
            var clientEntity = client.ToEntity();

            return(ClientRepository.CanInsertClientAsync(clientEntity, isCloned));
        }
        public async Task <int> RemoveClientAsync(ClientDto client)
        {
            var clientEntity = client.ToEntity();

            return(await _clientRepository.RemoveClientAsync(clientEntity));
        }