﻿using System.ComponentModel.DataAnnotations;

namespace WebSite.Code.Attributes
{
    public class LocalizedStringLengthAttribute : StringLengthAttribute
    {
        public LocalizedStringLengthAttribute(int minumunLength, int maximunLength, string resourceId)
            : base(maximunLength)
        {
            base.MinimumLength = minumunLength;
            base.ErrorMessage = string.Format(GetMessageFromResource(resourceId), minumunLength, maximunLength);
        }

        private static string GetMessageFromResource(string resourceId)
        {
            return AppResources.Texts.ResourceManager.GetString(resourceId);
        }
    }
}