Skip to content

Commit

Permalink
Change query to get items for Read and Delete forms
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavnavar committed Oct 26, 2020
1 parent c5c3480 commit be59643
Showing 1 changed file with 53 additions and 24 deletions.
77 changes: 53 additions & 24 deletions GridBlazor/Pages/GridComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private async Task GoToCrudView()
else if (Mode == GridMode.Read)
{
var item = await ((CGrid<T>)Grid).CrudDataService.Get(Keys);
ReadHandler(item);
await ReadHandler(item);
}
else if (Mode == GridMode.Update)
{
Expand All @@ -330,7 +330,7 @@ private async Task GoToCrudView()
else if (Mode == GridMode.Delete)
{
var item = await ((CGrid<T>)Grid).CrudDataService.Get(Keys);
DeleteHandler(item);
await DeleteHandler(item);
}
}
}
Expand Down Expand Up @@ -620,25 +620,40 @@ private void CreateHndlr()
StateHasChanged();
}

public void ReadHandler(object item)
public async Task ReadHandler(object item)
{
_item = (T)item;
((CGrid<T>)Grid).Mode = GridMode.Read;
if (Grid.ReadComponent != null)
CrudRender = ReadCrudComponent();
else
CrudRender = null;
var keys = Grid.GetPrimaryKeyValues(item);
await ReadHandler(keys);
}

_shouldRender = true;
StateHasChanged();
public async Task ReadHandler(object[] keys)
{
try
{
_item = await ((CGrid<T>)Grid).CrudDataService.Get(keys);
((CGrid<T>)Grid).Mode = GridMode.Read;
if (Grid.ReadComponent != null)
CrudRender = ReadCrudComponent();
else
CrudRender = null;

_shouldRender = true;
StateHasChanged();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
((CGrid<T>)Grid).Mode = GridMode.Grid;
throw;
}
}

public void ReadSelectedHandler()
public async Task ReadSelectedHandler()
{
if (SelectedRow != -1)
{
var item = Grid.ItemsToDisplay.ElementAt(SelectedRow);
ReadHandler(item);
await ReadHandler(item);
}
else
ShowError(Strings.SelectionReadError);
Expand Down Expand Up @@ -700,25 +715,39 @@ public async Task UpdateSelectedHandler()
ShowError(Strings.SelectionUpdateError);
}

public void DeleteHandler(object item)
public async Task DeleteHandler(object item)
{
_item = (T)item;
((CGrid<T>)Grid).Mode = GridMode.Delete;
if (Grid.DeleteComponent != null)
CrudRender = DeleteCrudComponent();
else
CrudRender = null;
var keys = Grid.GetPrimaryKeyValues(item);
await DeleteHandler(keys);
}
public async Task DeleteHandler(object[] keys)
{
try
{
_item = await ((CGrid<T>)Grid).CrudDataService.Get(keys);
((CGrid<T>)Grid).Mode = GridMode.Delete;
if (Grid.DeleteComponent != null)
CrudRender = DeleteCrudComponent();
else
CrudRender = null;

_shouldRender = true;
StateHasChanged();
_shouldRender = true;
StateHasChanged();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
((CGrid<T>)Grid).Mode = GridMode.Grid;
throw;
}
}

public void DeleteSelectedHandler()
public async Task DeleteSelectedHandler()
{
if (SelectedRow != -1)
{
var item = Grid.ItemsToDisplay.ElementAt(SelectedRow);
DeleteHandler(item);
await DeleteHandler(item);
}
else
ShowError(Strings.SelectionDeleteError);
Expand Down

0 comments on commit be59643

Please sign in to comment.