protected override ValidationResult IsValid(object value, ValidationContext validationContext) { bool isValid = false; if (value is string) { var id = (value as string) ?? ""; isValid = LegalCase.IsValidCaseId(id); } else if (value is List <string> ) { var caseList = value as List <string>; // empty lists are considered valid isValid = true; caseList.ForEach(c => isValid = isValid && LegalCase.IsValidCaseId(c)); } if (!isValid) { return(new ValidationResult("Invalid CaseId detected.")); } return(ValidationResult.Success); }
public async Task <IActionResult> PutLegalCase(long folderId, string caseId) { if (!LegalCase.IsValidCaseId(caseId) || !FolderExists(folderId)) { return(NotFound()); } var legalCase = new LegalCase { FolderId = folderId, CaseId = Int64.Parse(caseId) }; _context.Cases.Add(legalCase); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> DeleteLegalCase(long folderId, string caseId) { if (!LegalCase.IsValidCaseId(caseId)) { return(NotFound()); } var legalCase = await _context.Cases.FirstOrDefaultAsync(c => c.FolderId == folderId && c.CaseId == Int64.Parse(caseId)); if (legalCase == null) { return(NotFound()); } _context.Cases.Remove(legalCase); await _context.SaveChangesAsync(); return(NoContent()); }