phronCare/Models/Repositories/Stock/PhLSMUnitOfMeasureRepository.cs
Leandro Hernan Rojas 369190695b
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 26m25s
Add Massive Import Products
2025-07-14 16:16:05 -03:00

42 lines
1.4 KiB
C#

using Domain.Entities;
using Domain.Generics;
using Microsoft.EntityFrameworkCore;
using Models.Helpers;
using Models.Interfaces;
using Models.Models;
namespace Models.Repositories.Stock
{
public class PhLSMUnitOfMeasureRepository(PhronCareOperationsHubContext context) : IPhLSMUnitOfMeasureRepository
{
private readonly PhronCareOperationsHubContext _context = context;
public async Task<PagedResult<ELSUnitOfMeasure>> GetAllAsync(int page = 1, int pageSize = 100)
{
var query = _context.PhLsmUnitOfMeasures.AsQueryable();
var paged = await query.ToPagedResultAsync(page, pageSize);
return new PagedResult<ELSUnitOfMeasure>
{
Items = paged.Items.Select(EntityMapper.MapEntity<PhLsmUnitOfMeasure, ELSUnitOfMeasure>),
TotalItems = paged.TotalItems,
Page = paged.Page,
PageSize = paged.PageSize
};
}
public async Task<bool> ExistsByCodeAsync(string code)
{
if (string.IsNullOrWhiteSpace(code))
return false;
return await _context.PhLsmUnitOfMeasures
.AnyAsync(x => x.Code.ToLower() == code.ToLower());
}
public async Task<List<string>> GetAllCodesAsync()
{
return await _context.PhLsmUnitOfMeasures
.Select(x => x.Code)
.ToListAsync();
}
}
}