Esempio n. 1
0
        private async Task <UpdateResult> UpdateClientAction(string id, UpdateClientBindingModel model)
        {
            var updateBuilder     = Builders <Domain.Entity.Client> .Update;
            var updateBuilderList = new List <UpdateDefinition <Domain.Entity.Client> >();

            if (!string.IsNullOrEmpty(model.ApplicationType))
            {
                updateBuilderList.Add(updateBuilder.Set(x => x.ApplicationType, GetApplicationTypeEnum(model.ApplicationType)));
            }

            if (model.Active != null)
            {
                updateBuilderList.Add(updateBuilder.Set(x => x.Active, model.Active));
            }

            if (model.RefreshTokenLifeTime != null)
            {
                updateBuilderList.Add(updateBuilder.Set(x => x.RefreshTokenLifeTime, model.RefreshTokenLifeTime));
            }

            if (!string.IsNullOrEmpty(model.UserId))
            {
                updateBuilderList.Add(updateBuilder.Set(x => x.UserId, model.UserId));
            }

            if (!string.IsNullOrEmpty(model.Secret))
            {
                updateBuilderList.Add(updateBuilder.Set(x => x.Secret, GetHash(model.Secret)));
            }

            var update = updateBuilder.Combine(updateBuilderList);

            return(await Context.GetClientCollection().UpdateOneAsync(x => x.Id.Equals(id), update));
        }
Esempio n. 2
0
        public async Task <ICommonDto> UpdateClient(string id, UpdateClientBindingModel clientModel)
        {
            await ClientExists(id);

            if (!string.IsNullOrEmpty(clientModel.ApplicationType) && clientModel.ApplicationType.ToUpper().Equals("JAVA SCRIPT"))
            {
                if (string.IsNullOrEmpty(clientModel.AllowedOrigin) || clientModel.AllowedOrigin.Equals("*"))
                {
                    CustomException.ThrowBadRequestException("Provide AllowedOrigin for cors support");
                }

                if (string.IsNullOrEmpty(clientModel.Secret))
                {
                    clientModel.Secret = GenerateClientSecret();
                }
            }
            else
            {
                clientModel.AllowedOrigin = "*";
                clientModel.Secret        = null;
            }

            var updateResult = await UpdateClientAction(id, clientModel);

            if (!updateResult.IsAcknowledged)
            {
                CustomException.ThrowBadRequestException("Client update failed.");
            }

            var updatedClient = await Context.GetClientCollection().Find(x => x.Id.Equals(id)).SingleAsync();

            var updatedClientDto = (UpdatedClientDto)_clientFactory.GetModel <UpdatedClientDto>(updatedClient);

            updatedClientDto.Secret = clientModel.Secret;
            return(updatedClientDto);
        }
Esempio n. 3
0
 public async Task <IHttpActionResult> UpdateClient(string id, UpdateClientBindingModel clientModel)
 => Ok(await _clientService.UpdateClient(id, clientModel));