Skip to content

Commit

Permalink
Add support for custom ToListAsync for IQueryable object (gustavnavar…
Browse files Browse the repository at this point in the history
  • Loading branch information
dev0926 committed Mar 21, 2022
1 parent fd732ef commit 08f372f
Show file tree
Hide file tree
Showing 64 changed files with 260 additions and 165 deletions.
8 changes: 4 additions & 4 deletions GridBlazor/CGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,13 +1141,13 @@ private async Task GetItemsDTO()
try
{
ItemsDTO<T> response;
if (_dataService != null)
if (_dataServiceAsync != null)
{
response = _dataService((QueryDictionary<StringValues>)_query);
response = await _dataServiceAsync(_query);
}
else if (_dataServiceAsync != null)
else if (_dataService != null)
{
response = await _dataServiceAsync((QueryDictionary<StringValues>)_query);
response = _dataService(_query);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/GridBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>8.0</LangVersion>
<GenerateEmbeddedFilesManifest>True</GenerateEmbeddedFilesManifest>
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
<Version>3.2.2</Version>
<Version>3.2.3</Version>
<Title>GridBlazor</Title>
<Description>Grid components for Blazor</Description>
<Summary>Grid components for Blazor</Summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>3.2.2</Version>
<Version>3.2.3</Version>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions GridBlazorClientSide.Client/Pages/ButtonCrud.razor
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ else
{
private CGrid<Order> _grid;
private GridComponent<Order> _gridComponent;
private bool _areEventsLoaded = false;
private bool _afterRenderExecuted = false;
private object[] _keys;
private GridMode _mode;
private Task _task;
Expand Down Expand Up @@ -106,12 +106,12 @@ else

protected override void OnAfterRender(bool firstRender)
{
if (!_areEventsLoaded && _gridComponent != null)
if (!_afterRenderExecuted && _gridComponent != null)
{
_gridComponent.BeforeInsert += BeforeInsert;
_gridComponent.BeforeUpdate += BeforeUpdate;
_gridComponent.BeforeDelete += BeforeDelete;
_areEventsLoaded = true;
_afterRenderExecuted = true;
}
}

Expand Down
6 changes: 3 additions & 3 deletions GridBlazorClientSide.Client/Pages/Crud.razor
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ else
{
private CGrid<Order> _grid;
private GridComponent<Order> _gridComponent;
private bool _areEventsLoaded = false;
private bool _afterRenderExecuted = false;
private object[] _keys;
private GridMode _mode;
private Task _task;
Expand Down Expand Up @@ -104,12 +104,12 @@ else

protected override void OnAfterRender(bool firstRender)
{
if (!_areEventsLoaded && _gridComponent != null)
if (!_afterRenderExecuted && _gridComponent != null)
{
_gridComponent.BeforeInsert += BeforeInsert;
_gridComponent.BeforeUpdate += BeforeUpdate;
_gridComponent.BeforeDelete += BeforeDelete;
_areEventsLoaded = true;
_afterRenderExecuted = true;
}
}

Expand Down
6 changes: 3 additions & 3 deletions GridBlazorClientSide.Client/Pages/NestedCrud.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ else
private object[] _keys;
private GridMode _mode;
private Task _task;
private bool _areEventsLoaded = false;
private bool _afterRenderExecuted = false;

[Parameter]
public string OrderId { get; set; }
Expand Down Expand Up @@ -127,12 +127,12 @@ else

protected override void OnAfterRender(bool firstRender)
{
if (_gridComponent != null && !_areEventsLoaded)
if (_gridComponent != null && !_afterRenderExecuted)
{
_gridComponent.BeforeInsert += BeforeInsert;
_gridComponent.BeforeUpdate += BeforeUpdate;
_gridComponent.BeforeDelete += BeforeDelete;
_areEventsLoaded = true;
_afterRenderExecuted = true;
}
}

Expand Down
6 changes: 3 additions & 3 deletions GridBlazorClientSide.Client/Pages/NestedCrudCreateGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ else
private GridComponent<Order> _gridComponent;
private OrderDetailMemoryService _orderDetailMemoryService;
private Task _task;
private bool _areEventsLoaded = false;
private bool _afterRenderExecuted = false;

protected override async Task OnParametersSetAsync()
{
Expand Down Expand Up @@ -90,10 +90,10 @@ else

protected override void OnAfterRender(bool firstRender)
{
if (_gridComponent != null && !_areEventsLoaded)
if (_gridComponent != null && !_afterRenderExecuted)
{
_gridComponent.AfterInsert += AfterInsert;
_areEventsLoaded = true;
_afterRenderExecuted = true;
}
}

Expand Down
64 changes: 32 additions & 32 deletions GridBlazorClientSide.Server/Controllers/SampleDataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SampleDataController(NorthwindDbContext context)
}

[HttpGet("[action]")]
public ActionResult GetOrdersGrid()
public async Task<ActionResult> GetOrdersGrid()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -36,7 +36,7 @@ public ActionResult GetOrdersGrid()
.WithGridItemsCount()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

Expand All @@ -59,7 +59,7 @@ public ActionResult GetOrdersGridordersAutoGenerateColumns()
}

[HttpGet("[action]")]
public ActionResult GetOrdersGridWithTotals()
public async Task<ActionResult> GetOrdersGridWithTotals()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -71,7 +71,7 @@ public ActionResult GetOrdersGridWithTotals()
.WithGridItemsCount()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

Expand All @@ -93,7 +93,7 @@ public ActionResult GetOrdersGridWithCount()
}

[HttpGet("[action]")]
public ActionResult GetOrdersGridSearchable()
public async Task<ActionResult> GetOrdersGridSearchable()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -106,12 +106,12 @@ public ActionResult GetOrdersGridSearchable()
.Searchable(true, false, false)
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

[HttpGet("[action]")]
public ActionResult GetOrdersGridExtSorting()
public async Task<ActionResult> GetOrdersGridExtSorting()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -124,12 +124,12 @@ public ActionResult GetOrdersGridExtSorting()
.Groupable(true)
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

[HttpGet("[action]")]
public ActionResult GetOrdersGridGroupable()
public async Task<ActionResult> GetOrdersGridGroupable()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -142,7 +142,7 @@ public ActionResult GetOrdersGridGroupable()
.Groupable(true)
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

Expand Down Expand Up @@ -173,7 +173,7 @@ public ActionResult GetMinFreight(string clientName)
}

[HttpGet("[action]")]
public ActionResult GetOrdersGridWithSubgrids()
public async Task<ActionResult> GetOrdersGridWithSubgrids()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -184,13 +184,13 @@ public ActionResult GetOrdersGridWithSubgrids()
.WithMultipleFilters()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());

return Ok(items);
}

