Skip to content

Instantly share code, notes, and snippets.

@JIOO-phoeNIX
Created January 24, 2021 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JIOO-phoeNIX/33741d1f27f5ec0c93943dbb3193dc76 to your computer and use it in GitHub Desktop.
Save JIOO-phoeNIX/33741d1f27f5ec0c93943dbb3193dc76 to your computer and use it in GitHub Desktop.
@page "/EmployeeView"
@using GraphQLSampleAppUI.DataAccess;
@using GraphQLSampleAppUI.DataAccess.Model;
@inject NavigationManager NavigationManager
<h1>All Employee</h1>
<a href="/CreateEmployee">Create an Employee</a>
@if (AllEmployees.Count == 0)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Age</th>
<th>Department Name</th>
</tr>
</thead>
<tbody>
@foreach (var emp in AllEmployees)
{
<tr>
<td><a href="/ViewEmployee/@emp.EmployeeId">@emp.Name</a> </td>
<td>@emp.Email</td>
<td>@emp.Age</td>
<td>@emp.Department.Name</td>
</tr>
}
</tbody>
</table>
}
@code {
private List<Employee> AllEmployees = new List<Employee>();
protected override async Task OnInitializedAsync()
{
try
{
string completeQuery = "query{allEmployeeWithDepartment{name,age,departmentId,email,employeeId,department{name,departmentId}}}";
string graphQLQueryType = "allEmployeeWithDepartment";
var result = await Query.ExceuteQueryReturnListAsyn<Employee>(graphQLQueryType, completeQuery);
AllEmployees = result;
}
catch (Exception ex)
{
throw ex;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment