DELETING APPOINTMENT

HOW TO DETECT THE DELETING APPOINTMENT TO DO SOMETHING, NOT THROUGH THE EDIT BUT BY CLICKING ON IT AND THEN BY PRESSING THE CANC/DEL KEY?

REAGRDS 
ANDREA

6 Replies

AN andrea July 4, 2018 04:12 PM UTC

SOMEONE KNOWS HOW TO IMPLEMENTS

AppointmentCollectionChanged 

TO DETECT THE REMOVE ACTION?



GC Ganeshamoorthy Chandramoorthy Syncfusion Team July 6, 2018 10:00 AM UTC

Hi Andrea, 
 
We have checked with your query. Currently, schedule doesn’t provide direct support for appointment collection changed event. You can use CollectionChanged event of your underlying appointment collection. We have prepared a sample to detect the delete action of custom appointment. Kindly find the sample below, 
 
Code snippet: 
//CollectionChanged property of custom appointment collection 
meetings.CollectionChanged += Meetings_CollectionChanged;

private void Meetings_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
{ 
    if (e.Action == NotifyCollectionChangedAction.Remove) 
    { } 
} 
 
Sample: SfSchedule 
 
Regrads, 
Ganeshamoorthy C 



SC Scott September 16, 2018 03:54 AM UTC

andrea,

I'm struggling through getting sfSchedule to work with WPF too.  Here's what I'm doing to detect changes in the appointment collection, and it's been working for me.

I don't know, yet, how to post code properly on this forum, so if you want you can check out my gist on github:
https://gist.github.com/scottpage/5b842e54fe19c1beb683d09050c654a5

I'll post my entire class to help you, here's the link:
https://gist.github.com/scottpage/4af0b9a269c4fed42784ec3795bc1748

I hope this helps, if not, let me know and I'll be more than happy to help you out.  I've struggled enough with sfSchedule and MVVM, I'd hate to see anyone else do the same.

Some info to help you understand my code without seeing outside of this method:
  1)  ScheduledEventAppointment is an abstract (MustInherit) class that inherits from ScheduleAppointment (provided by Syncfusion sfSchedule).
  2)  My.Application.Api is a property of a custom class, in Application.xaml.vb, that I created for my REST api server.  Keep in mind, it's just a class with functions that return an object.
  3)  I'm breaking MVVM rules by using MessageBox.Show for testing only.  I haven't implemented any kind of dependency injection, yet.
  4)  SESA.IsExamination is an extension method for ScheduledEventAppointment that determines the derived (inherited) Type of the current ScheduledEventAppointment.
  5)  AddScheduledEventScheduledAppointment is a method used to add the appointment to the schedule.

    Private Async Sub ScheduledEvents_CollectionChanged(sender As Object, e As NotifyCollectionChangedEventArgs)
        Select Case e.Action
            Case NotifyCollectionChangedAction.Remove
                If _DeletingEventFromOtherLocation Then Return
                Dim SESA = DirectCast(e.OldItems(0), ScheduledEventAppointment)
                If MessageBox.Show(String.Format("Arg you sure you want to delete scheduled event {0}", SESA.ScheduledEvent.Id), "Deleting Event", MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
                    Await My.Application.Api.DeleteExaminationEventAsync(SESA.ScheduledEvent.Id)
                Else
                    If SESA.IsExamination Then
                        AddScheduledEventScheduledAppointment(SESA.AsExamination.Examination)
                    End If
                End If
        End Select
    End Sub

'*** REST API (Calls to server) ***
    Public Async Function DeleteExaminationEventAsync(id As Integer) As Task(Of Integer)
        Dim Request As New RestRequest(String.Format("/Examinations/{0}", id), Method.DELETE)
        Dim Response = Await _Client.ExecuteTaskAsync(Of Integer)(Request)
        Return Response.Data
    End Function

'*** METHODS IN SAME CLASS AS CollectionChanged EVENT ***
    Private Sub AddScheduledEventScheduledAppointment(newEvent As ExaminationInfoDto)
        If My.Application.Dispatcher.CheckAccess Then
            If ScheduledEvents.ContainsExamination(newEvent.Id) Then Return
            Dim ESA As New ExaminationAppointment(newEvent, ExaminationStatus)
            _AddingEventFromMainHub = True
            ScheduledEvents.Add(ESA)
            _AddingEventFromMainHub = False
        Else
            My.Application.Dispatcher.BeginInvoke(New Action(Of ExaminationInfoDto)(AddressOf AddScheduledEventScheduledAppointment), (newEvent))
        End If
    End Sub

' *** EXTENSIONS ***
    <Extension>
    Public Function IsExamination(sa As ScheduledEventAppointment) As Boolean
        Return TypeOf sa Is ExaminationAppointment
    End Function





DY Deivaselvan Y Syncfusion Team September 17, 2018 11:41 AM UTC

Hi Scott,

Thank you for your solution to this requirement in MVVM. We also have a KB article to use SfSchedule control in MVVM pattern and you can refer the below articles for more details on it.

https://www.syncfusion.com/kb/6047/how-to-access-schedule-events-in-mvvm-by-using-commads
https://www.syncfusion.com/kb/5748/how-to-render-custom-appointments-in-schedule-using-mvvm-pattern


Regards,
Deivaselvan 



AN andrea September 26, 2018 12:33 PM UTC

Thanks


PR Padmini Ramamurthy Syncfusion Team September 27, 2018 04:41 AM UTC

Hi Andrea, 
  
You are welcome and please get back to us if you need any other assistance. 
  
Regards, 
Padmini R. 


Loader.
Up arrow icon