Example #1
0
        public async Task <ActionResult <ClientDto> > UpdateClientAsync(Guid id, UpdateClientDto clientDto)
        {
            var existingItem = await repository.GetClientAsync(id);

            if (existingItem is null)
            {
                return(NotFound());
            }

            Client updateItem = existingItem with
            {
                Name      = clientDto.Name,
                Telephone = clientDto.Telephone,
                Email     = clientDto.Email,
                IsDeleted = clientDto.IsDeleted,
                Photo     = clientDto.Photo,
                CNP       = clientDto.CNP,
                Adress    = clientDto.Adress,
                Barcode   = clientDto.Barcode,
                Comment   = clientDto.Comment
            };
            await repository.UpdateClientAsync(updateItem);

            return(NoContent());
        }
        public async Task <IActionResult> Update(UpdateClientDto input)
        {
            await _mediatorService.Send(new UpdateClientCommand(input.ClientGuid, input.FirstName, input.LastName,
                                                                input.ContactNumber, input.EmailAddress));

            return(new OkResult());
        }
Example #3
0
        public async Task Should_create_app_with_anonymous_read_access()
        {
            var appName = Guid.NewGuid().ToString();

            // STEP 1: Create app
            var createRequest = new CreateAppDto {
                Name = appName
            };

            var app = await _.Apps.PostAppAsync(createRequest);

            // Should return create app with correct name.
            Assert.Equal(appName, app.Name);


            // STEP 2: Make the client anonymous.
            var clientRequest = new UpdateClientDto {
                AllowAnonymous = true
            };

            await _.Apps.PutClientAsync(appName, "default", clientRequest);


            // STEP 3: Check anonymous permission
            var url = $"{_.ClientManager.Options.Url}api/apps/{appName}/settings";

            using (var httpClient = new HttpClient())
            {
                var response = await httpClient.GetAsync(url);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
Example #4
0
 public AddOrUpdateClient(UpdateClientDto client, bool isUpdate, int id)
 {
     InitializeComponent();
     this.client   = client;
     this.isUpdate = isUpdate;
     this.id       = id;
 }
Example #5
0
        public async Task Should_update_client()
        {
            // STEP 0: Create app.
            await CreateAppAsync();


            // STEP 0: Create client.
            var client = await CreateAsync();


            // STEP 1: Update client name.
            var updateNameRequest = new UpdateClientDto
            {
                Name            = clientName,
                AllowAnonymous  = true,
                ApiCallsLimit   = 100,
                ApiTrafficLimit = 200,
                Role            = "Owner"
            };

            var clients_2 = await _.Apps.PutClientAsync(appName, client.Id, updateNameRequest);

            var client_2 = clients_2.Items.Find(x => x.Id == client.Id);

            // Should update client name.
            Assert.Equal(updateNameRequest.Name, client_2.Name);
            Assert.Equal(updateNameRequest.AllowAnonymous, client_2.AllowAnonymous);
            Assert.Equal(updateNameRequest.ApiCallsLimit, client_2.ApiCallsLimit);
            Assert.Equal(updateNameRequest.ApiTrafficLimit, client_2.ApiTrafficLimit);
            Assert.Equal(updateNameRequest.Role, client_2.Role);
        }
        private async Task SynchronizeClientsAsync(AppModel model, SyncOptions options, ISession session)
        {
            var current = await session.Apps.GetClientsAsync(session.App);

            if (options.Delete)
            {
                foreach (var client in current.Items)
                {
                    var generatedClientId = $"{session.App}:{client.Id}";

                    if (model.Clients.ContainsKey(client.Id) || session.ClientId.Equals(generatedClientId))
                    {
                        continue;
                    }

                    await log.DoSafeAsync($"Client '{client.Id}' deleting", async() =>
                    {
                        await session.Apps.DeleteClientAsync(session.App, client.Id);
                    });
                }
            }

            foreach (var(clientId, _) in model.Clients)
            {
                var existing = current.Items.FirstOrDefault(x => x.Id == clientId);

                if (existing != null)
                {
                    continue;
                }

                await log.DoSafeAsync($"Client '{clientId}' creating", async() =>
                {
                    var request = new CreateClientDto {
                        Id = clientId
                    };

                    current = await session.Apps.PostClientAsync(session.App, request);
                });
            }

            foreach (var(clientId, value) in model.Clients)
            {
                var existing = current.Items.FirstOrDefault(x => x.Id == clientId);

                if (existing == null || value.JsonEquals(existing))
                {
                    continue;
                }

                await log.DoSafeAsync($"Client '{clientId}' updating", async() =>
                {
                    var request = new UpdateClientDto {
                        Role = value.Role
                    };

                    await session.Apps.PutClientAsync(session.App, clientId, request);
                });
            }
        }
        public int Update(UpdateClientDto dto)
        {
            var client = AssertAccessRights(uow.Client.Get(dto.id));

            client.Update(ApplicationUser, dto);
            uow.SaveChanges();
            return(client.id);
        }
Example #8
0
        public async Task <IActionResult> PutClient(string app, string id, [FromBody] UpdateClientDto request)
        {
            var command = request.ToCommand(id);

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
Example #9
0
        public async Task <IActionResult> Put(int id, [FromBody] UpdateClientDto client, CancellationToken cancellationToken)
        {
            var command = new UpdateClientCommand {
                Id = id, Client = client
            };
            await Mediator.Send(command, cancellationToken);

            return(NoContent());
        }
Example #10
0
        private async Task AssignClient(string role = null)
        {
            var updateRequest = new UpdateClientDto
            {
                Role = role
            };

            await _.Apps.PutClientAsync(_.AppName, client, updateRequest);
        }
Example #11
0
        public async Task <IActionResult> UpdateClient(UpdateClientDto client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelStateErrors));
            }
            var result = await _clientAppService.UpdateClient(client);

            return(ResultResponse(result, "修改客户端成功"));
        }
