using Back.Data.Contracts; using Back.Data.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Hosting; using Shared.DTOs; namespace Back.Services { public class servInvoicePayment { private readonly IAsyncRepository _Repo; private readonly IAsyncRepository _CodingRepo; public servInvoicePayment(IAsyncRepository Repo, IAsyncRepository CodingRepo) { _Repo = Repo; _CodingRepo = CodingRepo; } public async Task Add(InvoicePayment item) { return await _Repo.AddAsync(item); } public async Task Update(InvoicePayment item) { return await _Repo.UpdateByObjAsync(item); } public async Task Delete(InvoicePayment item) { return await _Repo.DeleteAsync(item); } public async Task Exist(int companyID, int invoiceID, int ID) { return await _Repo.Get(w => w.InvoiceID == invoiceID && w.ID == ID && w.invoice.CompanyID == companyID).AnyAsync(); } public async Task GetinvoicePay(int CompanyID, int ID) { return await _Repo .Get(w => w.ID == ID && w.invoice.CompanyID == CompanyID && !w.invoice.IsDeleted) .Include(s=>s.invoice) .FirstOrDefaultAsync(); } public async Task GetInvoicePayByInvoicePayID (int companyID, int invoiceID, int ID) { return await _Repo.Get(w => w.InvoiceID == invoiceID && w.ID == ID && w.invoice.CompanyID == companyID).FirstOrDefaultAsync(); } public async Task>> GetPaymentMethods() { return await _CodingRepo.Get(w => w.FildID == 71) .Select(s=>new IdName { ID=s.Code,Title=s.Title }).ToListAsync(); } } }