public async Task <IActionResult> Get(long hardwareDeviceId, [FromBody] PageCriteriaViewModel viewModel)
 {
     return(await ExecuteAsync(async() =>
     {
         var pageViewModel = PageCriteriaViewModel.ToModel(viewModel, typeof(LogEntry));
         var pagedData = await _repository.GetByDeviceAsync(hardwareDeviceId, pageViewModel);
         return PagedDataViewModel <LogEntryViewModel> .ToViewModel(pagedData);
     }));
 }
Пример #2
0
        //private IQueryable<Firm> SortFirm(IQueryable<Firm> entity, string sort, string sortDir)
        //{
        //    const string _dir = direction;
        //    if (entity != null && !string.IsNullOrEmpty(sort))
        //    {
        //        switch (sort.ToLower())
        //        {
        //            case name:
        //                entity = sortDir.Equals(_dir, StringComparison.InvariantCultureIgnoreCase) ? entity.OrderBy(e => e.Name) : entity.OrderByDescending(e => e.Name);
        //                break;
        //            case battleCardReportingPriority:
        //                entity = sortDir.Equals(_dir, StringComparison.InvariantCultureIgnoreCase) ? entity.OrderBy(e => e.BattleCardReportingPriority) : entity.OrderByDescending(e => e.BattleCardReportingPriority);
        //                break;
        //            case active:
        //                entity = sortDir.Equals(_dir, StringComparison.InvariantCultureIgnoreCase) ? entity.OrderBy(e => e.Active) : entity.OrderByDescending(e => e.Active);
        //                break;
        //            default:
        //                entity = sortDir.Equals(_dir, StringComparison.InvariantCultureIgnoreCase) ? entity.OrderBy(e => e.ID)
        //                    : entity.OrderBy(e => e.ID);
        //                break;
        //        }
        //    }
        //    return entity;
        //}

        //private IQueryable<Firm> PagingFirm(IQueryable<Firm> entity, int pageSize, int skip)
        //{
        //    if (pageSize>0)
        //    {
        //        entity = entity.Skip(skip).Take(pageSize);
        //    }

        //    return entity;
        //}
        //private IQueryable<Firm>  FilterGridData(IQueryable<Firm> entity, GridFilterObejctModel filter)
        //{
        //    System.Diagnostics.Contracts.Contract.Requires(entity != null && filter != null);

        //    if (filter != null && !string.IsNullOrEmpty(filter.Value) && entity != null)
        //    {
        //        string expressonFilter = string.Empty;
        //        string _field = filter.Field;
        //        string _operator = filter.Operator;
        //        string _value = filter.Value;
        //        Func<Firm, bool> predicate = null;

        //        switch (_field)
        //        {
        //            case name:
        //                predicate = (e) => e.Name.ToLower().Contains(_value.ToLower());
        //                break;
        //            case active:
        //                predicate = (e) => e.Active.Value.ToString().Equals(_value,StringComparison.InvariantCultureIgnoreCase);
        //                break;
        //            default: break;

        //        }
        //        entity = entity.Where(predicate).AsQueryable();
        //    }

        //    return entity;
        //}

        public PagedDataViewModel <Firm> GetAllFirms(GridPropertyObejctModel gridAttrData)
        {
            PagedDataViewModel <Firm> firm = new PagedDataViewModel <Firm>();

            try
            {
                List <int> itemIds      = new List <int>();
                long       totalRecords = 0;
                string     strIds       = string.Empty;

                var _firm = CurrentContext.Firms.Where(t => t.RecordStatus == true).AsEnumerable();

                totalRecords = _firm.Count();
                if (gridAttrData != null)  //Grid Property operations Handled
                {
                    itemIds = FilterGridDataIds(gridAttrData);

                    if (itemIds.Any())
                    {
                        strIds  = string.Join(Constants.Pipe, itemIds);
                        strIds += Constants.Pipe;
                    }

                    if (gridAttrData.filters.Any())
                    {
                        totalRecords = itemIds.Count;
                    }

                    _firm = CurrentContext.Firms.Where(c => itemIds.Contains(c.ID))
                            .OrderBy(t => SqlFunctions.CharIndex(Constants.Pipe + SqlFunctions.StringConvert((double)t.ID).Trim() + Constants.Pipe, strIds)).AsEnumerable();


                    //_firm = SortFirm(_firm, _sortfield, _sortDir);
                    //_firm = PagingFirm(_firm, _pageSize, _skip);
                }

                firm.Total = totalRecords;
                firm.Data  = _firm;
            }
            catch (OptimisticConcurrencyException ex)
            {
                EventLogger.LogEvent(ex);
            }
            catch (Exception ex)
            {
                EventLogger.LogEvent(ex);
                throw;
            }
            return(firm);
        }