コード例 #1
0
        public FormDataValidationResult Validate()
        {
            var result = new FormDataValidationResult();


            if (Title.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Title is required");
            }
            if (Description.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Description is required");
            }
            if (Constraints.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Constraints is required");
            }
            if (InputSpecification.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("InputSpecification is required");
            }
            if (OutputSpecification.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("OutputSpecification is required");
            }
            if (SampleInput.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("SampleInput is required");
            }
            if (SampleOutput.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("SampleOutput is required");
            }
            if (Notes.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Notes is required");
            }
            if (TimeLimit == 0 || TimeLimit > 20)
            {
                result.AddErrorMessage("TimeLimit is invalid");
            }
            if (MemoryLimit == 0 || MemoryLimit > 512)
            {
                result.AddErrorMessage("MemoryLimit is invalid");
            }
            if (string.IsNullOrEmpty(TestCaseInput))
            {
                result.AddErrorMessage("TestCaseInput is required");
            }
            if (string.IsNullOrEmpty(TestCaseOutput))
            {
                result.AddErrorMessage("TestCaseOutput is required");
            }

            return(result);
        }
コード例 #2
0
        public FormDataValidationResult Validate()
        {
            var result = new FormDataValidationResult();

            if (Title.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Title is required");
            }

            if (Description.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Description is required");
            }

            if (!IsPublic)
            {
                if (Password.IsNullOrWhiteSpace())
                {
                    result.AddErrorMessage("Password is required");
                }

                if (ConfirmPassword.IsNullOrWhiteSpace())
                {
                    result.AddErrorMessage("Confirm password is required");
                }
                else if (ConfirmPassword != Password)
                {
                    result.AddErrorMessage("Passwords do not match");
                }
            }

            if (StartDate < DateTime.Now)
            {
                result.AddErrorMessage("Invalid Start date");
            }

            if (StartDate >= EndDate)
            {
                result.AddErrorMessage("Invalid start and end date");
            }

            if (Problems.ToList().Count == 0)
            {
                result.AddErrorMessage("1 or more problems must be added");
            }

            // todo check problem uniqueness

            return(result);
        }
コード例 #3
0
        public FormDataValidationResult Validate()
        {
            FormDataValidationResult result = new FormDataValidationResult();

            if (Title == null || Title.IsEmpty())
            {
                result.AddErrorMessage("Title is required");
            }

            if (Description == null || Description.IsEmpty())
            {
                result.AddErrorMessage("Description is required");
            }

            return(result);
        }
コード例 #4
0
        public FormDataValidationResult Validate()
        {
            var context = new OjDBContext();
            FormDataValidationResult result = new FormDataValidationResult();

            if (UserName.IsEmpty())
            {
                result.AddErrorMessage("UserName Required");
            }
            else if (UserName.Length < 4)
            {
                result.AddErrorMessage("UserName is too short");
            }
            else if (context.Users.FirstOrDefault(x => x.UserName == UserName) != null)
            {
                result.AddErrorMessage("UserName is already taken");
            }

            if (Email.IsEmpty())
            {
                result.AddErrorMessage("Email is Required");
            }
            else if (!(Email.Contains("@") && Email.Contains(".")))
            {
                result.AddErrorMessage("Email is invalid");
            }

            if (Password.IsEmpty())
            {
                result.AddErrorMessage("Password must is required");
            }
            else if (Password.Length < 8)
            {
                result.AddErrorMessage("Password must be atleast 8 characters long");
            }
            if (Password != ConfirmPassword)
            {
                result.AddErrorMessage("Passwords do not match");
            }

            return(result);
        }