示例#1
0
 public SparePartList GetList(SparePartFilter filter)
 {
     using (EntityFrameworkContext context = new EntityFrameworkContext())
     {
         SparePartList list       = new SparePartList();
         var           spareParts = context.SpareParts.Include(x => x.Mark).Where(x => x.Name.ToUpper().Contains(filter.NameFilter));
         if (filter.MarkIds.Length > 0)
         {
             spareParts = spareParts.Where(x => filter.MarkIds.Contains(x.MarkId));
         }
         list.PagesCount = (int)Math.Ceiling(spareParts.Count() / (double)filter.PageSize);
         if (filter.Sort > 0)
         {
             if ((int)filter.Sort % 2 == 0)
             {
                 spareParts = spareParts.OrderBy(x => SortFunction[(int)filter.Sort / 2](x));
             }
             else
             {
                 spareParts = spareParts.OrderByDescending(x => SortFunction[(int)filter.Sort / 2 + 1](x));
             }
         }
         list.SpareParts = spareParts.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList();
         return(list);
     }
 }
示例#2
0
        public IActionResult ListForUsers([FromBody] SparePartFilter filter)
        {
            SparePartListForUsers list = new SparePartListForUsers();
            var listFromDb             = _sparePartService.GetList(filter);

            list.PagesCount = listFromDb.PagesCount;
            list.SpareParts = listFromDb.SpareParts.Select(x => _mapper.Map <SparePartForUsers>(x));
            return(Ok(list));
        }
示例#3
0
 public IActionResult List([FromBody] SparePartFilter filter)
 {
     return(Ok(_sparePartService.GetList(filter)));
 }
示例#4
0
 public SparePartList GetList(SparePartFilter filter)
 {
     return(_sparePartRepository.GetList(filter));
 }