[HttpGet("[action]")]
public ActionResult OrderColumnsListFilter()
public async Task<ActionResult> OrderColumnsListFilter()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -202,12 +202,12 @@ public ActionResult OrderColumnsListFilter()
.WithGridItemsCount()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

[HttpGet("[action]")]
public ActionResult OrderColumnsWithEdit()
public async Task<ActionResult> OrderColumnsWithEdit()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -219,12 +219,12 @@ public ActionResult OrderColumnsWithEdit()
.WithGridItemsCount()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

[HttpGet("[action]")]
public ActionResult OrderColumnsWithCrud()
public async Task<ActionResult> OrderColumnsWithCrud()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -236,12 +236,12 @@ public ActionResult OrderColumnsWithCrud()
.WithGridItemsCount()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

[HttpGet("[action]")]
public ActionResult OrderColumnsWithSubgridCrud()
public async Task<ActionResult> OrderColumnsWithSubgridCrud()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -253,7 +253,7 @@ public ActionResult OrderColumnsWithSubgridCrud()
.WithGridItemsCount()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

Expand All @@ -279,7 +279,7 @@ public ActionResult GetOrderColumnsWithErrors()
}

[HttpGet("[action]")]
public ActionResult GetOrdersGridAllFeatures()
public async Task<ActionResult> GetOrdersGridAllFeatures()
{
var repository = new OrdersRepository(_context);
IGridServer<Order> server = new GridCoreServer<Order>(repository.GetAll(), Request.Query,
Expand All @@ -291,7 +291,7 @@ public ActionResult GetOrdersGridAllFeatures()
.Searchable(true, false)
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());

return Ok(items);
}
Expand Down Expand Up @@ -361,7 +361,7 @@ public ActionResult GetAllProducts()
}

[HttpGet("[action]")]
public ActionResult GetOrderDetailsGrid(int OrderId)
public async Task<ActionResult> GetOrderDetailsGrid(int OrderId)
{
var orderDetails = (new OrderDetailsRepository(_context)).GetForOrder(OrderId);

Expand All @@ -373,12 +373,12 @@ public ActionResult GetOrderDetailsGrid(int OrderId)
.WithMultipleFilters()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

[HttpGet("[action]")]
public ActionResult GetOrderDetailsGridWithCrud(int OrderId)
public async Task<ActionResult> GetOrderDetailsGridWithCrud(int OrderId)
{
var orderDetails = (new OrderDetailsRepository(_context)).GetForOrder(OrderId);

Expand All @@ -390,12 +390,12 @@ public ActionResult GetOrderDetailsGridWithCrud(int OrderId)
.WithMultipleFilters()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

[HttpGet("[action]")]
public ActionResult GetOrderDetailsGridAllFeatures(int OrderId)
public async Task<ActionResult> GetOrderDetailsGridAllFeatures(int OrderId)
{
var orderDetails = (new OrderDetailsRepository(_context)).GetForOrder(OrderId);

Expand All @@ -407,12 +407,12 @@ public ActionResult GetOrderDetailsGridAllFeatures(int OrderId)
.WithMultipleFilters()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

[HttpGet("[action]")]
public ActionResult GetCustomersGrid()
public async Task<ActionResult> GetCustomersGrid()
{
var repository = new CustomersRepository(_context);
IGridServer<Customer> server = new GridCoreServer<Customer>(repository.GetAll(), Request.Query,
Expand All @@ -424,7 +424,7 @@ public ActionResult GetCustomersGrid()
.WithGridItemsCount()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

Expand Down Expand Up @@ -493,7 +493,7 @@ public async Task<ActionResult> Subtract1ToFreight(int id)
}

[HttpGet("[action]")]
public ActionResult GetEmployeesGrid()
public async Task<ActionResult> GetEmployeesGrid()
{
var repository = new EmployeeRepository(_context);
IGridServer<Employee> server = new GridCoreServer<Employee>(repository.GetAll(), Request.Query,
Expand All @@ -505,7 +505,7 @@ public ActionResult GetEmployeesGrid()
.WithGridItemsCount()
.SetRemoveDiacritics<NorthwindDbContext>("RemoveDiacritics");

var items = server.ItemsToDisplay;
var items = await server.GetItemsToDisplayAsync(async x => await x.ToListAsync());
return Ok(items);
}

Expand Down
Loading

0 comments on commit 08f372f

Please sign in to comment.