public async Task <ActionResult> PostAsync(JsonValidatorRequestModel request) { if (request == null) { return(this.View("Index", this.GetModel(null, null, isEditView: true).SetUploadError("The request seems to be invalid."))); } // normalize schema name string schemaName = this.NormalizeSchemaName(request.SchemaName); // get raw text string input = request.Content; if (string.IsNullOrWhiteSpace(input)) { return(this.View("Index", this.GetModel(null, schemaName, isEditView: true).SetUploadError("The JSON file seems to be empty."))); } // upload file UploadResult result = await this.Storage.SaveAsync(input); if (!result.Succeeded) { return(this.View("Index", this.GetModel(result.ID, schemaName, isEditView: true).SetContent(input, null).SetUploadError(result.UploadError))); } // redirect to view return(this.Redirect(this.Url.PlainAction("Index", "JsonValidator", new { schemaName = schemaName, id = result.ID }))); }
public async Task <ActionResult> PostAsync(JsonValidatorRequestModel request) { if (request == null) { return(this.View("Index", new JsonValidatorModel(this.SectionUrl, null, null, this.SchemaFormats).SetUploadError("The request seems to be invalid."))); } // normalize schema name string schemaName = this.NormalizeSchemaName(request.SchemaName); // get raw log text string input = request.Content; if (string.IsNullOrWhiteSpace(input)) { return(this.View("Index", new JsonValidatorModel(this.SectionUrl, null, schemaName, this.SchemaFormats).SetUploadError("The JSON file seems to be empty."))); } // upload log input = this.GzipHelper.CompressString(input); SavePasteResult result = await this.Pastebin.PostAsync($"JSON validator {DateTime.UtcNow:s}", input); // handle errors if (!result.Success) { return(this.View("Index", new JsonValidatorModel(this.SectionUrl, result.ID, schemaName, this.SchemaFormats).SetUploadError($"Pastebin error: {result.Error ?? "unknown error"}"))); } // redirect to view UriBuilder uri = new UriBuilder(new Uri(this.SectionUrl)); uri.Path = $"{uri.Path.TrimEnd('/')}/{schemaName}/{result.ID}"; return(this.Redirect(uri.Uri.ToString())); }