예제 #1
0
        //-> GetList
        public async Task <GetListDTO <ItemViewDTO> > GetList(ItemFindDTO findDTO)
        {
            /*
             * //--seem like search sql not dynamic -> should write one helper function or interface to do dynamic search
             * IQueryable<tblItem> records = from x in db.tblItems
             *                                  where x.deleted == null
             *                                  && (string.IsNullOrEmpty(findDTO.code) ? 1 == 1 : x.code.Contains(findDTO.code))
             *                                  && (string.IsNullOrEmpty(findDTO.name) ? 1 == 1 : x.name.Contains(findDTO.name))
             *                                  orderby x.id ascending
             *                                  select x;
             * return await Listing(findDTO.currentPage, records);
             */
            //--seem like search sql not dynamic -> should write one helper function or interface to do dynamic search

            /*
             * IQueryable<tblItem> records = from x in db.tblItems
             *                            where x.deleted == null
             *                            && (string.IsNullOrEmpty(findDTO.code) ? 1 == 1 : x.code.Contains(findDTO.code))
             *                            && (string.IsNullOrEmpty(findDTO.name) ? 1 == 1 : x.name.Contains(findDTO.name))
             *                            select x;
             * return await Listing(findDTO.currentPage, records.AsQueryable().OrderBy($"{findDTO.orderBy} {findDTO.orderDirection}"));
             */
            IQueryable <tblItem> query = db.tblItems.Where(x => x.deleted == null);

            if (!string.IsNullOrEmpty(findDTO.code))
            {
                query = query.Where(x => x.code.StartsWith(findDTO.code));
            }
            if (!string.IsNullOrEmpty(findDTO.name))
            {
                query = query.Where(x => x.name.StartsWith(findDTO.name));
            }
            query = query.AsQueryable().OrderBy($"{findDTO.orderBy} {findDTO.orderDirection}");

            return(await ListingHandler(findDTO.currentPage, query));
        }
예제 #2
0
 public async Task <ActionResult> Paging(ItemFindDTO findDTO)
 {
     return(PartialView(await handler.GetList(findDTO)));
 }