34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using Back.Services;
|
|
using FluentValidation;
|
|
using Shared.DTOs;
|
|
using System;
|
|
|
|
namespace Back.Validations
|
|
{
|
|
public class MobileValidation : AbstractValidator<Tuple<string,bool>>
|
|
{
|
|
public MobileValidation(servCompany servCompany)
|
|
{
|
|
CascadeMode = CascadeMode.Stop;
|
|
RuleFor(m => m.Item1)
|
|
.NotEmpty().WithMessage("موبایل نمی تواند باشد")
|
|
.NotNull().WithMessage("موبایل نمی تواند باشد")
|
|
.Length(11).WithMessage("فرمت موبایل صحیح نمی باشد")
|
|
.Must(m => m.StartsWith("09")).WithMessage("فرمت موبایل صحیح نمی باشد");
|
|
RuleFor(m => m)
|
|
.Custom((model, context) => {
|
|
if (model.Item2)
|
|
{
|
|
if (!servCompany.ExistMobileAndCompanyIsActive(model.Item1).Result)
|
|
{
|
|
context.AddFailure("این موبایل یافت نشد");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
});
|
|
}
|
|
}
|
|
}
|