cus end
This commit is contained in:
97
Back/Validations/AddOrCustomerValidation.cs
Normal file
97
Back/Validations/AddOrCustomerValidation.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Back.Common;
|
||||
using Back.Services;
|
||||
using FluentValidation;
|
||||
using Shared.DTOs;
|
||||
|
||||
namespace Back.Validations
|
||||
{
|
||||
public class AddOrCustomerValidation : AbstractValidator<Tuple<int, RCustomer, eActionValidation>>
|
||||
{
|
||||
public AddOrCustomerValidation(CheckPermission _checkPermission, servCustomer servCustomer)
|
||||
{
|
||||
CascadeMode = CascadeMode.Stop;
|
||||
When(r => r.Item3 == eActionValidation.add, () =>
|
||||
{
|
||||
RuleFor(r => r.Item1)
|
||||
.Custom((CompanyID, context) =>
|
||||
{
|
||||
if (!_checkPermission.AllowAddCustomerInCompany(CompanyID).Result)
|
||||
context.AddFailure("اضافه کردن مشتری محدود شده است");
|
||||
});
|
||||
});
|
||||
|
||||
When(r => r.Item3 == eActionValidation.update, () =>
|
||||
{
|
||||
RuleFor(r => r)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
var companyid = model.Item1;
|
||||
if (!model.Item2.ID.HasValue || model.Item2.ID <= 0)
|
||||
context.AddFailure("شناسه مشتری نمی تواند خالی باشذ");
|
||||
else
|
||||
{
|
||||
var customerid = model.Item2.ID.Value;
|
||||
if (!servCustomer.ExistCustomerByCustomerID(customerid, companyid).Result)
|
||||
context.AddFailure("مشتری با این شناسه یافت نشد");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
RuleFor(r => r.Item2.FullName)
|
||||
.NotNull().WithMessage("نام نمی تواند خالی باشذ")
|
||||
.NotEmpty().WithMessage("نام نمی تواند خالی باشذ")
|
||||
.MinimumLength(5).WithMessage("حداقل کارکتر مجار نام 5 می باشد");
|
||||
|
||||
RuleFor(r => r.Item2.Phone)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model) && model.Length <8)
|
||||
context.AddFailure("حداقل کارکتر مجار تلفن 8 می باشد");
|
||||
});
|
||||
|
||||
RuleFor(r => r.Item2.Email)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model) && (!model.Contains("@") || !model.Contains(".")))
|
||||
context.AddFailure("فرمت پست الکترونیک صحبح نمی باشد");
|
||||
});
|
||||
RuleFor(r => r.Item2.EconomicCode)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model) && (model.Length < 11 || model.Length > 14))
|
||||
context.AddFailure("تعداد کارکتر شماره اقتصادی صحبح نمی باشد");
|
||||
});
|
||||
RuleFor(r => r.Item2.BranchID)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model) && (model.Length > 10))
|
||||
context.AddFailure("تعداد کارکتر کد شعبه صحبح نمی باشد");
|
||||
});
|
||||
RuleFor(r => r.Item2.ZipCode)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model) && (model.Length != 10))
|
||||
context.AddFailure("تعداد کارکتر کد پستی صحبح نمی باشد");
|
||||
});
|
||||
RuleFor(r => r.Item2.MeliCode)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model) && (model.Length < 10 || model.Length > 12))
|
||||
context.AddFailure("تعداد کارکتر شناسه ملی صحبح نمی باشد");
|
||||
});
|
||||
RuleFor(r => r.Item2.PassportNumber)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model) && (model.Length != 9))
|
||||
context.AddFailure("تعداد کارکتر شماره گذرنامه صحبح نمی باشد");
|
||||
});
|
||||
RuleFor(r => r.Item2.Info)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model) && model.Length > 50)
|
||||
context.AddFailure("تعداد کارکتر توضیحات بیش از 50 می باشد");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user