119 lines
3.4 KiB
C#
119 lines
3.4 KiB
C#
![]() |
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 ReceiptService
|
|||
|
{
|
|||
|
private readonly IAsyncRepository<Receipt> _ReceiptRepo;
|
|||
|
|
|||
|
public ReceiptService(IAsyncRepository<Receipt> ReceiptRepo)
|
|||
|
{
|
|||
|
_ReceiptRepo = ReceiptRepo;
|
|||
|
}
|
|||
|
|
|||
|
public async Task<ReceiptDto?> ADD(ReceiptDto item)
|
|||
|
{
|
|||
|
var model = new Receipt()
|
|||
|
{
|
|||
|
Date = item.Date,
|
|||
|
CODID = item.CODID,
|
|||
|
Count = item.Count,
|
|||
|
ForSale = item.ForSale,
|
|||
|
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<ReceiptDto?> Update(ReceiptDto 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.ForSale= item.ForSale;
|
|||
|
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<ReceiptDto?> Get(int itemID, int CompanyID)
|
|||
|
{
|
|||
|
return await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID)
|
|||
|
.Include(inc=>inc.cODItem)
|
|||
|
.Select(s=>new ReceiptDto()
|
|||
|
{
|
|||
|
Date = s.Date,
|
|||
|
CODID=s.CODID,
|
|||
|
Count = s.Count,
|
|||
|
ForSale= s.ForSale,
|
|||
|
ID=s.ID,
|
|||
|
CODTitle=s.cODItem.Title,
|
|||
|
info = s.info,
|
|||
|
Type=s.Type
|
|||
|
|
|||
|
})
|
|||
|
.FirstOrDefaultAsync();
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
public async Task<List<ReceiptDto>?> GetAll(int CompanyID, TypeReceipt? 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 ReceiptDto()
|
|||
|
{
|
|||
|
Date = s.Date,
|
|||
|
CODID = s.CODID,
|
|||
|
Count = s.Count,
|
|||
|
ForSale = s.ForSale,
|
|||
|
ID = s.ID,
|
|||
|
CODTitle = s.cODItem.Title,
|
|||
|
info = s.info,
|
|||
|
Type = s.Type
|
|||
|
})
|
|||
|
.ToListAsync();
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|