Load Appointments on Demand via Web Services in .NET MAUI Scheduler Using JSON Data
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (181).NET Core  (28).NET MAUI  (227)Angular  (113)ASP.NET  (49)ASP.NET Core  (81)ASP.NET MVC  (87)Azure  (42)Black Friday Deal  (1)Blazor  (236)BoldSign  (14)DocIO  (24)Essential JS 2  (110)Essential Studio  (200)File Formats  (73)Flutter  (136)JavaScript  (226)Microsoft  (122)PDF  (83)Python  (1)React  (105)Streamlit  (1)Succinctly series  (131)Syncfusion  (964)TypeScript  (33)Uno Platform  (3)UWP  (3)Vue  (46)Webinar  (53)Windows Forms  (59)WinUI  (72)WPF  (163)Xamarin  (159)XlsIO  (38)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (11)Business intelligence  (55)Button  (4)C#  (164)Chart  (147)Chart of the week  (58)Cloud  (15)Company  (440)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (73)Development  (681)Doc  (7)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (7)Essential Tools  (13)Excel  (43)Extensions  (23)File Manager  (7)Gantt  (21)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (522)Mobile MVC  (9)OLAP server  (2)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (45)Performance  (13)PHP  (2)PivotGrid  (5)Predictive Analytics  (6)Report Server  (3)Reporting  (8)Reporting / Back Office  (9)Rich Text Editor  (12)Road Map  (12)Scheduler  (54)Security  (5)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (32)Solution Services  (4)Spreadsheet  (11)SQL  (15)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (406)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (628)What's new  (341)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Load Appointments on Demand Via Web Services in .NET MAUI Scheduler using JSON Data

Load Appointments on Demand via Web Services in .NET MAUI Scheduler Using JSON Data

The .NET MAUI Scheduler provides all the scheduling functionalities to create and manage professional and personal appointments. This blog explains how to load appointments on demand in the .NET MAUI Scheduler control via web services using JSON data.

Let’s get started!

Creating a web data model

First, we need to create a .NET MAUI application and a web data model to get the appointment information from a web service.  

Refer to the following code example.

public class WebData
{
    public string Subject { get; set; }
    public string StartTime { get; set; }
    public string EndTime { get; set; }
}

Creating a web API service and fetching data from it

We can get the online JSON data with the help of the GetStringAsync method and deserialize it as a list of WebData models. We will use the hosted service as an example.

Refer to the following code example to deserialize JSON web data.

SchedulerViewModel.cs

private async Task<List<WebData>> GetJsonWebData()
{
    var httpClient = new HttpClient();
    var response = await httpClient.GetStringAsync("https://services.syncfusion.com/js/production/api/schedule");
    return JsonConvert.DeserializeObject<List< WebData >>(response);
}

Load appointments on demand via web service in .NET MAUI Scheduler

Let’s load the deserialized data into the Syncfusion .NET MAUI Scheduler control on demand.

Note: Before proceeding, please read the getting started with .NET MAUI Scheduler documentation.

Step 1: Register the handler

We register the handler for Syncfusion core in the MauiProgram.cs file.

Public static MauiApp CreateMauiApp()
{
     var builder = MauiApp.CreateBuilder();
     builder.ConfigureSyncfusionCore();
}

Step 2: Creating an appointment model class

Next, we create the appointment Event data model class containing basic information to generate the appointments.

Refer to the following code example.

Event.cs

public class Event : INotifyPropertyChanged
{
    private DateTime from;
    private DateTime to;
    private bool isAllDay;
    private string eventName;
    private Brush background;

    /// <summary>
    /// Gets or sets the value to display the start date.
    /// </summary>
    public DateTime From
    {
        get
        { return this.from; }
        set
        {
           this.from = value;
           this.OnPropertyChanged(nameof(From));
        }
    }

    /// <summary>
    /// Gets or sets the value to display the end date.
    /// </summary>
    public DateTime To
    {
        get { return this.to; }
        set
        {
            this.to = value;
            this.OnPropertyChanged(nameof(To));
        }
     }

     /// <summary>
     /// Gets or sets the value indicating whether the appointment is all day or not.
     /// </summary>
     public bool IsAllDay
     {
        get { return this.isAllDay; }
        set
        {
            this.isAllDay = value;
            this.OnPropertyChanged(nameof(IsAllDay));
        }
     }

     /// <summary>
     /// Gets or sets the value to display the subject.
     /// </summary>
     public string EventName
     {
        get { return this.eventName; }
        set { this.eventName = value; }
     }