Example #12
0
        public async Task Should_manage_clients()
        {
            var clientId    = Guid.NewGuid().ToString();
            var clientName  = "My Client";
            var clientRole1 = "Editor";
            var clientRole2 = "Owner";

            // STEP 1: Create client.
            var createRequest = new CreateClientDto {
                Id = clientId
            };

            var clients_1 = await _.Apps.PostClientAsync(_.AppName, createRequest);

            var client_1 = clients_1.Items.FirstOrDefault(x => x.Id == clientId);

            // Should return client with correct name and id.
            Assert.Equal(clientRole1, client_1.Role);
            Assert.Equal(clientId, client_1.Name);


            // STEP 2: Update client name.
            var updateNameRequest = new UpdateClientDto {
                Name = clientName
            };

            var clients_2 = await _.Apps.PutClientAsync(_.AppName, clientId, updateNameRequest);

            var client_2 = clients_2.Items.FirstOrDefault(x => x.Id == clientId);

            // Should update client name.
            Assert.Equal(clientName, client_2.Name);


            // STEP 3: Update client role.
            var updateRoleRequest = new UpdateClientDto {
                Role = clientRole2
            };

            var clients_3 = await _.Apps.PutClientAsync(_.AppName, clientId, updateRoleRequest);

            var client_3 = clients_3.Items.FirstOrDefault(x => x.Id == clientId);

            // Should update client role.
            Assert.Equal(clientRole2, client_3.Role);


            // STEP 4: Delete client
            var clients_4 = await _.Apps.DeleteClientAsync(_.AppName, clientId);

            var client_4 = clients_4.Items.FirstOrDefault(x => x.Id == clientId);

            // Should not return deleted client.
            Assert.Null(client_4);
        }
        public async Task <ActionResult> UdpateClient([FromBody] UpdateClientDto clientDto)
        {
            if (!IsAvailableOperation())
            {
                return(BadRequest());
            }

            await _clientService.Update(clientDto);

            AddLog(Enums.LogType.Create, LogMessage.CreateSuccessByIdMessage(LogMessage.ClientEntityName, clientDto.Id, LogMessage.UpdateAction, UserId));
            return(Ok());
        }
        public async Task Update(UpdateClientDto dto)
        {
            var client = _DB.Clients.SingleOrDefault(x => x.Id == dto.Id && !x.IsDelete);

            client.Email       = dto.Email;
            client.Mobile      = dto.Mobile;
            client.CompanyName = dto.CompanyName;
            client.Address     = dto.Address;
            client.CityId      = dto.CityId;
            _DB.Clients.Update(client);
            _DB.SaveChanges();
        }
Example #15
0
 public Client UpdateClientDtoToClient(UpdateClientDto updateClientDto)
 {
     return(new Client
     {
         FirstName = updateClientDto.FirstName,
         LastName = updateClientDto.LastName,
         PhoneNumber = updateClientDto.PhoneNumber,
         Email = updateClientDto.Email,
         DriversLicenseNumber = updateClientDto.DriversLicenseNumber,
         IdNumber = updateClientDto.IdNumber,
         Pesel = updateClientDto.Pesel
     });
 }
