﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace VoIPReseller.Src.ValidationAttributes
{
    public class PostCodeAttribute : CustomValidationAttribute, IClientValidatable
    {
        public override bool IsValid(object value)
        {
            if (value != null)
            {
                var validator = new PostCodeValidator();
                return validator.Validate(value.ToString());
            }
            return true;
        }

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            yield return new ModelClientValidationRule
            {
                ErrorMessage = base.getErrorMessage(),
                ValidationType = "postcode"
            };
        }
    }
}