예제 #1
0
        public async Task <IEnumerable <EquipmentIndexViewModel> > GetEquipments([FromQuery] ParameterCommonViewModel parameter)
        {
            try
            {
                var equipments = await _equipment.GetEquipmentsAsync(parameter);

                var meta = new
                {
                    equipments.Total,
                    equipments.Page,
                    equipments.Size,
                    equipments.Pages,
                    equipments.HasNext,
                    equipments.HasPrevious
                };

                Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(meta).ToLower());
                LoggerService.GetInstance.CreateLog("[GetEquipments] The get process has completed successfully.");

                return(equipments);
            }
            catch (Exception e)
            {
                LoggerService.GetInstance.CreateLog("[GetEquipments]" + e.Message);

                throw new Exception(e.Message);
            }
        }
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        public async Task <PaginationService <T> > GetResourcesAsync(ParameterCommonViewModel parameter)
        {
            var resources = await _context.Set <T>().ToListAsync();

            return(PaginationService <T> .ToPagedList(resources, parameter.Page, parameter.Size));
        }