Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Issue with Recurrent Appointment { public ObservableCollection Appointments { get; set; } public PocoDataViewModel() { GenerateAppointments(); } public void GenerateAppointments
posted

I'm trying to use a custom entity types with recurrent activity. When I use my custom entity types without recurrent activity, everything works, but when I want to add the recurrent activity, no appointments appear on the XamScheduler control after adding it.

My model : 

public class PocoAppointment
    {
        public PocoAppointment()
        {
            Id = Guid.NewGuid().ToString();
        }

        public string Id { get; set; }
        public string Subject { get; set; }
        public DateTime End { get; set; }
        public DateTime Start { get; set; }
        public string Recurrence { get; set; }
        //public bool IsRecurrenceRoot { get; set; }
        //public ActivityBase RecurrenceRoot { get; set; }
        public string RecurrenceId { get; set; }
        public string Description { get; set; }
        public string Location { get; set; }
        public string ResourceId { get; set; }
    }

My ViewModel : 

public class PocoDataViewModel
    {
        public ObservableCollection<PocoAppointment> Appointments { get; set; }

        public PocoDataViewModel()
        {
            GenerateAppointments();
        }

        public void GenerateAppointments()
        {
            Appointments = new ObservableCollection<PocoAppointment>();

            var item = new PocoAppointment();
            item.Start = DateTime.Now;
            item.End = DateTime.Now.AddDays(2); ;
            item.Subject = "My Event";

            Appointments.Add(item);

        }

    }

My Xaml : 

    <Grid>
        <ig:XamScheduler x:Name="Scheduler" ViewMode="MonthView" />
    </Grid>

And my Xaml.cs : 

public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();

            ((App)Application.Current).viewModel = new PocoDataViewModel();

            Scheduler.BindingContext = ((App)Application.Current).viewModel;
            ScheduleListDataSource datasource = new ScheduleListDataSource();
            datasource.AppointmentItemsSource = ((PocoDataViewModel)Scheduler.BindingContext).Appointments;

            //Mapping
            datasource.AppointmentPropertyMappings.Add(
                new AppointmentPropertyMapping()
                {
                    Property = AppointmentProperty.Start,
                    DataObjectPropertyName = nameof(PocoAppointment.Start)
                });

            datasource.AppointmentPropertyMappings.Add(
                new AppointmentPropertyMapping()
                {
                    Property = AppointmentProperty.End,
                    DataObjectPropertyName = nameof(PocoAppointment.End)
                });

            datasource.AppointmentPropertyMappings.Add(
                new AppointmentPropertyMapping()
                {
                    Property = AppointmentProperty.Subject,
                    DataObjectPropertyName = nameof(PocoAppointment.Subject)
                });

            datasource.AppointmentPropertyMappings.Add(
                new AppointmentPropertyMapping()
                {
                    Property = AppointmentProperty.Description,
                    DataObjectPropertyName = nameof(PocoAppointment.Description)
                });

            datasource.AppointmentPropertyMappings.Add(
                new AppointmentPropertyMapping()
                {
                    Property = AppointmentProperty.Location,
                    DataObjectPropertyName = nameof(PocoAppointment.Location)
                });

            datasource.AppointmentPropertyMappings.Add(
                new AppointmentPropertyMapping()
                {
                    Property = AppointmentProperty.Id,
                    DataObjectPropertyName = nameof(PocoAppointment.Id)
                });

            datasource.AppointmentPropertyMappings.Add(
                new AppointmentPropertyMapping()
                {
                    Property = AppointmentProperty.ResourceId,
                    DataObjectPropertyName = nameof(PocoAppointment.ResourceId)
                });

            datasource.AppointmentPropertyMappings.Add(
                new AppointmentPropertyMapping()
                {
                    Property = AppointmentProperty.ResourceId,
                    DataObjectPropertyName = nameof(PocoAppointment.ResourceId)
                });


            //Fin de mapping

            Scheduler.DataSource = datasource;
        }

        private async void ToolbarItem_Clicked(object sender, EventArgs e)
        {
            var page = new AppointmentPage();
            await Navigation.PushAsync(page);
        }

So, If I create a new appointment with this code, it doesn't appear on the XamScheduler : 

 PocoAppointment appointment1 = new PocoAppointment();
            appointment1.Subject = txtName.Text;

            DateTime today = dtStart.Date;
             appointment1.Start = new DateTime(today.Year, today.Month, today.Day, tHeure.Time.Hours,
                       tHeure.Time.Minutes, 0);

                    DateRecurrence dr1 = new DateRecurrence();
                    dr1.Frequency = DateRecurrenceFrequency.Daily;
                    dr1.Until = new DateTime(dtEnd.Date.Year, dtEnd.Date.Month, dtEnd.Date.Day, tHeure.Time.Hours,
                        tHeure.Time.Minutes, 0);

                    appointment1.Recurrence = dr1.ToICalendarString();
                    ((App)Application.Current).viewModel.Appointments.Add(appointment1);

What's wrong please ?

Regards

Parents
  • 25665
    Offline posted

    Hello William,

    Thank you for contacting Infragistics!

    I have look at the code you have provide. It appears you are mapping the ResourceId property twice. Have you tried mapping the recurrence properties?

Reply Children
No Data