private OPCProblemDetails _Validate(SurveyPAModel model) { #region Test Data //ValidationProblemDetails valid = new ValidationProblemDetails(); //valid.Detail = "There is errors with the validation, see error list"; //valid.Title = "Validation errors"; //valid.Errors.Add("mykey", new string[] { "value1", "value2" }); //valid.Errors.Add("another mykey", new string[] { "more value1", "stuff" }); //return BadRequest(valid); //throw new Exception("this is a test exception", new Exception("this is the inner exception")); #endregion var validator = new SurveyPAModelValidator(_localizer); var results = validator.Validate(model); if (!results.IsValid) { OPCProblemDetails valid = new OPCProblemDetails(); valid.Detail = "There is errors with the validation, see error list"; valid.Title = "Validation errors"; foreach (var error in results.Errors) { valid.AddError(error.PropertyName, error.ErrorMessage); } return(valid); } return(null); }
private OPCProblemDetails _Validate(SurveyContactInfoModel model) { var validator = new SurveyContactInfoModelValidator(_localizer); var results = validator.Validate(model); if (!results.IsValid) { OPCProblemDetails valid = new OPCProblemDetails(); valid.Detail = "There is errors with the validation, see error list"; valid.Title = "Validation errors"; foreach (var error in results.Errors) { valid.AddError(error.PropertyName, error.ErrorMessage); } return(valid); } return(null); }
public IActionResult Validate([FromBody] SurveyPipedaModel model, [FromQuery] string complaintId) { var validator = new SurveyPipedaModelValidator(_localizer); var results = validator.Validate(model); if (!results.IsValid) { OPCProblemDetails valid = new OPCProblemDetails(); valid.Detail = "There is errors with the validation, see error list"; valid.Title = "Validation errors"; foreach (var error in results.Errors) { //valid.Errors.Add(error., new string[] { "more value1", "stuff" }); valid.AddError(error.PropertyName, error.ErrorMessage); } return(BadRequest(valid)); } return(Ok()); }
public IActionResult ValidateAttachments([FromBody] PAFilePageData files, [FromQuery] string complaintId) { //throw new Exception("this is a test exception", new Exception("this is the inner exception")); //ValidationProblemDetails valid = new ValidationProblemDetails(); //valid.Detail = "There is errors with the validation, see error list"; //valid.Title = "Validation errors"; //valid.Errors.Add("mykey", new string[] { "value1", "value2" }); //valid.Errors.Add("another mykey", new string[] { "more value1", "stuff" }); //return BadRequest(valid); if (files.Documentation_type == "upload" || files.Documentation_type == "both") { List <SurveyFile> allFiles = new List <SurveyFile>(); if (files.Documentation_file_upload != null) { allFiles.AddRange(files.Documentation_file_upload); } if (files.Documentation_file_upload_rep != null) { allFiles.AddRange(files.Documentation_file_upload_rep); } if (allFiles.Count > 0) { long totalSizes = 0; long multipleFileMaxSize = 26214400; var folderName = Path.Combine("FileUploads", complaintId); var folderpath = Path.Combine(Directory.GetCurrentDirectory(), folderName); if (!Directory.Exists(folderpath)) { Directory.CreateDirectory(folderpath); } DirectoryInfo directory = new DirectoryInfo(folderpath); FileInfo[] filesStored = directory.GetFiles(); // We need to make sure the list of files sent to us saved in local storage (in other words the files the users think he is // uploading) are all saved on the server properly with the right size OPCProblemDetails fileMissingProblem = new OPCProblemDetails { Status = 400, Detail = _localizer.GetLocalizedStringSharedResource("FileNotFound"), Title = _localizer.GetLocalizedStringSharedResource("ValidationIssues") }; foreach (SurveyFile file in allFiles) { long.TryParse(file.content, out long fileSize); if (fileSize == 0 || filesStored.Where(f => f.Name == file.name && f.Length == fileSize).Any() == false) { fileMissingProblem.AddError(_localizer.GetLocalizedStringSharedResource("FileNotFound"), string.Format(_localizer.GetLocalizedStringSharedResource("FileMissing"), file.name)); } else { // We are adding to the total file size that we will process later totalSizes += fileSize; } } if (fileMissingProblem.Errors.Count > 0) { return(BadRequest(fileMissingProblem)); } // Next step is to validate for total file size. if (totalSizes > multipleFileMaxSize) { OPCProblemDetails problem = new OPCProblemDetails { Detail = _localizer.GetLocalizedStringSharedResource("SizeOfFilesExceeded"), Status = 400, Title = _localizer.GetLocalizedStringSharedResource("ValidationIssues") }; problem.Errors.Add(_localizer.GetLocalizedStringSharedResource("Attachments"), new List <string>() { _localizer.GetLocalizedStringSharedResource("SizeOfFilesExceeded") }); return(BadRequest(problem)); } } else { OPCProblemDetails problem = new OPCProblemDetails { Detail = "There is no files uploaded", Status = 400, Title = _localizer.GetLocalizedStringSharedResource("ValidationIssues") }; return(BadRequest(problem)); } } return(Ok()); }