Skip to content

Commit 966c141

Browse files
authored
Add the project files
1 parent 0d66ad9 commit 966c141

33 files changed

+1563
-0
lines changed

App.razor

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
<Router AppAssembly="@typeof(Program).Assembly">
3+
<Found Context="routeData">
4+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
5+
</Found>
6+
<NotFound>
7+
<LayoutView Layout="@typeof(MainLayout)">
8+
<p>Sorry, there's nothing at this address.</p>
9+
</LayoutView>
10+
</NotFound>
11+
</Router>

Blazor_EditForm.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Syncfusion.Blazor" Version="18.2.0.44" />
9+
</ItemGroup>
10+
11+
</Project>

Blazor_EditForm.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29521.150
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor_EditForm", "Blazor_EditForm.csproj", "{70A8F420-9C60-4ACA-A43D-0C73F1FBBD77}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{70A8F420-9C60-4ACA-A43D-0C73F1FBBD77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{70A8F420-9C60-4ACA-A43D-0C73F1FBBD77}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{70A8F420-9C60-4ACA-A43D-0C73F1FBBD77}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{70A8F420-9C60-4ACA-A43D-0C73F1FBBD77}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3CA0B867-5E59-4C3E-8B5E-E720316C2750}
24+
EndGlobalSection
25+
EndGlobal

Data/EmployeeDetails.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.ComponentModel.DataAnnotations;
5+
using System.Runtime.CompilerServices;
6+
7+
namespace Blazor_EditForm.Data
8+
{
9+
/// <summary>
10+
/// Get the employee details
11+
/// </summary>
12+
public class EmployeeDetails
13+
{
14+
[Required]
15+
public string FirstName { get; set; }
16+
public string LastName { get; set; }
17+
[Required]
18+
[DataType(DataType.EmailAddress)]
19+
[EmailAddress]
20+
public string Email { get; set; }
21+
public string Gender { get; set; } = "male";
22+
[Required]
23+
[DataType(DataType.PhoneNumber)]
24+
[Phone]
25+
public string PhoneNumber { get; set; }
26+
[Required]
27+
public DateTime? DOB { get; set; }
28+
[Required]
29+
public string Country { get; set; }
30+
[Required]
31+
public string City { get; set; }
32+
[Required]
33+
public string Address { get; set; }
34+
[Required]
35+
[Range(0, 20, ErrorMessage = "The Experience range should be 0 to 20")]
36+
public decimal? TotalExperience { get; set; }
37+
}
38+
39+
public class Countries
40+
{
41+
public string Name { get; set; }
42+
public string Code { get; set; }
43+
44+
public List<Countries> GetCountries()
45+
{
46+
List<Countries> Country = new List<Countries>
47+
{
48+
new Countries() { Name = "Australia", Code = "AU" },
49+
new Countries() { Name = "United Kingdom", Code = "UK" },
50+
new Countries() { Name = "United States", Code = "US" },
51+
};
52+
return Country;
53+
}
54+
}
55+
public class Cities
56+
{
57+
public string Name { get; set; }
58+
public string Code { get; set; }
59+
public string CountryCode { get; set; }
60+
public List<Cities> GetCities()
61+
{
62+
List<Cities> CityName = new List<Cities>
63+
{
64+
new Cities() { Name = "New York", CountryCode = "US", Code="US-101" },
65+
new Cities() { Name = "Virginia", CountryCode = "US", Code="US-102" },
66+
new Cities() { Name = "Washington", CountryCode = "US", Code="US-103" },
67+
new Cities() { Name = "Victoria", CountryCode = "AU", Code="AU-101" },
68+
new Cities() { Name = "Tasmania", CountryCode = "AU", Code="AU-102" },
69+
new Cities() { Name = "Queensland", CountryCode = "AU", Code="AU-103" },
70+
new Cities() { Name = "London", CountryCode = "UK", Code="UK-101" },
71+
new Cities() { Name = "Manchester", CountryCode = "UK", Code="UK-102" },
72+
new Cities() { Name = "Ashford", CountryCode = "UK", Code="UK-103" }
73+
};
74+
return CityName;
75+
}
76+
}
77+
}

