Skip to content

Commit

Permalink
Merge pull request #2 from Backiaraj/common
Browse files Browse the repository at this point in the history
Added missing files and updated the sample for edit form validation
  • Loading branch information
rajendranr-5483 authored Jul 16, 2024
2 parents ce9c8c7 + f140883 commit f1d8ad7
Show file tree
Hide file tree
Showing 33 changed files with 1,239 additions and 118 deletions.
6 changes: 3 additions & 3 deletions App.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</Router>
14 changes: 14 additions & 0 deletions Blazor_EditForm.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Blazor" Version="25.2.7" />
<PackageReference Include="Syncfusion.Blazor.Themes" Version="25.2.7" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions Blazor_EditForm.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor_EditForm", "Blazor_EditForm.csproj", "{DC1EFAC9-1F6C-46C4-9B25-F3C80A03CD1B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DC1EFAC9-1F6C-46C4-9B25-F3C80A03CD1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC1EFAC9-1F6C-46C4-9B25-F3C80A03CD1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC1EFAC9-1F6C-46C4-9B25-F3C80A03CD1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC1EFAC9-1F6C-46C4-9B25-F3C80A03CD1B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Data/EmployeeDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;

namespace EditFormValidation.Data
namespace Blazor_EditForm.Data
{
/// <summary>
/// Get the employee details
Expand Down
15 changes: 7 additions & 8 deletions Data/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
namespace EditFormValidation.Data
namespace Blazor_EditForm.Data;

public class WeatherForecast
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public DateOnly Date { get; set; }

public int TemperatureC { get; set; }
public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string? Summary { get; set; }
}
public string? Summary { get; set; }
}
23 changes: 11 additions & 12 deletions Data/WeatherForecastService.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
namespace EditFormValidation.Data
namespace Blazor_EditForm.Data;

public class WeatherForecastService
{
public class WeatherForecastService
private static readonly string[] Summaries = new[]
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
}
17 changes: 0 additions & 17 deletions EditFormValidation.csproj

This file was deleted.

25 changes: 0 additions & 25 deletions EditFormValidation.sln

This file was deleted.

19 changes: 19 additions & 0 deletions Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@page "/counter"

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
private int currentCount = 0;

private void IncrementCount()
{
currentCount++;
}

}
52 changes: 26 additions & 26 deletions Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
@page
@model EditFormValidation.Pages.ErrorModel
@model Blazor_EditForm.Pages.ErrorModel

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>Error</title>
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet"/>
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true"/>
</head>

<body>
<div class="main">
<div class="content px-4">
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
<div class="main">
<div class="content px-4">
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
@if (Model.ShowRequestId)
{
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
</div>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
</div>
</div>
</body>

</html>
</html>
35 changes: 17 additions & 18 deletions Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace EditFormValidation.Pages
namespace Blazor_EditForm.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;
private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
50 changes: 50 additions & 0 deletions Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@page "/fetchdata"
@using Blazor_EditForm.Data
@inject WeatherForecastService ForecastService

<PageTitle>Weather forecast</PageTitle>

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from a service.</p>

@if (forecasts == null)
{
<p>
<em>Loading...</em>
</p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}

@code {
private WeatherForecast[]? forecasts;

protected override async Task OnInitializedAsync()
{
forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
}

}
Loading

0 comments on commit f1d8ad7

Please sign in to comment.