Issues in Scheduler CRUD

I am new to Syncfusion. 

Syncfusion.Blazor.Grids already installed & working in my project. In same project want to use Scheduler. 
Working on local data. Giving issues when I try to persist in database. checked the helpsite:

To perform CRUD actions (to insert, update and delete the data in database) you use CustomAdaptor or ODataV4 adaptor, please refer to the following UG link. 

I am using EFCore, Dot.Net 8.0. Have added to my _imports.razor file:

@using Syncfusion.Blazor.Schedule
@using Syncfusion.Blazor.Data

have a CustomAdapter, which in turn is using a service. 

the main culprit is below part in DataAdaptor Service:

 

public class AppointmentCustomAdaptor : DataAdaptor

{

    private readonly AppointmentService _appointmentService;

    private List<AppointmentData> EventData;


    public AppointmentCustomAdaptor(AppointmentService appointmentService)

    {

        _appointmentService = appointmentService;

    }


    private int _schoolId = 2;


    // Fetch all records based on the hardcoded SchoolID

    // Corrected ReadAsync method

    public async override Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string key = null)

    {

        // Fetch data from the service

        EventData = (await _appointmentService.GetAppointmentsBySchoolIdAsync(_schoolId)).ToList();



        // Properly return as an object of DataResult

        return Task.FromResult<object>(new DataResult

        {

            Result = EventData,

            Count = EventData.Count()

        });

    }


runtime values:

?EventData Count = 1 [0]: {EduBuddy.Data.AppointmentData} ?DataResult error CS0119: 'DataResult' is a type, which is not valid in the given context

My Page:


<SfSchedule TValue="AppointmentData" Width="100%" Height="650px" SelectedDate="@CurrentDate" @bind-CurrentView="@CurrentView">

    <ScheduleEventSettings TValue="AppointmentData">

      <!-- This is directly using typeof for AdaptorInstance as the demo site does -->

        <SfDataManager AdaptorInstance="@typeof(AppointmentCustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>

     </ScheduleEventSettings>

</SfSchedule>


@code {

    public View CurrentView { get; set; } = View.Week;

    private DateTime CurrentDate { get; set; } = DateTime.Today;

}


2 Replies

VP Vishal Pandey September 22, 2024 06:17 AM UTC

Or maybe problem is elsewhere. Even below code gave issues. The page showing unhandled error on loading. 
only this page giving issues. rest project working fine. 


    public async override Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string key = null)

    {

        // Create simple sample data set for testing

        List<AppointmentData> sampleData = new List<AppointmentData>

{

    new AppointmentData

    {

        Id = 1,

        Subject = "Test Appointment",

        StartTime = DateTime.Now,

        EndTime = DateTime.Now.AddHours(1),

        Location = "Test Location",

        Description = "This is a test appointment.",

        IsAllDay = false,

        SchoolID=2

    }

};


        // Return the sample data wrapped in DataResult

        // Directly return the sample data as object, without DataResult

        return Task.FromResult<object>(sampleData);

    }



VR Vijay Ravi Syncfusion Team September 23, 2024 07:33 AM UTC

Hi Vishal Pandey,


We have checked and validated the code snippets you shared. It appears that you're trying to cast a Task<object> to an IEnumerable<object>, which is not valid. The Task.FromResult<object>(sampleData) returns a Task<object>, not an IEnumerable<object>.


You should return the Data directly, not wrapped in a Task. Since your method is asynchronous, you can use await with Task.FromResult to return the data:


[appointmentDataAdaptor.cs]

you can use await Task.FromResult to return the data:

public override async Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string key = null)

{

    List<AppointmentData> sampleData = new List<AppointmentData>

    {

        new AppointmentData

        {

            Id = 1,

            Subject = "Test Appointment",

            StartTime = DateTime.Now,

            EndTime = DateTime.Now.AddHours(1),

            Location = "Test Location",

            Description = "This is a test appointment.",

            IsAllDay = false,

            RecordID=2

        }

    };

    return await Task.FromResult(sampleData);

}

 
Regards

Vijay



Attachment: updated_BlazorSchedulerCRUDusingcustomadaptor_76ade66d.zip

Loader.
Up arrow icon