Skip to content

Commit 04ceb8d

Browse files
Blazor Scheduler Getting Started Example Committed.
1 parent 369a946 commit 04ceb8d

30 files changed

+1376
-0
lines changed

App.razor

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

Data/WeatherForecast.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace my_blazor_scheduler.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

+25
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 my_blazor_scheduler.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

+16
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

+16
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

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@page "/fetchdata"
2+
3+
@using my_blazor_scheduler.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

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@page "/"
2+
@using Syncfusion.EJ2.Blazor.Schedule
3+
4+
<EjsSchedule TValue="AppointmentData" SelectedDate="@(new DateTime(2020, 1, 10))" CurrentView="View.Month">
5+
<ScheduleViews>
6+
<ScheduleView Option="View.Day" StartHour="07:00" EndHour="15:00"></ScheduleView>
7+
<ScheduleView Option="View.Week" StartHour="10:00" EndHour="18:00"></ScheduleView>
8+
<ScheduleView Option="View.Month" ShowWeekend="false"></ScheduleView>
9+
</ScheduleViews>
10+
<ScheduleEventSettings DataSource="@DataSource">
11+
<ScheduleField Id="EventID">
12+
<FieldSubject Name="EventSubject"></FieldSubject>
13+
<FieldStartTime Name="EventStart"></FieldStartTime>
14+
<FieldEndTime Name="EventEnd"></FieldEndTime>
15+
</ScheduleField>
16+
</ScheduleEventSettings>
17+
18+
@*For remote data, uncomment and make use of the below ScheduleEventSettings and remove the previous ScheduleEventSettings*@
19+
@*<ScheduleEventSettings TValue="AppointmentData">
20+
<EjsDataManager Url="https://js.syncfusion.com/demos/ejservices/api/Schedule/LoadData" Adaptor="@Syncfusion.EJ2.Blazor.Adaptors.WebApiAdaptor">
21+
</EjsDataManager>
22+
</ScheduleEventSettings>*@
23+
24+
</EjsSchedule>
25+
26+
@code{
27+
List<AppointmentData> DataSource = new List<AppointmentData>
28+
{
29+
new AppointmentData { EventID = 1, EventSubject = "Paris", EventStart = new DateTime(2020, 1, 10, 10, 0, 0) , EventEnd = new DateTime(2020, 1, 10, 12, 0, 0) },
30+
new AppointmentData { EventID = 2, EventSubject = "Germany", EventStart = new DateTime(2020, 1, 13, 10, 0, 0) , EventEnd = new DateTime(2020, 1, 13, 12, 0, 0) }
31+
};
32+
public class AppointmentData
33+
{
34+
@*Change the below field names to default field name values like Id, Subject, StartTime and EndTime, while binding the above remote url service to the Scheduler*@
35+
public int EventID { get; set; }
36+
public string EventSubject { get; set; }
37+
public DateTime EventStart { get; set; }
38+
public DateTime EventEnd { get; set; }
39+
}
40+
}

Pages/_Host.cshtml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@page "/"
2+
@namespace my_blazor_scheduler.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10+
<title>my-blazor-scheduler</title>
11+
<base href="~/" />
12+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
13+
<link href="css/site.css" rel="stylesheet" />
14+
<link href="https://cdn.syncfusion.com/ej2/17.4.49/material.css" rel="stylesheet" />
15+
<script src="https://cdn.syncfusion.com/ej2/17.4.49/dist/ej2.min.js"></script>
16+
<script src="https://cdn.syncfusion.com/ej2/17.4.49/dist/ejs.interop.min.js"></script>
17+
18+
</head>
19+
<body>
20+
<app>
21+
<component type="typeof(App)" render-mode="ServerPrerendered" />
22+
</app>
23+
24+
<div id="blazor-error-ui">
25+
<environment include="Staging,Production">
26+
An error has occurred. This application may no longer respond until reloaded.
27+
</environment>
28+
<environment include="Development">
29+
An unhandled exception has occurred. See browser dev tools for details.
30+
</environment>
31+
<a href class="reload">Reload</a>
32+
<a class="dismiss">🗙</a>
33+
</div>
34+
35+
<script src="_framework/blazor.server.js"></script>
36+
</body>
37+
</html>

