public ActionResult Add(ClientCertificate newCertificate, ClientCertificateInputModel file) { if (String.IsNullOrEmpty(newCertificate.Thumbprint) && file != null && file.Cert != null) { newCertificate.Thumbprint = file.Cert.Thumbprint; if (newCertificate.Thumbprint != null) { ModelState["newCertificate.Thumbprint"].Errors.Clear(); ModelState["newCertificate.Thumbprint"].Value = new ValueProviderResult(newCertificate.Thumbprint, newCertificate.Thumbprint, ModelState["newCertificate.Thumbprint"].Value.Culture); } } if (ModelState.IsValid) { try { this.clientCertificatesRepository.Add(newCertificate); TempData["Message"] = Resources.ClientCertificateController.CertificateAdded; return RedirectToAction("Configure", new { id = newCertificate.UserName }); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); } catch { ModelState.AddModelError("", Resources.ClientCertificateController.ErrorAddingClientCertificate); } } var vm = new ClientCertificatesForUserViewModel(this.clientCertificatesRepository, this.userManagementRepository, newCertificate.UserName); vm.NewCertificate = newCertificate; return View("Configure", vm); }
public ClientCertificatesForUserViewModel(IClientCertificatesRepository clientCertificatesRepository, IUserManagementRepository userManagementRepository, string username) { this.clientCertificatesRepository = clientCertificatesRepository; this.userManagementRepository = userManagementRepository; int totalCount; var allnames = userManagementRepository.GetUsers(0, 100, out totalCount) .Select(x => new SelectListItem { Text = x }).ToList(); allnames.Insert(0, new SelectListItem { Text = Resources.ClientCertificatesForUserViewModel.ChooseItem, Value = "" }); this.AllUserNames = allnames; this.UserName = username; NewCertificate = new ClientCertificate { UserName = username }; if (!IsNew) { var certs = this.clientCertificatesRepository .GetClientCertificatesForUser(this.UserName) .ToArray(); this.Certificates = certs; } else { this.Certificates = new ClientCertificate[0]; } }
public void Delete(ClientCertificate certificate) { using (var entities = IdentityServerConfigurationContext.Get()) { var record = (from entry in entities.ClientCertificates where entry.UserName.Equals(certificate.UserName, StringComparison.OrdinalIgnoreCase) && entry.Thumbprint.Equals(certificate.Thumbprint, StringComparison.OrdinalIgnoreCase) select entry) .SingleOrDefault(); if (record != null) { entities.ClientCertificates.Remove(record); entities.SaveChanges(); } } }
public void Add(ClientCertificate certificate) { using (var entities = IdentityServerConfigurationContext.Get()) { var record = (from entry in entities.ClientCertificates where entry.UserName.Equals(certificate.UserName, StringComparison.OrdinalIgnoreCase) && entry.Thumbprint.Equals(certificate.Thumbprint, StringComparison.OrdinalIgnoreCase) select entry) .SingleOrDefault(); if (record == null) { record = new ClientCertificates { UserName = certificate.UserName, Thumbprint = certificate.Thumbprint }; entities.ClientCertificates.Add(record); } record.Description = certificate.Description; entities.SaveChanges(); } }
public ActionResult Remove(ClientCertificate model) { if (ModelState.IsValid) { try { this.clientCertificatesRepository.Delete(model); TempData["Message"] = Resources.ClientCertificateController.CertificateRemoved; return RedirectToAction("Configure", new { id = model.UserName }); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); } catch { ModelState.AddModelError("", Resources.ClientCertificateController.ErrorRemovingClientCertificate); } } var vm = new ClientCertificatesForUserViewModel(this.clientCertificatesRepository, this.userManagementRepository, model.UserName); return View("Configure", vm); }