xxxxxxxxxx
[HttpPost]
public async Task> GetOutageReportList([FromBody] DataSourceRequest request)
{
try
{
var time = DateTime.UtcNow.AddDays(-1);
var outageList = _outageReportRepository
.Include(x => x.SupplyNetwork).Include(x => x.Cause)
.Where(x => x.TenantId == CurrentTenant.Id.Value)
.Where(x => x.RecordedTime >= time)
.Select(x => ObjectMapper.Map(x)).ToList();
var output = await outageList.ToDataSourceResultAsync(request);
DataEnvelope dataToReturn;
if (request.Groups != null && request.Groups.Count > 0)
{
// If there is grouping, use the field for grouped data
// The app must be able to serialize and deserialize it
// Example helper methods for this are available in this project
// See the GroupDataHelper.DeserializeGroups and JsonExtensions.Deserialize methods
dataToReturn = new DataEnvelope
{
GroupedData = output.Data.Cast().ToList(),
TotalItemCount = output.Total
};
}
else
{
// When there is no grouping, the simplistic approach of
// just serializing and deserializing the flat data is enough
dataToReturn = new DataEnvelope
{
CurrentPageData = output.Data.Cast().ToList(),
TotalItemCount = output.Total
};
}
return dataToReturn;
}
catch (Exception ex)
{
Console.WriteLine("Error: ", ex.Message);
Console.WriteLine(ex);
throw;
}
}
xxxxxxxxxx
protected async Task OnReadHandler(GridReadEventArgs args)
{
LastRequest = args.Request;
List filters = null;
if (LastRequest.Filters.Any())
{
var filterDescriptors = LastRequest.Filters.SelectMemberDescriptors().ToList();
if (filterDescriptors.Any())
{
filters = new List();
foreach (var filter in filterDescriptors)
{
filters.Add(new FilterDescriptor { Member = filter.Member, Operator = filter.Operator, Value = filter.Value });
}
}
}
LastRequest.Filters = filters;
await LoadData();
}