Program.cs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Hosting;
10+
using Microsoft.Extensions.Logging;
11+
12+
namespace my_blazor_scheduler
13+
{
14+
public class Program
15+
{
16+
public static void Main(string[] args)
17+
{
18+
CreateHostBuilder(args).Build().Run();
19+
}
20+
21+
public static IHostBuilder CreateHostBuilder(string[] args) =>
22+
Host.CreateDefaultBuilder(args)
23+
.ConfigureWebHostDefaults(webBuilder =>
24+
{
25+
webBuilder.UseStartup<Startup>();
26+
});
27+
}
28+
}

Properties/launchSettings.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:42803",
7+
"sslPort": 44349
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"my-blazor-scheduler": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
}
25+
}
26+
}
27+
}

Shared/MainLayout.razor

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<div class="main">
8+
<div class="top-row px-4">
9+
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
10+
</div>
11+
12+
<div class="content px-4">
13+
@Body
14+
</div>
15+
</div>

Shared/NavMenu.razor

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div class="top-row pl-4 navbar navbar-dark">
2+
<a class="navbar-brand" href="">my-blazor-scheduler</a>
3+
<button class="navbar-toggler" @onclick="ToggleNavMenu">
4+
<span class="navbar-toggler-icon"></span>
5+
</button>
6+
</div>
7+
8+
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
9+
<ul class="nav flex-column">
10+
<li class="nav-item px-3">
11+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
12+
<span class="oi oi-home" aria-hidden="true"></span> Home
13+
</NavLink>
14+
</li>
15+
<li class="nav-item px-3">
16+
<NavLink class="nav-link" href="counter">
17+
<span class="oi oi-plus" aria-hidden="true"></span> Counter
18+
</NavLink>
19+
</li>
20+
<li class="nav-item px-3">
21+
<NavLink class="nav-link" href="fetchdata">
22+
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
23+
</NavLink>
24+
</li>
25+
</ul>
26+
</div>
27+
28+
@code {
29+
private bool collapseNavMenu = true;
30+
31+
private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
32+
33+
private void ToggleNavMenu()
34+
{
35+
collapseNavMenu = !collapseNavMenu;
36+
}
37+
}

Startup.cs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Components;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.HttpsPolicy;
9+
using Microsoft.Extensions.Configuration;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
12+
using my_blazor_scheduler.Data;
13+
using Syncfusion.EJ2.Blazor;
14+
15+
namespace my_blazor_scheduler
16+
{
17+
public class Startup
18+
{
19+
public Startup(IConfiguration configuration)
20+
{
21+
Configuration = configuration;
22+
}
23+
24+
public IConfiguration Configuration { get; }
25+
26+
// This method gets called by the runtime. Use this method to add services to the container.
27+
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
28+
public void ConfigureServices(IServiceCollection services)
29+
{
30+
services.AddRazorPages();
31+
services.AddServerSideBlazor();
32+
services.AddSingleton<WeatherForecastService>();
33+
services.AddSyncfusionBlazor();
34+
}
35+
36+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
37+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
38+
{
39+
// Provide your license key here
40+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Your License Key");
41+
42+
if (env.IsDevelopment())
43+
{
44+
app.UseDeveloperExceptionPage();
45+
}
46+
else
47+
{
48+
app.UseExceptionHandler("/Error");
49+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
50+
app.UseHsts();
51+
}
52+
53+
app.UseHttpsRedirection();
54+
app.UseStaticFiles();
55+
56+
app.UseRouting();
57+
58+
app.UseEndpoints(endpoints =>
59+
{
60+
endpoints.MapBlazorHub();
61+
endpoints.MapFallbackToPage("/_Host");
62+
});
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)