Data/WeatherForecast.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace Blazor_EditForm.Data
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}

Data/WeatherForecastService.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
5+
namespace Blazor_EditForm.Data
6+
{
7+
public class WeatherForecastService
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
15+
{
16+
var rng = new Random();
17+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
18+
{
19+
Date = startDate.AddDays(index),
20+
TemperatureC = rng.Next(-20, 55),
21+
Summary = Summaries[rng.Next(Summaries.Length)]
22+
}).ToArray());
23+
}
24+
}
25+
}

Pages/Counter.razor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/counter"
2+
3+
<h1>Counter</h1>
4+
5+
<p>Current count: @currentCount</p>
6+
7+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
8+
9+
@code {
10+
private int currentCount = 0;
11+
12+
private void IncrementCount()
13+
{
14+
currentCount++;
15+
}
16+
}

Pages/Error.razor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/error"
2+
3+
4+
<h1 class="text-danger">Error.</h1>
5+
<h2 class="text-danger">An error occurred while processing your request.</h2>
6+
7+
<h3>Development Mode</h3>
8+
<p>
9+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
10+
</p>
11+
<p>
12+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
13+
It can result in displaying sensitive information from exceptions to end users.
14+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
15+
and restarting the app.
16+
</p>

Pages/FetchData.razor

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@page "/fetchdata"
2+
3+
@using Blazor_EditForm.Data
4+
@inject WeatherForecastService ForecastService
5+
6+
<h1>Weather forecast</h1>
7+
8+
<p>This component demonstrates fetching data from a service.</p>
9+
10+
@if (forecasts == null)
11+
{
12+
<p><em>Loading...</em></p>
13+
}
14+
else
15+
{
16+
<table class="table">
17+
<thead>
18+
<tr>
19+
<th>Date</th>
20+
<th>Temp. (C)</th>
21+
<th>Temp. (F)</th>
22+
<th>Summary</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
@foreach (var forecast in forecasts)
27+
{
28+
<tr>
29+
<td>@forecast.Date.ToShortDateString()</td>
30+
<td>@forecast.TemperatureC</td>
31+
<td>@forecast.TemperatureF</td>
32+
<td>@forecast.Summary</td>
33+
</tr>
34+
}
35+
</tbody>
36+
</table>
37+
}
38+
39+
@code {
40+
private WeatherForecast[] forecasts;
41+
42+
protected override async Task OnInitializedAsync()
43+
{
44+
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
45+
}
46+
}

