public async Task <PaginationService <EquipmentIndexViewModel> > GetEquipmentsAsync(ParameterCommonViewModel parameter) { var equipments = await _context.Equipments.Include(e => e.Clinic).Select(e => new EquipmentIndexViewModel { Id = e.Id, EquipmentName = e.EquipmentName, ClinicName = e.Clinic.ClinicName, Condition = e.Condition, Quantity = e.Quantity, UnitPrice = e.UnitPrice, SuppliedAt = e.SuppliedAt }) .AsNoTracking() .OrderByDescending(e => e.Id) .ToListAsync(); if (!string.IsNullOrEmpty(parameter.Keyword)) { equipments = equipments .Where(c => c.ClinicName.ToLower().Trim().Contains(parameter.Keyword.ToLower().Trim()) || c.EquipmentName.ToLower().Trim().Contains(parameter.Keyword.ToLower().Trim())) .ToList(); } return(PaginationService <EquipmentIndexViewModel> .ToPagedList(equipments, parameter.Page, parameter.Size)); }
public async Task <PaginationService <ClinicIndexViewModel> > GetClinicsAsync(ParameterCommonViewModel parameter) { var clinics = await _context.Clinics.Include(c => c.Equipments).Select(c => new ClinicIndexViewModel { Id = c.Id, ClinicName = c.ClinicName, EquipmentCount = c.Equipments.Count() }) .AsNoTracking() .OrderByDescending(c => c.Id) .ToListAsync(); if (!string.IsNullOrEmpty(parameter.Keyword)) { clinics = clinics.Where(c => c.ClinicName.ToLower().Trim().Contains(parameter.Keyword.ToLower().Trim())).ToList(); } return(PaginationService <ClinicIndexViewModel> .ToPagedList(clinics, parameter.Page, parameter.Size)); }
public async Task <PaginationService <T> > GetResourcesAsync(ParameterCommonViewModel parameter) { var resources = await _context.Set <T>().ToListAsync(); return(PaginationService <T> .ToPagedList(resources, parameter.Page, parameter.Size)); }