Some checks failed
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Failing after 2m13s
74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Models.Interfaces;
|
|
using Models.Helpers;
|
|
using Models.Models;
|
|
using Domain.Entities;
|
|
using Domain.Generics;
|
|
|
|
namespace Models.Repositories
|
|
{
|
|
public class PhSQuoteHeaderRepository(PhronCareOperationsHubContext context) : IPhSQuoteHeaderRepository
|
|
{
|
|
private readonly PhronCareOperationsHubContext _context = context;
|
|
//private readonly IPhSFormSeriesRepository _formSeriesRepository = formSeriesRepository;
|
|
#region Metodos
|
|
public async Task<PagedResult<EQuoteHeader>> GetAllAsync(int page = 1, int pageSize = 50)
|
|
{
|
|
var query = _context.PhSQuoteHeaders
|
|
.Include(q => q.PhSQuoteDetails)
|
|
.Include(q => q.PhSQuoteRoles)
|
|
.Include(q => q.PhSQuoteAdjustments)
|
|
.Include(q => q.PhSQuoteTaxes)
|
|
.AsNoTracking();
|
|
|
|
var pagedEntities = await query.ToPagedResultAsync(page, pageSize);
|
|
|
|
return new PagedResult<EQuoteHeader>
|
|
{
|
|
Items = pagedEntities.Items.Select(EntityMapper.MapEntity<PhSQuoteHeader, EQuoteHeader>),
|
|
TotalItems = pagedEntities.TotalItems,
|
|
Page = pagedEntities.Page,
|
|
PageSize = pagedEntities.PageSize
|
|
};
|
|
}
|
|
public async Task<EQuoteHeader?> GetByIdAsync(int id)
|
|
{
|
|
var entity = await _context.PhSQuoteHeaders
|
|
.Include(q => q.PhSQuoteDetails)
|
|
.Include(q => q.PhSQuoteRoles)
|
|
.Include(q => q.PhSQuoteAdjustments)
|
|
.Include(q => q.PhSQuoteTaxes)
|
|
.FirstOrDefaultAsync(q => q.Id == id);
|
|
|
|
return entity != null ? EntityMapper.MapEntity<PhSQuoteHeader, EQuoteHeader>(entity) : null;
|
|
}
|
|
public async Task<IEnumerable<EQuoteHeader>> GetByCustomerIdAsync(int customerId)
|
|
{
|
|
var entities = await _context.PhSQuoteHeaders
|
|
.Where(q => q.CustomerId == customerId)
|
|
.Include(q => q.PhSQuoteDetails)
|
|
.Include(q => q.PhSQuoteRoles)
|
|
.Include(q => q.PhSQuoteAdjustments)
|
|
.Include(q => q.PhSQuoteTaxes)
|
|
.ToListAsync();
|
|
|
|
return entities.Select(EntityMapper.MapEntity<PhSQuoteHeader, EQuoteHeader>);
|
|
}
|
|
public async Task UpdateAsync(EQuoteHeader quoteHeader)
|
|
{
|
|
var dbEntity = EntityMapper.MapEntity<EQuoteHeader, PhSQuoteHeader>(quoteHeader);
|
|
_context.PhSQuoteHeaders.Update(dbEntity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
public async Task DeleteAsync(int id)
|
|
{
|
|
var entity = await _context.PhSQuoteHeaders.FindAsync(id);
|
|
if (entity != null)
|
|
{
|
|
_context.PhSQuoteHeaders.Remove(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |