protected override ValidationResult IsValid(
            object value, ValidationContext validationContext)
        {
            // Get the email value to validate
            string email = Convert.ToString(value);

            // Casting the validation context to the "Staff" model class
            Staff staff = (Staff)validationContext.ObjectInstance;

            // Get the Staff Id from the staff instance
            int staffId = staff.StaffId;

            return(staffContext.IsEmailExist(email, staffId)
                ? new ValidationResult("Email address already exists!")
                : ValidationResult.Success);
        }
示例#2
0
        protected override ValidationResult IsValid(
            object value, ValidationContext validationContext)
        {
            string email   = Convert.ToString(value);
            Staff  staff   = (Staff)validationContext.ObjectInstance;
            int    staffId = staff.StaffID;

            if (staffContext.IsEmailExist(email, staffId))
            {
                return(new ValidationResult
                           ("Email address already exists!"));
            }
            else
            {
                // validation passed
                return(ValidationResult.Success);
            }
        }