Skip to content

Commit a4f4f9e

Browse files
committed
Updated the Blazor common UG documentation
1 parent c7f3c43 commit a4f4f9e

File tree

2 files changed

+64
-66
lines changed

2 files changed

+64
-66
lines changed

blazor/tutorials/build-a-blazor-stay-reservation-app.md

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
---
22
layout: post
3-
title: Build a Blazor Stay Reservation App - Syncfusion
4-
description: Step by step tutorial to build a Blazor Stay Reservation Application using Syncfusion Blazor components.
3+
title: Build a Blazor stay reservation app - Syncfusion
4+
description: Learn here about step-by-step tutorial to build a Blazor stay reservation application using Syncfusion Blazor components like Scheduler, Sidebar, and Toast.
55
platform: Blazor
6-
component: Tutorials
6+
control: Tutorials
77
documentation: ug
88
---
99

10-
# Build a Blazor Stay Reservation App with Syncfusion® Blazor Components
10+
# Build a Blazor stay reservation app with Syncfusion® Blazor components
1111

12-
In this tutorial, we'll walk through the process of building a "Stay Reservation" application. This demonstrates how to use the **Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Scheduler** component as the centerpiece of a booking system, complete with filtering, booking form and a responsive layout.
12+
This tutorial explains how to build a stay reservation application. It demonstrates how to use the **Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Scheduler** component as the centerpiece of a booking system, with filtering, a booking form, and a responsive layout.
13+
14+
By the end of this tutorial, the reader will be able to:
15+
* Set up a Blazor project with Syncfusion<sup style="font-size:70%">&reg;</sup> components.
16+
* Configure the Blazor Scheduler for a reservation system.
17+
* Manage application state using a dependency-injected service.
18+
* Build a filterable sidebar with checkboxes and accordions.
19+
* Combine multiple components to create a polished application.
1320

14-
By the end of this tutorial, you will have learned how to:
15-
* Set up a Blazor project with Syncfusion<sup style="font-size:70%">&reg;</sup> components.
16-
* Configure the Blazor Scheduler for a reservation system.
17-
* Manage application state using a dependency-injected service.
18-
* Build a filterable sidebar with Checkboxes and Accordions.
19-
* Combine multiple components to create a polished, final application.
2021

21-
Let's get started!
2222

2323
## Prerequisites
2424

