How to stop Delete if server returned an error?

Hello!
I'm trying to delete an event from the scheduler but before deleting it on the frontend I need to go to the database. I'm using the OnActionBegin to call the backend for deletion. If the service returns an error, I need to cancel the delete but I can't seem to stop the event from being deleted from the schedule. I can see there is a Cancel on the ActionEventArgs but setting it to true does nothing. I even tried to set the DeletedRecords to null or clearing the list.

So my question is how do I stop an event from being deleted from the scheduler if I receive an error from the backend? is the OnActionBegin the right event to be using?

Kind regards,
Rodrigo F.

3 Replies

AK Alagumeena Kalaiselvan Syncfusion Team February 24, 2020 12:41 PM UTC

Hi Rodrigo, 

Thanks for contacting Syncfusion support! 

We have validated your reported issue “How to stop, If server returned an error” and we suspect that issue may occurs due to getting delayed response from the server . So, we suggest you to use the async method which will run synchronously. Refer the below code for that 

<EjsSchedule TValue="Appointment" Height="650px" SelectedDate="@(DateTime.Now)"> 
    <ScheduleEventSettings DataSource="@DataSource"></ScheduleEventSettings> 
    <ScheduleEvents TValue="Appointment" OnActionBegin="ActionBegin" /> 
</EjsSchedule> 
 
@code { 
    public async Task ActionBegin(ActionEventArgs<Appointment> args) 
    { 
       var IsServerError = await UpdateData(); 
       if (IsServerError) 
        { 
            args.Cancel = true; 
        } 
    } 
   ... 
} 

Kindly try out with suggested way and get back to us, If you need further assistance. 

Regards 
Alagumeena.K 



RO Rodrigo February 24, 2020 12:54 PM UTC

Hi Alagumeena,
I'm already using async/await. On the code below there are some validations that return an exception (currently blazor doesn't have a centralized blaze to deal with exceptions) and if that happens I want to cancel the delete event.
try
{
if (args.RequestType == BeginEventRemove && args.DeletedRecords.Count > 0)
{
var itemToRemove = args.DeletedRecords.FirstOrDefault();
await Service.DeleteMothod(itemToRemove .Id);
}
}
catch (InvalidOperationException ioe)
{
ToastService.ShowToast(new ToastDetail()
{
Level = ToastLevel.Error,
Message = "Error",
SubMessages = new List<string>() { ioe.Message }
});
}


AK Alagumeena Kalaiselvan Syncfusion Team February 25, 2020 01:58 PM UTC

Hi Rodrigo, 
Thanks for your update! 
We have checked your case and we suggest you to invoke the “RefreshEvents” public method in catch block to overcome this issue. Refer the below code for that 
<EjsSchedule @ref="ScheduleObj" TValue="Appointment" Height="650px" SelectedDate="@(DateTime.Now)">  
     
</EjsSchedule>  
  
@code {  
  EjsSchedule<Appointment> ScheduleObj; 
    try 
{ 
 if (args.RequestType == BeginEventRemove && args.DeletedRecords.Count > 0) 
 { 
    var itemToRemove = args.DeletedRecords.FirstOrDefault(); 
    await Service.DeleteMothod(itemToRemove.Id); 
 } 
} 
catch (InvalidOperationException ioe) 
{ 
   ToastService.ShowToast(new ToastDetail() 
    { 
    ScheduleObj.RefreshEvents(); // To refresh the scheduler events 
    Level = ToastLevel.Error, 
    Message = "Error", 
    SubMessages = new List<string>() { ioe.Message } 
    }); 
 } 
...}  
Please try with above solution and let us know, If you need further assistance. 
Regards 
Alagumeena.K 


Loader.
Up arrow icon