Example #16
0
        public async Task <IActionResult> Put([FromBody] UpdateClientDto dto, Guid id)
        {
            var cmd = new UpdateClientCommand {
                ClientId = id, DisplayName = dto.DisplayName, RedirectUri = dto.RedirectUri
            };
            var result = await _sagaBus.InvokeAsync <UpdateClientCommand, MessageResult>(cmd);

            if (result.Succeed)
            {
                return(Created(Url.Action(), null));
            }
            return(BadRequest(result.Message));
        }
Example #17
0
        public static UpdateClientDto GetItems()
        {
            var client = new UpdateClientDto
            {
                FirstName            = LvClientList.SelectedItems[0].SubItems[1].Text,
                LastName             = LvClientList.SelectedItems[0].SubItems[2].Text,
                PhoneNumber          = LvClientList.SelectedItems[0].SubItems[3].Text,
                Email                = LvClientList.SelectedItems[0].SubItems[4].Text,
                IdNumber             = LvClientList.SelectedItems[0].SubItems[5].Text,
                DriversLicenseNumber = LvClientList.SelectedItems[0].SubItems[6].Text,
                Pesel                = LvClientList.SelectedItems[0].SubItems[7].Text,
            };

            return(client);
        }
Example #18
0
        public async Task Put_Failed(
            [Frozen] UpdateClientDto updateClientDto,
            [Frozen] User user,
            [Frozen] Client client)
        {
            //Arrange
            _mapper.Setup(m => m.Map <User>(updateClientDto)).Returns(user);
            _clientService.Setup(c => c.GetClient(_id)).ReturnsAsync(client);
            _clientService.Setup(p => p.PutClient(user, client)).ReturnsAsync(false);

            //Action
            var result = await _clientsController.PutAsync(_id, updateClientDto);

            //Assert
            Assert.True(result is NotFoundResult);
        }
Example #19
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var            provider      = new Dependencies().Load();
            IClientService clientService = provider.GetService <IClientService>();

            if (isUpdate)
            {
                var clientUpdate = new UpdateClientDto {
                    FirstName            = tbxFirstName.Text,
                    LastName             = tbxLastName.Text,
                    PhoneNumber          = tbxPhoneNumber.Text,
                    Email                = tbxEmail.Text,
                    DriversLicenseNumber = tbxDriversLicenseNumber.Text,
                    IdNumber             = tbxIdNumber.Text,
                    Pesel                = tbxPesel.Text
                };
                if (!clientUpdate.Validate())
                {
                    MessageBox.Show("Validation error");
                    return;
                }
                clientService.UpdateClient(id, clientUpdate);

                this.Hide();
            }
            else
            {
                var clientAdd = new AddClientDto
                {
                    FirstName            = tbxFirstName.Text,
                    LastName             = tbxLastName.Text,
                    PhoneNumber          = tbxPhoneNumber.Text,
                    Email                = tbxEmail.Text,
                    DriversLicenseNumber = tbxDriversLicenseNumber.Text,
                    IdNumber             = tbxIdNumber.Text,
                    Pesel                = tbxPesel.Text
                };
                if (!clientAdd.Validate())
                {
                    MessageBox.Show("Validation error");
                    return;
                }
                clientService.AddClient(clientAdd);

                this.Hide();
            }
        }
        public async Task <IActionResult> UpdateClient([FromBody] UpdateClientDto updateClientDto)
        {
            try
            {
                var result = await _clientCashedService.Update(updateClientDto);

                if (result.Errors.Any())
                {
                    return(Conflict());
                }
                return(Ok(result.Data));
            }
            catch (Exception ex)
            {
                _logging.WriteExption(ex);
                return(BadRequest());
            }
        }
Example #21
0
        public async Task <bool> UpdateClient(UpdateClientDto clientDto)
        {
            await IsExists(clientDto.ClientId, clientDto.Id);

            var client = await _clientRepository.GetAll().Include(x => x.AllowedGrantTypes)
                         .Include(x => x.RedirectUris)
                         .Include(x => x.PostLogoutRedirectUris)
                         .Include(x => x.AllowedScopes)
                         .Include(x => x.IdentityProviderRestrictions)
                         .Include(x => x.AllowedCorsOrigins).FirstOrDefaultAsync(c => c.Id == clientDto.Id);

            if (client == null)
            {
                throw new Exception("Client不存在");
            }
            var entity = _mapper.Map <UpdateClientDto, Client>(clientDto, client);

            _clientRepository.Update(entity);
            return(await _clientRepository.SaveChangesAsync() > 0);
        }