2525
* [System requirements for Blazor components](https://blazor.syncfusion.com/documentation/system-requirements)
2626

2727
## Create the Blazor Web App
2828

29-
First, let's create a new Blazor Web App.
29+
Create a new Blazor Web App.
3030

3131
```bash
3232
dotnet new blazor -o StayReservation
3333
cd StayReservation
3434
```
3535

36-
Choose the "Blazor Web App" template. For this project, we'll use the **Interactive Server** render mode for simplicity.
36+
Choose the "Blazor Web App" template. For this project, use the **Interactive Server** render mode for simplicity.
3737

38-
## Add and Configure Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Components
38+
## Add and configure Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor components
3939

40-
Next, we need to add the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor libraries to our project. We'll need packages for the Scheduler, navigation elements (like the Sidebar and Accordion), and various input components.
40+
Next, add the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor libraries to the project. Packages are required for the Scheduler, navigation elements (such as Sidebar and Accordion), and input components.
4141

4242
Install the essential Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor NuGet packages:
4343

@@ -47,20 +47,20 @@ dotnet add package Syncfusion.Blazor.Notifications
4747
dotnet add package Syncfusion.Blazor.Themes
4848
```
4949

50-
Now, let's configure the app to recognize and style the Syncfusion<sup style="font-size:70%">&reg;</sup> components.
50+
Configure the app to recognize and style the Syncfusion<sup style="font-size:70%">&reg;</sup> components.
5151

52-
1. **Register Syncfusion<sup style="font-size:70%">&reg;</sup> Services**
52+
1. **Register Syncfusion<sup style="font-size:70%">&reg;</sup> services**
5353

54-
In your `Program.cs` file, register the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor service.
54+
In `Program.cs`, register the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor service.
5555

5656
```csharp
5757
// Add the following line before builder.Build()
5858
builder.Services.AddSyncfusionBlazor();
5959
```
6060

61-
2. **Add Theme and Script References**
61+
2. **Add theme and script references**
6262

63-
Open `Components/App.razor`. We need to add the Syncfusion<sup style="font-size:70%">&reg;</sup> theme stylesheet and the necessary script reference for component interactivity. We'll use the modern `tailwind.css` theme.
63+
Open `Components/App.razor`. Add the Syncfusion<sup style="font-size:70%">&reg;</sup> theme stylesheet and the script reference for component interactivity. The example uses the `tailwind.css` theme.
6464

6565
```html
6666
<!DOCTYPE html>
@@ -86,9 +86,9 @@ Now, let's configure the app to recognize and style the Syncfusion<sup style="fo
8686
</html>
8787
```
8888

89-
3. **Add Namespace Imports**
89+
3. **Add namespace imports**
9090

91-
To avoid having to add `@using` directives in every component, add the most common Syncfusion<sup style="font-size:70%">&reg;</sup> namespaces to your `_Imports.razor` file.
91+
To avoid adding `@using` directives in each component, add the commonly used Syncfusion<sup style="font-size:70%">&reg;</sup> namespaces to the `_Imports.razor` file.
9292

9393
```csharp
9494
@using StayReservation
@@ -101,7 +101,9 @@ Now, let's configure the app to recognize and style the Syncfusion<sup style="fo
101101
@using Syncfusion.Blazor.DropDowns
102102
```
103103

104-
## Define the Data and State Management Service
104+
## Define the data and state management service
105+
106+
A real-world app needs a way to manage its data and state. Create an `AppointmentService` to act as a central hub for reservation data and UI state. Inject this service into components that need to share information.
105107

106108
A real-world app needs a way to manage its data and state. For this, we'll create an `AppointmentService` to act as a central hub for our reservation data and UI state. This service will be injected into the components that need to share information.
107109

@@ -141,7 +143,7 @@ public class AppointmentData
141143
}
142144
```
143145

144-
Now, create the `AppointmentService.cs` in the `Data` folder. This service will hold the appointment list and references to our components.
146+
Create `AppointmentService.cs` in the `Data` folder. This service holds the appointment list and references to components.
145147

146148
The complete code for `AppointmentService.cs` is available in the GitHub repository at the following link: [`AppointmentService.cs`](https://github.com/syncfusion/blazor-showcase-stay-reservation/blob/master/webapp/Stay-Reservation/Data/AppointmentService.cs). You may reuse the full code as needed.
147149

@@ -169,14 +171,13 @@ Register this service as a singleton in `Program.cs`:
169171
builder.Services.AddSingleton<AppointmentService>();
170172
```
171173

172-
## Build the UI Components
174+
## Build the UI components
173175

174-
Our application has three main UI parts: the sidebar for calendar date navigation and filtering the rooms (`Sidebar.razor`), the scheduler view (`Schedule.razor`), and the main page (`Index.razor`) that puts it all together.
176+
The application has three main UI parts: the sidebar for calendar date navigation and filtering rooms (`Sidebar.razor`), the scheduler view (`Schedule.razor`), and the main page (`Index.razor`) that assembles them.
175177

176178
### The Filtering Sidebar (`Sidebar.razor`)
177179

178-
This component uses an `<SfSidebar>` to contain calendar and filters. An `<SfCalendar>`allows the user to select the date desired date in scheduler.
179-
An `<SfAccordion>` organizes the filters, `<SfCheckBox>` component used to controls which floors are displayed. `<SfSlider>` is used to filter the price range.
180+
This component uses an `<SfSidebar>` to contain the calendar and filters. An `<SfCalendar>` allows the user to select the desired date in the scheduler. An `<SfAccordion>` organizes the filters, `<SfCheckBox>` component which floors are displayed. `<SfSlider>` filters the price range.
180181

181182
```html
182183
@using StayReservation.Data
@@ -242,15 +243,15 @@ When a checkbox is clicked, its state is updated in the `AppointmentService`. We
242243

243244
### The Scheduler View (`Schedule.razor`)
244245

245-
This is the core of our application. Here, we'll configure the `<SfSchedule>` component to display reservations grouped by floor.
246+
This is the core of the application. Configure the `<SfSchedule>` component to display reservations grouped by floor.
246247

247-
First, let's create a new file: `Components/Pages/Schedule.razor`.
248+
Create a new file: `Components/Pages/Schedule.razor`.
248249

249250
The Scheduler needs two main pieces of data:
250251
1. A list of **resources**—in our case, the hotel floors.
251252
2. A list of **events** (or appointments)—the actual reservations.
252253

253-
The appointment and resource data will come from `AppointmentService`.
254+
The appointment and resource data come from `AppointmentService`.
254255

255256
The complete code for `Schedule.razor` is available in the GitHub repository at the following link: [`Schedule.razor`](https://github.com/syncfusion/blazor-showcase-stay-reservation/blob/master/webapp/Stay-Reservation/Components/Pages/Schedule.razor). You may reuse the full code as needed.
256257

@@ -311,14 +312,14 @@ The complete code for `Schedule.razor` is available in the GitHub repository at
311312
```
312313

313314
Key configuration points:
314-
* `<ScheduleEventSettings>`: Binds the scheduler's events to the list in our `AppointmentService`.
315-
* `<ScheduleGroup>`: We tell the scheduler to group by the resource named "Floors".
316-
* `<ScheduleResource>`: We define our "Floors" resource. This maps the `FloorId` field in our `AppointmentData` to the `FloorId` in our `floorData` list, automatically assigning colors and text to the resource groups headers.
317-
* `<ScheduleTemplates>`: We use templates to customize the date header, cell, and resource header.
315+
* `<ScheduleEventSettings>`: Binds the scheduler's events to the list in `AppointmentService`.
316+
* `<ScheduleGroup>`: Groups by the resource named "Floors".
317+
* `<ScheduleResource>`: Defines the "Floors" resource. This maps the `FloorId` field in `AppointmentData` to the `FloorId` in the `floorData` list, assigning colors and text to resource group headers.
318+
* `<ScheduleTemplates>`: Uses templates to customize the date header, cell, and resource header.
318319

319320
## Assemble the Main Page
320321

321-
Now, let's bring it all together in the main `Index.razor` page. This component will host the sidebar and the schedule, along with a header to control the UI.
322+
Bring it together in the main `Index.razor` page. This component hosts the sidebar and the schedule, along with a header to control the UI.
322323

323324
Update `Components/Pages/Index.razor` with the following code:
324325

@@ -346,11 +347,11 @@ Update `Components/Pages/Index.razor` with the following code:
346347
</div>
347348
```
348349

349-
## Implement the Filtering Logic
350+
## Implement the filtering logic
350351

351-
We need to connect the checkboxes in the sidebar to the data displayed in the scheduler. Since we're using our `AppointmentService` to hold the state, we can detect changes to the checkbox values and re-filter the scheduler's resource data. Can bind the change event to checkbox and sliders to form the filter query and update the resource data.
352+
Connect the checkboxes in the sidebar to the data displayed in the scheduler. Since `AppointmentService` holds the state, detect changes to the checkbox and slider values, form the filter query, and update the resource data.
352353

353-
Refer the following code to implement the filtering logic in `Components/Pages/Sidebar.razor`:
354+
Use the following code to implement the filtering logic in `Components/Pages/Sidebar.razor`:
354355

355356
The complete code for `Sidebar.razor` is available in the GitHub repository at the following link: [`Sidebar.razor`](https://github.com/syncfusion/blazor-showcase-stay-reservation/blob/master/webapp/Stay-Reservation/Components/Pages/Sidebar.razor). You may reuse the full code as needed.
356357

@@ -425,16 +426,16 @@ The complete code for `Sidebar.razor` is available in the GitHub repository at t
425426
}
426427
```
427428

428-
Now, whenever a user clicks a checkbox, it triggers the `OnChange` event, which calls the `FloorHandler` method. This method updates the `ResourceQuery` property on the `Service` object, which is used to filter the resources in the scheduler. The `StateChanged` method is called to refresh the scheduler with the new resource data.
429+
When a user clicks a checkbox, it triggers the `OnChange` event, which calls the `FloorHandler` method. This method updates the `ResourceQuery` property on the `Service` object to filter resources in the scheduler. The `StateChanged` method refreshes the scheduler with the new resource data.
429430

430-
Build and run the app by executing the `dotnet watch run`command in the command shell from the `StayReservation` folder.
431+
Build and run the app by executing the `dotnet watch run` command in the command shell from the `StayReservation` folder.
431432

432-
## Implement the Appointment Booking form
433-
Bind the Scheduler's Editor Template to a custom form for creating and editing appointments. This form will include fields for the appointment's subject, start and end times, and a dropdown list for selecting the room. The form will be displayed when a user double clicks on an empty cell in the scheduler or on an existing appointment. The form will be displayed in a popup window.
433+
## Implement the appointment booking form
434+
Bind the Scheduler's Editor Template to a custom form for creating and editing appointments. This form includes fields for the appointment subject, start and end times, and a drop-down list for selecting the room. The form is displayed when a user double-clicks an empty cell in the scheduler or an existing appointment, in a popup window.
434435

435-
We can validate the form fields using the `ValidationMessage` component. The `ValidationMessage` component displays an error message when the validation fails. The `ValidationMessage` component is bound to the `Subject` property of the `AppointmentData` object. The `Subject` property is required, so the `ValidationMessage` component displays an error message when the `Subject` property is empty.
436+
Validate the form fields using the `ValidationMessage` component. The `ValidationMessage` component displays an error message when validation fails. It is bound to the `Subject` property of the `AppointmentData` object, which is required, so an error message appears when the `Subject` property is empty.
436437

437-
We can apply the following code to the `Schedule.razor` file to create the custom form.
438+
Apply the following code to the `Schedule.razor` file to create the custom form.
438439

439440
```html
440441
<SfSchedule>
@@ -555,19 +556,19 @@ We can apply the following code to the `Schedule.razor` file to create the custo
555556
</ScheduleTemplates>
556557
</SfSchedule>
557558
```
558-
More details about editor template can be found in the [Editor Template](https://blazor.syncfusion.com/documentation/scheduler/editor-template#customizing-event-editor-using-template) documentation.
559+
More details about the editor template are available in the [Editor Template](https://blazor.syncfusion.com/documentation/scheduler/editor-template#customizing-event-editor-using-template) documentation.
559560
560-
## Adding Toast Notifications
561+
## Add toast notifications
561562

562-
Integrate `SfToast` for user notifications throughout the application. When a user creates or deletes a reservation, a toast notification will appear.
563+
Integrate `SfToast` for user notifications throughout the application. When a user creates or deletes a reservation, a toast notification appears.
563564

564565
```csharp
565566
<SfToast ID="toast_default" @ref="Service.ToastObj" Content="@Service.ToastContent" Timeout="5000" Icon="e-meeting" ShowCloseButton="true" Height="70px" Width="400px">
566567
<ToastPosition X="@Service.ToastPositionXValue" Y="@Service.ToastPositionYValue"></ToastPosition>
567568
</SfToast>
568569
```
569570

570-
The `OnActionBegin` event of the `SfSchedule` component can be bound to a method that will handle the toast notifications.
571+
Bind the `OnActionBegin` event of the `SfSchedule` component to a method that handles toast notifications.
571572

572573
```csharp
573574
public async Task OnActionBegin(ActionEventArgs<AppointmentData> args)
@@ -620,12 +621,12 @@ The `OnActionBegin` event of the `SfSchedule` component can be bound to a method
620621

621622
## GitHub and demo references
622623

623-
The complete code for this example is available in the [GitHub repository](https://github.com/syncfusion/blazor-showcase-stay-reservation).
624+
The complete code for this example is available in the GitHub repository: https://github.com/syncfusion/blazor-showcase-stay-reservation
624625
625-
A demo of this example can be tried in [this link](https://blazor.syncfusion.com/showcase/stay-reservation).
626+
Try the live demo: https://blazor.syncfusion.com/showcase/stay-reservation
626627
627628
## Summary
628629

629-
This guide has demonstrated how to build a functional and interactive stay reservation application. It has shown how to compose a complex UI by combining multiple Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor components like the **Scheduler**, **Sidebar**, **AppBar**, **Accordion**, **Inputs**, and **Dropdowns**.
630+
This guide demonstrates how to build a functional and interactive stay reservation application. It shows how to compose a complex UI by combining Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor components such as **Scheduler**, **Sidebar**, **AppBar**, **Accordion**, **Inputs**, and **DropDowns**.
630631

631-
Most importantly, a clean state management pattern has been implemented using a singleton service, allowing the components to communicate and share data seamlessly. This architecture is scalable and makes the application easy to maintain and extend with new features.
632+
A clean state management pattern is implemented using a singleton service, allowing the components to communicate and share data seamlessly. This architecture is scalable and makes the application easier to maintain and extend with new features.

0 commit comments

Comments
 (0)