NuGetGallery.ApiController.SubmitPackageValidationResults C# (CSharp) Method

SubmitPackageValidationResults() private method

private SubmitPackageValidationResults ( string apiKey, string id, string version, bool success, string validationComments ) : System.Web.Mvc.ActionResult
apiKey string
id string
version string
success bool
validationComments string
return System.Web.Mvc.ActionResult
        public virtual ActionResult SubmitPackageValidationResults(string apiKey, string id, string version, bool success, string validationComments)
        {
            Guid parsedApiKey;
            if (!Guid.TryParse(apiKey, out parsedApiKey)) return new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, string.Format(CultureInfo.CurrentCulture, Strings.InvalidApiKey, apiKey));

            var testReporterUser = userSvc.FindByApiKey(parsedApiKey);
            if (testReporterUser == null) return new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, String.Format(CultureInfo.CurrentCulture, Strings.ApiKeyNotAuthorized, "submitvalidationresults"));
            // Only the package operations user can submit test results
            if (testReporterUser.Key != settings.PackageOperationsUserKey) return new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, String.Format(CultureInfo.CurrentCulture, Strings.ApiKeyNotAuthorized, "submitvalidationresults"));

            if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(version))
            {
                return new HttpStatusCodeWithBodyResult(HttpStatusCode.NotFound, string.Format(CultureInfo.CurrentCulture, Strings.PackageWithIdAndVersionNotFound, id, version));
            }

            if (string.IsNullOrWhiteSpace(validationComments))
            {
                return new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, "Submitting validation results requires 'validationComments' and 'success'.");
            }

            var package = packageSvc.FindPackageByIdAndVersion(id, version, allowPrerelease: true, useCache: false);
            if (package == null) return new HttpStatusCodeWithBodyResult(HttpStatusCode.NotFound, string.Format(CultureInfo.CurrentCulture, Strings.PackageWithIdAndVersionNotFound, id, version));

            package.PackageValidationResultDate = DateTime.UtcNow;
            package.PackageValidationResultStatus = PackageAutomatedReviewResultStatusType.Failing;

            var message = "{0} has failed automated validation.".format_with(package.PackageRegistration.Id);
            if (success)
            {
                package.PackageValidationResultStatus = PackageAutomatedReviewResultStatusType.Passing;
                message = "{0} has passed automated validation. It may have or may still fail other checks like testing (verification).".format_with(package.PackageRegistration.Id);
            }

            message += "{0}{1}".format_with(Environment.NewLine, validationComments);

            packageSvc.UpdateSubmittedStatusAfterAutomatedReviews(package);

            packageSvc.ChangePackageStatus(package, package.Status, package.ReviewComments, message, testReporterUser, testReporterUser, sendMaintainerEmail: true, submittedStatus: success ? package.SubmittedStatus : PackageSubmittedStatusType.Waiting, assignReviewer: false);

            return new HttpStatusCodeWithBodyResult(HttpStatusCode.Accepted, "Package validation results have been updated.");
        }