ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Validators/Customer/SubAccountValidator.cs
using FluentValidation;
using Grand.Domain.Customers;
using Grand.Core.Validators;
using Grand.Services.Localization;
using Grand.Web.Models.Customer;
using System.Collections.Generic;

namespace Grand.Web.Validators.Customer
{
    public class SubAccountValidator : BaseGrandValidator<SubAccountModel>
    {
        public SubAccountValidator(
            IEnumerable<IValidatorConsumer<SubAccountModel>> validators,
            ILocalizationService localizationService,
            CustomerSettings customerSettings)
            : base(validators)
        {
            RuleFor(x => x.Email).NotEmpty().WithMessage(localizationService.GetResource("Account.Fields.Email.Required"));
            RuleFor(x => x.Email).EmailAddress().WithMessage(localizationService.GetResource("Common.WrongEmail"));

            RuleFor(x => x.FirstName).NotEmpty().WithMessage(localizationService.GetResource("Account.Fields.FirstName.Required"));
            RuleFor(x => x.LastName).NotEmpty().WithMessage(localizationService.GetResource("Account.Fields.LastName.Required"));

            RuleFor(x => x.Password).NotEmpty().WithMessage(localizationService.GetResource("Account.Fields.Password.Required")).When(subaccount => string.IsNullOrEmpty(subaccount.Id));
            RuleFor(x => x.Password).Length(customerSettings.PasswordMinLength, 999).WithMessage(string.Format(localizationService.GetResource("Account.Fields.Password.LengthValidation"), customerSettings.PasswordMinLength))
                .When(subaccount => string.IsNullOrEmpty(subaccount.Id));
        }
    }
}