     /// <summary>
     /// Gets or sets the value to display the background.
     /// </summary>
     public Brush Background
     {
        get { return this.background; }
        set { this.background = value; }
     }

     public event PropertyChangedEventHandler? PropertyChanged;

     private void OnPropertyChanged(string propertyName)
     {
        this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
     }
}

Step 3: Create the appointments

Following that, we’ll look at creating an Events collection from online data retrieved via the web service.

You can load appointments on demand with a loading indicator based on the Scheduler’s visible date range. We can improve the appointment loading performance using the QueryAppointmentsCommand property.

Refer to the following code example to retrieve web appointments in the view model class.

SchedulerViewModel.cs

public ICommand QueryAppointmentsCommand { get; set; }

private ObservableCollection<Event> events;
public ObservableCollection<Event> Events
{
    get
    {
        return this.events;
    }
    set
    {
        this.events = value;
    }
}

public SchedulerViewModel()
{
    this.QueryAppointmentsCommand = new Command<object>(LoadAppointments);
}

private async void LoadAppointments(object obj)
{
    //// Get appointment details from the web service.
    if (jsonWebData == null)
        jsonWebData = await GetJsonWebData();

    Random random = new Random();
    var visibleDates = ((SchedulerQueryAppointmentsEventArgs)obj).VisibleDates;
    this.Events = new ObservableCollection<Event>();
    this.ShowBusyIndicator = true;

    DateTime visibleStartDate = visibleDates.FirstOrDefault();
    DateTime visibleEndDate = visibleDates.LastOrDefault();

    foreach (var data in jsonWebData)
    {
       DateTime startDate = Convert.ToDateTime(data.StartTime);
       DateTime endDate = Convert.ToDateTime(data.EndTime);

       if ((visibleStartDate <= startDate.Date && visibleEndDate >= startDate.Date) ||
          (visibleStartDate <= endDate.Date && visibleEndDate >= endDate.Date))
       {
          Events.Add(new Event()
          {
              EventName = data.Subject,
              From = startDate,
              To = endDate,
              Background = this.colors[random.Next(this.colors.Count)]
          });
       }
    }

    if (jsonWebData != null)
        await Task.Delay(1000);

    this.ShowBusyIndicator = false;
}

Step 4: Bind appointments to the Scheduler

Let’s initialize the .NET MAUI Scheduler control.

MainPage.xaml

xmlns:scheduler="clr-namespace:Syncfusion.Maui.Scheduler;assembly=Syncfusion.Maui.Scheduler"

<scheduler:SfScheduler/>

Next, we bind the custom data Events to the .NET MAUI Scheduler’s AppointmentsSource using the appointment mapping feature.

Refer to the following code example to bind the QueryAppointmentsCommand and AppointmentsSource properties from the SchedulerViewModel class.

MainPage.xaml

<scheduler:SfScheduler View="Month" 
                       QueryAppointmentsCommand="{Binding QueryAppointmentsCommand}"
                       AppointmentsSource="{Binding Events}">
 <scheduler:SfScheduler.AppointmentMapping>
  <scheduler:SchedulerAppointmentMapping Subject="EventName"
                                         StartTime="From"
                                         EndTime="To"
                                         Background="Background"
                                         IsAllDay="IsAllDay" />
 </scheduler:SfScheduler.AppointmentMapping>
 <scheduler:SfScheduler.BindingContext>
  <local:SchedulerViewModel/>
 </scheduler:SfScheduler.BindingContext>
</scheduler:SfScheduler>

After executing the previous code examples, we’ll get output like in the following image.

Loading appointments on demand via web services in .NET MAUI Scheduler using JSON data
Loading appointments on demand via web services in .NET MAUI Scheduler using JSON data

GitHub reference

For more details, refer to the example for loading appointments on demand via web services in .NET MAUI Scheduler using JSON data on GitHub.

Conclusion

Thanks for reading! In this blog, we learned how to load appointments on demand in the .NET MAUI Scheduler control via web services. With this, you can load only the required appointments on demand and considerably enhance the loading performance of your app. Try out the steps and leave your feedback in the comments section below!

For current Syncfusion customers, the newest version of Essential Studio is available from the license and downloads page. If you are not a customer yet, try our 30-day free trial to check out these new features.

You can also contact us through our support forumsupport portal, or feedback portal. We are always happy to assist you!

Test Flight
App Center Badge
Google Play Store Badge
Microsoft Badge
Github Store Badge

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed