예제 #1
0
        protected override bool Validate(IValidationTarget <Identifier> target)
        {
            if (string.IsNullOrWhiteSpace(target.Value.Value))
            {
                return(target.Error("Invalid identifer"));
            }

            if (target.Value.Trim() != target.Value)
            {
                return(target.Error("Invalid identifier"));
            }

            if (target.Value.Trim('-') != target.Value)
            {
                return(target.Error("Invalid identifier"));
            }

            if (target.Value.Length > 100)
            {
                return(target.Error("Identifier is too long"));
            }

            if (!target.Value.Value.All(c => c == '-' || char.IsLower(c) || char.IsDigit(c)))
            {
                return(target.Error("Invalid identifier"));
            }

            return(true);
        }
        protected override bool Validate(IValidationTarget <EmailAddress> target)
        {
            if (string.IsNullOrWhiteSpace(target.Value.Value))
            {
                return(target.Error("Invalid email address"));
            }

            if (target.Value.Trim() != target.Value)
            {
                return(target.Error("Invalid email address"));
            }

            if (target.Value.Length > 50)
            {
                return(target.Error("Email address is too long"));
            }

            try
            {
                if (new MailAddress(target.Value.Value).Address != target.Value.Value)
                {
                    return(target.Error("Invalid email address"));
                }

                return(true);
            }
            catch (FormatException)
            {
                return(target.Error("Invalid email address"));
            }
        }
예제 #3
0
        protected override bool Validate(IValidationTarget <Email> target)
        {
            if ((target.Value.IsSent == false) != (target.Value.Sent == null))
            {
                return(target.Error("Sent and IsSent do not match"));
            }

            if (!target.Value.Recipients.Any())
            {
                return(target.Error("No recipients"));
            }

            return(true);
        }
예제 #4
0
        protected override bool Validate(IValidationTarget <World> target)
        {
            Debug.Assert(target.Value.Account != null, "Validation or navigation failure");

            if (target.Value.Account.Type == AccountType.Research && target.Value.Privacy != WorldPrivacy.InviteOnly)
            {
                return(target.Error("Invalid world privacy"));
            }

            if (worlds.Find(target.Value.Identifier, out var same) && same != target.Value)
            {
                return(target.Error("Duplicate identifier"));
            }

            return(true);
        }
예제 #5
0
        protected override bool Validate(IValidationTarget <WorldPrivacy> target)
        {
            if (target.Value == WorldPrivacy.ERROR)
            {
                return(target.Error("Invalid pair outcome"));
            }

            return(true);
        }
예제 #6
0
        protected override bool Validate(IValidationTarget <AccountType> target)
        {
            if (target.Value == AccountType.ERROR)
            {
                return(target.Error("Invalid account type"));
            }

            return(true);
        }
예제 #7
0
        protected override bool Validate(IValidationTarget <T> target)
        {
            if (EqualityComparer <T> .Default.Equals(target.Value, default(T)))
            {
                return(target.Error("Object is null"));
            }

            return(true);
        }
예제 #8
0
        protected override bool Validate(IValidationTarget <PairOutcome> target)
        {
            if (target.Value == PairOutcome.ERROR)
            {
                return(target.Error("Invalid pair outcome"));
            }

            return(true);
        }
        protected override bool Validate(IValidationTarget <AccountStatus> target)
        {
            if (target.Value == AccountStatus.ERROR)
            {
                return(target.Error("Invalid account status"));
            }

            return(true);
        }
예제 #10
0
        protected override bool Validate(IValidationTarget <Account> target)
        {
            if (accounts.Find(target.Value.Email, out var same) && same != target.Value)
            {
                return(target.Error("An account already exists with that email"));
            }

            return(true);
        }
예제 #11
0
        protected override bool Validate(IValidationTarget <Pair> target)
        {
            entries.Entry(target.Value)
            .LoadRelations(p => p.World)
            .LoadRelations(p => p.Pairing.World);

            if (target.Value.World != target.Value.Pairing.World)
            {
                return(target.Error("World and Pairing.World mismatch"));
            }

            return(true);
        }
예제 #12
0
        protected override bool Validate(IValidationTarget <Member> target)
        {
            entries.Entry(target.Value)
            .LoadRelations(m => m.World);

            var members = worlds.Members(target.Value.World);

            if (members.Find(target.Value.Email, out var same) && same != target.Value)
            {
                return(target.Error("An account already exists with that email"));
            }

            return(true);
        }
예제 #13
0
        protected override bool Validate(IValidationTarget <Name> target)
        {
            if (string.IsNullOrWhiteSpace(target.Value.Value))
            {
                return(target.Error("Invalid name"));
            }

            if (target.Value.Trim() != target.Value)
            {
                return(target.Error("Invalid name"));
            }

            if (target.Value.Length > 100)
            {
                return(target.Error("Name is too long"));
            }

            if (target.Value.Value.Any(c => char.IsWhiteSpace(c) && c != ' '))
            {
                return(target.Error("Invalid characters in name"));
            }

            return(true);
        }