Example #22
0
        public async Task Should_create_app_with_anonymous_write_access()
        {
            var appName = Guid.NewGuid().ToString();

            // STEP 1: Create app
            var createRequest = new CreateAppDto {
                Name = appName
            };

            var app = await _.Apps.PostAppAsync(createRequest);

            // Should return create app with correct name.
            Assert.Equal(appName, app.Name);


            // STEP 2: Make the client anonymous.
            var clientRequest = new UpdateClientDto {
                AllowAnonymous = true
            };

            await _.Apps.PutClientAsync(appName, "default", clientRequest);


            // STEP 3: Create schema
            var schemaRequest = new CreateSchemaDto {
                Name = "my-content", IsPublished = true
            };

            await _.Schemas.PostSchemaAsync(appName, schemaRequest);


            // STEP 3: Create a content.
            var url = $"{_.ClientManager.Options.Url}api/content/{appName}/my-content";

            using (var httpClient = new HttpClient())
            {
                var response = await httpClient.PostAsync(url, new StringContent("{}", null, "text/json"));

                Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            }
        }
        public async Task Update(UpdateClientDto clientDto)
        {
            var clientRepository = DataContextManager.CreateRepository <IClientRepository>();

            var client = await clientRepository.GetById(clientDto.Id);

            if (client == null)
            {
                throw new NotFoundException("Client", clientDto.Id);
            }

            var otherClient = await clientRepository.GetByName(clientDto.Name);

            if (otherClient != null && otherClient.Id != clientDto.Id)
            {
                throw new FoundSameObjectException("Client", clientDto.Name);
            }

            client.Name       = clientDto.Name;
            client.UpdateDate = DateTime.UtcNow;

            await clientRepository.Update(client);
        }
Example #24
0
        public async Task <IActionResult> PutAsync(int id, UpdateClientDto dto)
        {
            Client client = await _clientService.GetClient(id);

            if (client == null)
            {
                return(NotFound());
            }
            else
            {
                User user = _mapper.Map <User>(dto);
                var  res  = await _clientService.PutClient(user, client);

                if (res)
                {
                    return(NoContent());
                }
                else
                {
                    return(NotFound());
                }
            }
        }
