...
This commit is contained in:
45
Back/Validations/Warehouse/Receipt/ADDValidation.cs
Normal file
45
Back/Validations/Warehouse/Receipt/ADDValidation.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Back.Data.Contracts;
|
||||
using FluentValidation;
|
||||
using Shared.DTOs.Warehouse;
|
||||
using Net.Pkcs11Interop.Common;
|
||||
using Back.Services;
|
||||
using Back.Data.Models;
|
||||
|
||||
namespace Back.Validations.Warehouse.Receipt
|
||||
{
|
||||
public class ADDValidation : AbstractValidator<Tuple<ReceiptDto,int>>
|
||||
{
|
||||
public ADDValidation(ServCOD servCOD, CheckPermission checkPermission)
|
||||
{
|
||||
// کالا مدنظر برای شرکت است
|
||||
CascadeMode = CascadeMode.Stop;
|
||||
|
||||
RuleFor(model => model)
|
||||
.Custom((model, context) => {
|
||||
if (servCOD.ExistCodByCompanyID(model.Item1.CODID, model.Item2).Result)
|
||||
context.AddFailure("کد کالا یافت نشد");
|
||||
});
|
||||
|
||||
|
||||
RuleFor(model => model.Item1.Count)
|
||||
.Custom((model, context) => {
|
||||
if (model <= 0)
|
||||
context.AddFailure("تعداد نمیتواند صفر یا کمتر از صفر باشد");
|
||||
});
|
||||
|
||||
RuleFor(model => model.Item1.info)
|
||||
.Custom((model, context) => {
|
||||
if (string.IsNullOrEmpty(model))
|
||||
context.AddFailure("توضیحی برای رسید در نظر بگیرید");
|
||||
});
|
||||
|
||||
RuleFor(r => r.Item2)
|
||||
.Custom((CompanyID, context) =>
|
||||
{
|
||||
if (!checkPermission.AllowAddReceiptInCompany(CompanyID).Result)
|
||||
context.AddFailure("اضافه کردن رسید محدود شده است");
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
30
Back/Validations/Warehouse/Receipt/DeleteValidation.cs
Normal file
30
Back/Validations/Warehouse/Receipt/DeleteValidation.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using FluentValidation;
|
||||
using Shared.DTOs.Warehouse;
|
||||
using Back.Data.Models.Warehouse;
|
||||
using Back.Data.Contracts;
|
||||
using Back.Services.Warehouse;
|
||||
using Back.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Back.Validations.Warehouse.Receipt
|
||||
{
|
||||
public class DeleteValidation : AbstractValidator<Tuple<int, int>>
|
||||
{
|
||||
public DeleteValidation(IAsyncRepository<Back.Data.Models.Warehouse.Receipt> _ReceiptRepo, WarehouseService warehouseService)
|
||||
{
|
||||
RuleFor(model => model)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
var ORGitem = _ReceiptRepo.Get(w => w.ID == model.Item1 && w.cODItem.CompanyID == model.Item2 && !w.Deleted).Include(i => i.cODItem).FirstOrDefault();
|
||||
if (ORGitem == null)
|
||||
context.AddFailure("رسید یافت نشد");
|
||||
|
||||
var Inventory = warehouseService.Inventory(model.Item2, ORGitem.CODID).Result;
|
||||
if (Inventory - ORGitem.Count < 0)
|
||||
{
|
||||
context.AddFailure($"حذف رسید روی موجودی کالا {ORGitem.cODItem.Title} تاثیر میگذارد و آن را منفی میکند");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
78
Back/Validations/Warehouse/Receipt/UpdateValidation.cs
Normal file
78
Back/Validations/Warehouse/Receipt/UpdateValidation.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Services;
|
||||
using Back.Services.Warehouse;
|
||||
using FluentValidation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Shared.DTOs.Warehouse;
|
||||
|
||||
namespace Back.Validations.Warehouse.Receipt
|
||||
{
|
||||
public class UpdateValidation : AbstractValidator<Tuple<ReceiptDto, int>>
|
||||
{
|
||||
public UpdateValidation(IAsyncRepository<Back.Data.Models.Warehouse.Receipt> _ReceiptRepo, ServCOD servCOD, WarehouseService warehouseService)
|
||||
{
|
||||
CascadeMode = CascadeMode.Stop;
|
||||
RuleFor(model => model)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
var ORGitem = _ReceiptRepo.Get(w => w.ID == model.Item1.ID && !w.Deleted).Include(i => i.cODItem).FirstOrDefault();
|
||||
if (ORGitem.InvoiceID.HasValue)
|
||||
{
|
||||
context.AddFailure("رسید فاکتور قایل ویرایش نیست");
|
||||
return;
|
||||
}
|
||||
if (ORGitem == null)
|
||||
context.AddFailure("رسید یافت نشد");
|
||||
else
|
||||
{
|
||||
if (ORGitem.CODID != model.Item1.CODID)
|
||||
{
|
||||
if (servCOD.ExistCodByCompanyID(model.Item1.CODID, model.Item2).Result)
|
||||
context.AddFailure("کد کالا یافت نشد");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ORGitem.CODID != model.Item1.CODID)
|
||||
{
|
||||
|
||||
context.AddFailure("در رسید امکان ویرایش کالا انکان پذیر نیست");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((ORGitem.Count > model.Item1.Count && ORGitem.ForSale && !model.Item1.ForSale) ||
|
||||
ORGitem.Count > model.Item1.Count)
|
||||
{
|
||||
var ekh = ORGitem.Count - model.Item1.Count;
|
||||
var Inventory = warehouseService.Inventory(model.Item2, ORGitem.CODID).Result;
|
||||
if ((Inventory - ekh) < 0)
|
||||
{
|
||||
context.AddFailure($"این تغییرات روی موجودی کالا {ORGitem.cODItem.Title} تاثیر میگذارد و آن را منفی میکند");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (ORGitem.ForSale && !model.Item1.ForSale)
|
||||
{
|
||||
var Inventory = warehouseService.Inventory(model.Item2, ORGitem.CODID).Result;
|
||||
if (Inventory - ORGitem.Count < 0)
|
||||
{
|
||||
context.AddFailure($"این تغییرات روی موجودی کالا {ORGitem.cODItem.Title} تاثیر میگذارد و آن را منفی میکند");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Item1.info))
|
||||
{
|
||||
context.AddFailure("توضیحی برای رسید در نظر بگیرید");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user