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> GetAllAsync(int page = 1, int pageSize = 100) { var query = _context.PhLsmUnitOfMeasures.AsQueryable(); var paged = await query.ToPagedResultAsync(page, pageSize); return new PagedResult { Items = paged.Items.Select(EntityMapper.MapEntity), TotalItems = paged.TotalItems, Page = paged.Page, PageSize = paged.PageSize }; } public async Task ExistsByCodeAsync(string code) { if (string.IsNullOrWhiteSpace(code)) return false; return await _context.PhLsmUnitOfMeasures .AnyAsync(x => x.Code.ToLower() == code.ToLower()); } public async Task> GetAllCodesAsync() { return await _context.PhLsmUnitOfMeasures .Select(x => x.Code) .ToListAsync(); } } }