Files
moadiran/Back/Services/Warehouse/RemittanceService.cs

114 lines
3.3 KiB
C#
Raw Normal View History

2025-01-11 10:10:47 +03:30
using Back.Data.Contracts;
using Back.Data.Models.Warehouse;
using Microsoft.EntityFrameworkCore;
using Shared.DTOs.Warehouse;
using Shared.Enums;
namespace Back.Services.Warehouse
{
public class RemittanceService
{
private readonly IAsyncRepository<Remittance> _ReceiptRepo;
public RemittanceService(IAsyncRepository<Remittance> remittanceRepo)
{
_ReceiptRepo = remittanceRepo;
}
public async Task<RemittanceDto?> ADD(RemittanceDto item)
{
var model = new Remittance()
{
Date = item.Date,
CODID = item.CODID,
Count = item.Count,
info = item.info,
Type = item.Type,
};
var returnmodel = await _ReceiptRepo.AddAsync(model);
if (returnmodel != null)
{
item.ID = returnmodel.ID;
return item;
}
else
{
return null;
}
}
public async Task<RemittanceDto?> Update(RemittanceDto item)
{
var model = await _ReceiptRepo.Get(w => w.ID == item.ID).FirstOrDefaultAsync();
model.Date = item.Date;
model.CODID = item.CODID;
model.Count = item.Count;
model.info = item.info;
model.Type = item.Type;
var returnmodel = await _ReceiptRepo.UpdateAsync(model);
if (returnmodel)
{
return item;
}
else
{
return null;
}
}
public async Task<bool> Delete(int itemID, int CompanyID)
{
var model = await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID).FirstOrDefaultAsync();
return await _ReceiptRepo.DeleteAsync(model);
}
public async Task<RemittanceDto?> Get(int itemID, int CompanyID)
{
return await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID)
.Include(inc => inc.cODItem)
.Select(s => new RemittanceDto()
{
Date = s.Date,
CODID = s.CODID,
Count = s.Count,
ID = s.ID,
CODTitle = s.cODItem.Title,
info = s.info,
Type = s.Type
})
.FirstOrDefaultAsync();
}
public async Task<List<RemittanceDto>?> GetAll(int CompanyID, TypeRemittance? Type = null, int CODID = 0)
{
var request = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID);
if (Type != null)
request = request.Where(w => w.Type == Type);
if (CODID != 0)
request = request.Where(w => w.CODID == CODID);
return await request
.Include(inc => inc.cODItem)
.Select(s => new RemittanceDto()
{
Date = s.Date,
CODID = s.CODID,
Count = s.Count,
ID = s.ID,
CODTitle = s.cODItem.Title,
info = s.info,
Type = s.Type
})
.ToListAsync();
}
}
}