Pages/Index.razor

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
@page "/"
2+
@using Blazor_EditForm.Data
3+
<h1>Employee Details Form</h1>
4+
5+
<EditForm Model="@employeeDetails" OnValidSubmit="@Submit">
6+
<DataAnnotationsValidator />
7+
<div class="form-row">
8+
<div class="form-group col-md-6">
9+
<label class="col-form-label">First Name :</label>
10+
<SfTextBox @bind-Value="@employeeDetails.FirstName"></SfTextBox>
11+
<ValidationMessage For="@(() => employeeDetails.FirstName)"></ValidationMessage>
12+
</div>
13+
<div class="form-group col-md-6">
14+
<label class="col-form-label">Last Name :</label>
15+
<SfTextBox @bind-Value="@employeeDetails.LastName"></SfTextBox>
16+
<ValidationMessage For="@(() => employeeDetails.LastName)"></ValidationMessage>
17+
</div>
18+
</div>
19+
<div class="form-row">
20+
<div class="form-group col-md-6">
21+
<label class="col-form-label">Email ID :</label>
22+
<SfTextBox @bind-Value="@employeeDetails.Email"></SfTextBox>
23+
<ValidationMessage For="@(() => employeeDetails.Email)"></ValidationMessage>
24+
</div>
25+
<div class="form-group col-md-6">
26+
<label class="col-form-label">Phone Number :</label>
27+
<SfTextBox @bind-Value="@employeeDetails.PhoneNumber"></SfTextBox>
28+
<ValidationMessage For="@(() => employeeDetails.PhoneNumber)"></ValidationMessage>
29+
</div>
30+
</div>
31+
32+
<div class="form-row">
33+
<div class="form-group col-md-6">
34+
<label class="col-form-label">Date Of Birth :</label>
35+
<SfDatePicker @bind-Value="@employeeDetails.DOB" Max=DateTime.Now></SfDatePicker>
36+
<ValidationMessage For="@(() => employeeDetails.DOB)"></ValidationMessage>
37+
</div>
38+
<div class="form-group col-md-6">
39+
<label class="col-form-label">Total Experience :</label>
40+
<SfNumericTextBox @bind-Value="@employeeDetails.TotalExperience"></SfNumericTextBox>
41+
<ValidationMessage For="@(() => employeeDetails.TotalExperience)"></ValidationMessage>
42+
</div>
43+
</div>
44+
<div class="form-row">
45+
<div class="form-group col-md-6">
46+
<label class="col-form-label">Address :</label>
47+
<SfTextBox Multiline=true @bind-Value="@employeeDetails.Address"></SfTextBox>
48+
<ValidationMessage For="@(() => employeeDetails.Address)"></ValidationMessage>
49+
</div>
50+
<div class="form-group col-md-3">
51+
<label class="col-form-label">Gender :</label>
52+
<div>
53+
<SfRadioButton Label="Male" Name="Gender" Value="male" @bind-Checked="@employeeDetails.Gender"></SfRadioButton>
54+
<SfRadioButton TChecked="string" Label="Female" Name="Gender" Value="female" @bind-Checked="@employeeDetails.Gender"></SfRadioButton>
55+
</div>
56+
</div>
57+
58+
</div>
59+
<div class="form-row">
60+
<div class="form-group col-md-6">
61+
<label class="col-form-label">Country :</label>
62+
<SfComboBox TValue="string" TItem="Countries" @bind-Value="@employeeDetails.Country" DataSource="@countries">
63+
<ComboBoxFieldSettings Text="Name" Value="Code"></ComboBoxFieldSettings>
64+
<ComboBoxEvents TValue="string" ValueChange="ChangeCountry"></ComboBoxEvents>
65+
</SfComboBox>
66+
<ValidationMessage For="@(() => employeeDetails.Country)"></ValidationMessage>
67+
</div>
68+
<div class="form-group col-md-6">
69+
<label class="col-form-label">City :</label>
70+
<SfDropDownList Enabled="@enableCityDropDown" TValue="string" TItem="Cities" @bind-Value="@employeeDetails.City" Query="@CityQuery" DataSource="@cities">
71+
<DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings>
72+
</SfDropDownList>
73+
<ValidationMessage For="@(() => employeeDetails.City)"></ValidationMessage>
74+
</div>
75+
</div>
76+
<ValidationSummary />
77+
<div class="form-group">
78+
<SfButton Type="submit" IsPrimary=true>Save</SfButton>
79+
<SfButton Type="reset">Reset</SfButton>
80+
</div>
81+
</EditForm>
82+
83+
@code{
84+
EmployeeDetails employeeDetails;
85+
List<EmployeeDetails> EmployeeList= new List<EmployeeDetails>();
86+
List<Countries> countries;
87+
List<Cities> cities;
88+
bool enableCityDropDown;
89+
public Query CityQuery { get; set; } = null;
90+
91+
protected override void OnInitialized()
92+
{
93+
employeeDetails = new EmployeeDetails();
94+
countries = new Countries().GetCountries();
95+
cities = new Cities().GetCities();
96+
}
97+
public void ChangeCountry(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)
98+
{
99+
this.enableCityDropDown = true;
100+
this.CityQuery = new Query().Where(new WhereFilter() { Field = "CountryCode", Operator = "equal", value = args.Value, IgnoreCase = false, IgnoreAccent = false });
101+
this.employeeDetails.City = null;
102+
}
103+
104+
public void Submit()
105+
{
106+
EmployeeList.Add(employeeDetails);
107+
}
108+
}

0 commit comments

Comments
 (0)