示例#1
0
        protected override bool CheckBusinessRules(BusinessRulesValidationMode validationMode)
        {
            // Remove any old error Codes
            ClearErrorCodes();

            ClearErrorCodes();
            if (validationMode == BusinessRulesValidationMode.INSERT
                || validationMode == BusinessRulesValidationMode.UPDATE)
            {
                string filteredHtml = HTML.Replace("<br>", string.Empty);
                if (string.IsNullOrEmpty(filteredHtml))
                {
                    AddErrorCode(new BusinessRulesValidationMessage("HTML",
                        "Description",
                        "You must provide an event description",
                        BusinessRulesValidationCode.REQUIRED_FIELD));
                }
                if (!string.IsNullOrWhiteSpace(ExternalLinkToEvent))
                {
                    if (!ExternalLinkToEvent.StartsWith("http://")
                        && !ExternalLinkToEvent.StartsWith("https://"))
                    {
                        AddErrorCode(new BusinessRulesValidationMessage("ExternalLinkToEvent",
                            "Link to more information",
                            "The link to more information must start with http:// or https://",
                            BusinessRulesValidationCode.FIELD_VALIDATION));
                    }
                }
                SecretCode = SecretCode.ToLower();
                if (!string.IsNullOrEmpty(SecretCode))
                {
                    var allowdups = false;

                    if (SecretCode.Length > 50)
                    {
                        AddErrorCode(new BusinessRulesValidationMessage("Secret Code",
                            "Secret Code",
                            "The Secret Code must be 50 characters or less.",
                            BusinessRulesValidationCode.UNSPECIFIED));
                    }
                    else if (!Regex.IsMatch(SecretCode, @"^[a-z0-9]+$"))
                    {
                        AddErrorCode(new BusinessRulesValidationMessage("Secret Code",
                            "Secret Code",
                            "The Secret Code can only contain letters and numbers.",
                            BusinessRulesValidationCode.UNSPECIFIED));
                    }
                    else if (!allowdups)
                    {
                        int eventsWithCode = 0;
                        switch (validationMode)
                        {
                            case BusinessRulesValidationMode.UPDATE:
                                eventsWithCode = GetEventCountByEventCode(EID, SecretCode);
                                break;
                            case BusinessRulesValidationMode.INSERT:
                                eventsWithCode = GetEventCountByEventCode(SecretCode);
                                break;
                        }
                        if (eventsWithCode != 0)
                        {
                            AddErrorCode(new BusinessRulesValidationMessage("Secret Code",
                                "Secret Code",
                                "The Secret Code you have chosen is already in use.  Please select a different Secret Code.",
                                BusinessRulesValidationCode.UNSPECIFIED));
                        }
                    }
                }
            }

            return (ErrorCodes.Count == 0);
            //return true;
        }