public async Task <IActionResult> Edit(EditRemoteClientViewModel model) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageRemoteClients)) { return(Unauthorized()); } var remoteClient = await _service.GetRemoteClientAsync(model.Id); if (remoteClient == null) { return(NotFound()); } if (ModelState.IsValid) { ValidateViewModel(model); } if (ModelState.IsValid) { await _service.TryUpdateRemoteClient(model.Id, model.ClientName, model.ApiKey); _notifier.Success(H["Remote client updated successfully"]); return(RedirectToAction(nameof(Index))); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Create() { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageRemoteClients)) { return(Unauthorized()); } var model = new EditRemoteClientViewModel(); return(View(model)); }
private void ValidateViewModel(EditRemoteClientViewModel model) { if (String.IsNullOrWhiteSpace(model.ClientName)) { ModelState.AddModelError(nameof(EditRemoteClientViewModel.ClientName), S["The client name is mandatory."]); } if (String.IsNullOrWhiteSpace(model.ApiKey)) { ModelState.AddModelError(nameof(EditRemoteClientViewModel.ApiKey), S["The api key is mandatory."]); } }
public async Task <IActionResult> Edit(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageRemoteClients)) { return(Unauthorized()); } var remoteClient = await _service.GetRemoteClientAsync(id); if (remoteClient == null) { return(NotFound()); } var model = new EditRemoteClientViewModel { Id = remoteClient.Id, ClientName = remoteClient.ClientName, ApiKey = remoteClient.ApiKey, }; return(View(model)); }
public async Task <IActionResult> Create(EditRemoteClientViewModel model) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageRemoteClients)) { return(Forbid()); } if (ModelState.IsValid) { ValidateViewModel(model); } if (ModelState.IsValid) { await _service.CreateRemoteClientAsync(model.ClientName, model.ApiKey); _notifier.Success(H["Remote client created successfully"]); return(RedirectToAction(nameof(Index))); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Edit(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageRemoteClients)) { return(Forbid()); } var remoteClient = await _service.GetRemoteClientAsync(id); if (remoteClient == null) { return(NotFound()); } var model = new EditRemoteClientViewModel { Id = remoteClient.Id, ClientName = remoteClient.ClientName, ApiKey = Encoding.UTF8.GetString(_dataProtector.Unprotect(remoteClient.ProtectedApiKey)), }; return(View(model)); }