public async Task DeactivateCertificateAsync(string thumbprint, User account) { if (string.IsNullOrEmpty(thumbprint)) { throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(thumbprint)); } if (account == null) { throw new ArgumentNullException(nameof(account)); } var certificate = GetCertificate(thumbprint); if (certificate == null) { throw new ArgumentException(Strings.CertificateDoesNotExist, nameof(thumbprint)); } var userCertificate = certificate.UserCertificates.SingleOrDefault(uc => uc.UserKey == account.Key); if (userCertificate != null) { _entitiesContext.DeleteOnCommit(userCertificate); await _entitiesContext.SaveChangesAsync(); await _auditingService.SaveAuditRecordAsync( new CertificateAuditRecord(AuditedCertificateAction.Deactivate, certificate.Thumbprint)); _telemetryService.TrackCertificateDeactivated(thumbprint); } }
public virtual async Task <ActionResult> UndoPendingEdits(string id, string version) { var package = _packageService.FindPackageByIdAndVersion(id, version); if (package == null) { return(HttpNotFound()); } if (!package.IsOwner(User)) { return(new HttpStatusCodeResult(403, "Forbidden")); } // To do as much successful cancellation as possible, Will not batch, but will instead try to cancel // pending edits 1 at a time, starting with oldest first. var pendingEdits = _entitiesContext.Set <PackageEdit>() .Where(pe => pe.PackageKey == package.Key) .OrderBy(pe => pe.Timestamp) .ToList(); int numOK = 0; int numConflicts = 0; foreach (var result in pendingEdits) { try { _entitiesContext.DeleteOnCommit(result); await _entitiesContext.SaveChangesAsync(); numOK += 1; } catch (DataException) { numConflicts += 1; } } if (numConflicts > 0) { TempData["Message"] = "Your pending edit has already been completed and could not be canceled."; } else if (numOK > 0) { TempData["Message"] = "Your pending edits for this package were successfully canceled."; } else { TempData["Message"] = "No pending edits were found for this package. The edits may have already been completed."; } return(Redirect(Url.Package(id, version))); }