public Task <IDataSourceResponse <TriggerViewModel> > ReadAsync(DataSourceRequest request) { var responseData = this.DbContext.Trigger.Include("Channel").Select(t => t); if (request.ServerFiltering != null) { var filter = request.ServerFiltering.FilterCollection.SingleOrDefault(f => f.Field == "ChannelId"); int channelId = Convert.ToInt32(filter.Value); responseData = responseData.Where(t => t.ChannelId == channelId); } IDataSourceResponse <TriggerViewModel> response = new DataSourceResponse <TriggerViewModel> { TotalRowCount = responseData.Count() }; if (request.ServerPaging != null) { int skip = Math.Max(request.ServerPaging.PageSize * (request.ServerPaging.Page - 1), 0); responseData = responseData.OrderBy(p => p.Id).Skip(skip).Take(request.ServerPaging.PageSize); } var dataCollection = responseData.ToList(); foreach (var data in dataCollection) { response.DataCollection.Add(TriggerViewModel.NewInstance(data)); } return(Task.FromResult(response)); }
public ICollection <TriggerViewModel> Read(IFilterInfoCollection serverFiltering) { ICollection <TriggerViewModel> triggers = new List <TriggerViewModel>(); if (serverFiltering != null) { var filter = serverFiltering.FilterCollection.SingleOrDefault(f => f.Field == "Id"); int channelId = Convert.ToInt32(filter.Value); var dataCollection = this.DbContext.Trigger.Include("Channel").Where(t => t.ChannelId == channelId).Select(t => t).ToList(); foreach (var data in dataCollection) { triggers.Add(TriggerViewModel.NewInstance(data)); } } return(triggers); }