first commit
This commit is contained in:
1 parent
9533dee08e
commit
a477f17532
31 files changed
+1773
-1
No files matched your search
@@ -0,0 +1,105 @@
|
||||
@page "/employee"
|
||||
@using Newtonsoft.Json;
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject Microsoft.Extensions.Localization.IStringLocalizer<App> Localize
|
||||
|
||||
<h1>@Localize["Employee Data"]</h1>
|
||||
<br />
|
||||
<EditForm Model="@employee" OnSubmit="SaveEmployeeToLocalStorage">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-12">@Localize["Name"]</label>
|
||||
<input class="form-control" @bind="employee.Name" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-12">@Localize["Gender"]</label>
|
||||
<select class="form-control" @bind="employee.Gender">
|
||||
<option value="">@Localize["Select Gender"]</option>
|
||||
<option value="Male">@Localize["Male"]</option>
|
||||
<option value="Female">@Localize["Female"]</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-12">@Localize["City"]</label>
|
||||
<input class="form-control" @bind="employee.City" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-12">@Localize["Salary"]</label>
|
||||
<input type="number" class="form-control" @bind="employee.Salary" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</EditForm>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<table class='table'>
|
||||
<thead class="table-active">
|
||||
<tr>
|
||||
@foreach (string header in TableHeader)
|
||||
{
|
||||
<th>
|
||||
@Localize[header]
|
||||
</th>
|
||||
}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (Employee emp in lstEmployees)
|
||||
{
|
||||
<tr>
|
||||
<td>@emp.Name</td>
|
||||
<td>@Localize[emp.Gender]</td>
|
||||
<td>@emp.City</td>
|
||||
<td>@emp.Salary.ToString("C2")</td>
|
||||
<td>@emp.JoiningDate</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code{
|
||||
Employee employee = new Employee();
|
||||
List<Employee> lstEmployees = new List<Employee>();
|
||||
|
||||
string[] TableHeader = { "Name", "Gender", "City", "Salary", "Joining Date" };
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var empGetJS = (IJSInProcessRuntime)JSRuntime;
|
||||
var empList = await empGetJS.InvokeAsync<string>("employeeData.get");
|
||||
FetchEmployeeFromLocalStorage(empList);
|
||||
}
|
||||
|
||||
void SaveEmployeeToLocalStorage()
|
||||
{
|
||||
employee.JoiningDate = DateTime.Now;
|
||||
lstEmployees.Add(employee);
|
||||
var empSetJS = (IJSInProcessRuntime)JSRuntime;
|
||||
empSetJS.InvokeVoid("employeeData.set", JsonConvert.SerializeObject(lstEmployees));
|
||||
employee = new Employee();
|
||||
}
|
||||
|
||||
void FetchEmployeeFromLocalStorage(string empList)
|
||||
{
|
||||
if (empList != null)
|
||||
{
|
||||
lstEmployees = JsonConvert.DeserializeObject<List<Employee>>(empList);
|
||||
}
|
||||
}
|
||||
|
||||
class Employee
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Gender { get; set; }
|
||||
public string City { get; set; }
|
||||
public int Salary { get; set; }
|
||||
public DateTime JoiningDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
@page "/"
|
||||
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
Welcome to your new app.
|
||||
|
||||
<SurveyPrompt Title="How is Blazor working for you?" />
|
||||
@@ -0,0 +1,37 @@
|
||||
@using System.Globalization
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<div class="col-md-3">
|
||||
<select class="form-control" @bind="Culture">
|
||||
@foreach (var language in supportedLanguages)
|
||||
{
|
||||
<option value="@language">@language.DisplayName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
CultureInfo[] supportedLanguages = new[]
|
||||
{
|
||||
new CultureInfo("en-US"),
|
||||
new CultureInfo("fr-FR"),
|
||||
new CultureInfo("ar-AE"),
|
||||
};
|
||||
|
||||
CultureInfo Culture
|
||||
{
|
||||
get => CultureInfo.CurrentCulture;
|
||||
set
|
||||
{
|
||||
if (CultureInfo.CurrentCulture != value)
|
||||
{
|
||||
var js = (IJSInProcessRuntime)JSRuntime;
|
||||
js.InvokeVoid("appCulture.set", value.Name);
|
||||
|
||||
Nav.NavigateTo(Nav.Uri, forceLoad: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user