Example #25
0
        public ClientDto Update(UpdateClientDto toUpdate)
        {
            IList <ValidationResult> ExtendValidation(UpdateClientDto toValidate)
            {
                var resource = this.GetErrorStringLocalizer();
                IList <ValidationResult> result = new List <ValidationResult>();

                if (toValidate.ReturnUrls == null || toValidate.ReturnUrls.Count() == 0)
                {
                    result.Add(new ValidationResult(resource["UpdateClientDtoDefaultReturnUrlRequired"]));
                }

                if (toValidate.ReturnUrls != null)
                {
                    foreach (var ur in toValidate.ReturnUrls)
                    {
                        if (!Uri.TryCreate(ur, UriKind.Absolute, out var u))
                        {
                            result.Add(new ValidationResult(resource["UpdateClientDtoReturnUrlIncorrect"]));
                        }
                    }
                }

                if (toValidate.ClientType != ClientTypeName.Confidential && toValidate.ClientType != ClientTypeName.Public)
                {
                    result.Add(new ValidationResult(resource["UpdateClientDtoTypeIncorrect"]));
                }

                if (!toValidate.ClientSecret.IsMatchClientSecretPolicy())
                {
                    result.Add(new ValidationResult(resource["UpdateClientDtoClientSecretDontMatchPolicy"]));
                }

                return(result);
            }

            Logger.LogInformation(String.Format("Try to update client for user {0}", toUpdate != null ? toUpdate.UserName : String.Empty));

            Validate(toUpdate, ExtendValidation);

            using (var context = RepositoriesFactory.CreateContext())
            {
                var resource = this.GetErrorStringLocalizer();

                var clientRepo          = RepositoriesFactory.GetClientRepository(context);
                var userClientRepo      = RepositoriesFactory.GetUserClientRepository(context);
                var scopeRepo           = RepositoriesFactory.GetScopeRepository(context);
                var userRepo            = RepositoriesFactory.GetUserRepository(context);
                var clientReturnUrlRepo = RepositoriesFactory.GetClientReturnUrlRepository(context);
                var clientScopeRepo     = RepositoriesFactory.GetClientScopeRepository(context);

                var myClient = clientRepo.GetById(toUpdate.Id);

                if (myClient == null || !myClient.IsValid)
                {
                    throw new DaOAuthServiceException(resource["UpdateClientInvalidClient"]);
                }

                var ucs = userClientRepo.GetAllByCriterias(toUpdate.UserName, toUpdate.Name, null, null, 0, 50);
                if (ucs != null && ucs.Count() > 0)
                {
                    var myUc = ucs.First();
                    if (myUc.ClientId != myClient.Id)
                    {
                        throw new DaOAuthServiceException(resource["UpdateClientNameAlreadyUsed"]);
                    }
                }

                var cl = clientRepo.GetByPublicId(toUpdate.PublicId);
                if (cl != null && cl.Id != myClient.Id)
                {
                    throw new DaOAuthServiceException(resource["UpdateClientpublicIdAlreadyUsed"]);
                }

                var scopes = scopeRepo.GetAll();
                if (toUpdate.ScopesIds != null)
                {
                    IList <int> ids = scopes.Select(s => s.Id).ToList();
                    foreach (var scopeId in toUpdate.ScopesIds)
                    {
                        if (!ids.Contains(scopeId))
                        {
                            throw new DaOAuthServiceException(resource["UpdateClientScopeDontExists"]);
                        }
                    }
                }

                var myUser = userRepo.GetByUserName(toUpdate.UserName);

                if (myUser == null || !myUser.IsValid)
                {
                    throw new DaOAuthServiceException(resource["UpdateClientInvalidUser"]);
                }

                var myUserClient = userClientRepo.
                                   GetUserClientByClientPublicIdAndUserName(myClient.PublicId, toUpdate.UserName);

                if (myUserClient == null || !myUserClient.Client.UserCreator.UserName.Equals(toUpdate.UserName, StringComparison.OrdinalIgnoreCase))
                {
                    throw new DaOAuthServiceException(resource["UpdateClientInvalidUser"]);
                }

                // update returns urls
                foreach (var ru in clientReturnUrlRepo.GetAllByClientPublicId(myClient.PublicId).ToList())
                {
                    clientReturnUrlRepo.Delete(ru);
                }

                foreach (var ru in toUpdate.ReturnUrls)
                {
                    clientReturnUrlRepo.Add(new ClientReturnUrl()
                    {
                        ClientId  = myClient.Id,
                        ReturnUrl = ru
                    });
                }

                // updates clients scopes
                foreach (var s in clientScopeRepo.GetAllByClientId(myClient.Id).ToList())
                {
                    clientScopeRepo.Delete(s);
                }
                if (toUpdate.ScopesIds != null)
                {
                    foreach (var s in toUpdate.ScopesIds)
                    {
                        clientScopeRepo.Add(new ClientScope()
                        {
                            ClientId = myClient.Id,
                            ScopeId  = s
                        });
                    }
                }

                // update client
                myClient.ClientSecret = toUpdate.ClientSecret;
                myClient.ClientTypeId = toUpdate.ClientType.Equals(
                    ClientTypeName.Confidential, StringComparison.OrdinalIgnoreCase)
                        ? (int)EClientType.CONFIDENTIAL : (int)EClientType.PUBLIC;
                myClient.Description = toUpdate.Description;
                myClient.Name        = toUpdate.Name;
                myClient.PublicId    = toUpdate.PublicId;

                clientRepo.Update(myClient);

                context.Commit();

                return(myClient.ToDto(true));
            }
        }
 public Task <bool> UpdateClientAsync(UpdateClientDto ClientDto)
 {
     throw new System.NotImplementedException();
 }
Example #27
0
        public async Task Update(int id, UpdateClientDto client)
        {
            var result = await _http.PutAsJsonAsync($"{_api.Url}/clients/{id}", client);

            await result.EnsureSuccess();
        }
Example #28
0
        public async Task <IActionResult> PutClient(string app, string clientId, [FromBody] UpdateClientDto request)
        {
            await CommandBus.PublishAsync(request.ToCommand(clientId));

            return(NoContent());
        }
Example #29
0
        public GetClientDto UpdateClient(int id, UpdateClientDto updateClientDto)
        {
            var updateClient = _clientConverter.UpdateClientDtoToClient(updateClientDto);

            return(_clientConverter.ClientToGetClientDto(_clientRepository.Update(id, updateClient)));
        }
 public IActionResult Update([FromForm] UpdateClientDto dto)
 {
     _clientservice.Update(dto);
     return(Ok(GetRespons()));
 }