コード例 #1
0
        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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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());
        }