This is a migrated thread and some comments may be shown as answers.

When the appointments are read from the database, categories for each one does not show

2 Answers 87 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Colin
Top achievements
Rank 2
Colin asked on 17 Jun 2014, 10:21 AM
Hi,

I am creating my own list of categories for the
RadScheduleView, it displays ok with this code:

myScheduleView.CategoriesSource = context.Category.ToList();

When I create and save a new appointment I am able to
save it with the category Id from the list above.

var appointment = e.Appointment as SqlAppointment;

                if (appointment.Category.CategoryName != null)

                {
                    appointment.CategoryId = context.Category
                                                                 .Where(p => p.CategoryName == appointment.Category.CategoryName)
                                                                .Select(p => p.CategoryId).FirstOrDefault();
                }

                context.SqlAppointment.Add(appointment);

                context.SaveChanges();


However when I re-run the app and load this

myScheduleView.CategoriesSource = context.Category.ToList();
myScheduleView.AppointmentsSource = context.SqlAppointment.ToList();


It load the categories it loads the appointments the
appointments have their keys to the categories, however the RadScheduleView is
not showing the category for each of the appointment, and I don’t know why? It should
it knows the Sources and the id’s.

Any idea what am I missing?

Thank you

2 Answers, 1 is accepted

Sort by
0
Colin
Top achievements
Rank 2
answered on 19 Jun 2014, 08:57 AM
I changed the SqlAppointment class to look like this:

    public class SqlAppointment : IAppointment, IExtendedAppointment
    {
        public int SqlAppointmentId { get; set; }
        public string Subject { get; set; }
        public string Body { get; set; }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public bool IsAllDayEvent { get; set; }
        public IRecurrenceRule RecurrenceRule { get; set; }
        public TimeZoneInfo TimeZone { get; set; }
        public Importance Importance { get; set; }
        public int? TimeMarkerId { get; set; }
        public int? CategoryId { get; set; }

        //keys
        public virtual TimeMarker TimeMarker { get; set; }
        public virtual Category Category { get; set; }

        ICategory IExtendedAppointment.Category
        {
            get { return this.Category as ICategory; }
            set { this.Category = value as Category; }
        }

        ITimeMarker IExtendedAppointment.TimeMarker
        {
            get { return this.TimeMarker as ITimeMarker; }
            set { this.TimeMarker = value as TimeMarker; }
        }

        public string RecurrencePattern { get; set; }

        public event EventHandler RecurrenceRuleChanged;

        private IList resources;
        public IList Resources
        {
            get
            {
                if (resources == null)
                {
                    resources = new ObservableCollection<SqlResource>();
                }
                return resources;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void BeginEdit()
        {
            //TODO: implement
            //throw new System.NotImplementedException();
        }

        public void CancelEdit()
        {
            //TODO: implement
            //throw new System.NotImplementedException();
        }

        public void EndEdit()
        {
            //TODO: implement
            //throw new System.NotImplementedException();
        }

        public bool Equals(IAppointment other)
        {
            var otherAppointment = other as SqlAppointment;
            bool result =otherAppointment != null &&
                   other.Start == Start &&
                   other.End == End &&
                   other.Subject == Subject &&
                   CategoryId == otherAppointment.CategoryId &&
                   TimeMarker == otherAppointment.TimeMarker &&
                   TimeZone == otherAppointment.TimeZone &&
                   IsAllDayEvent == other.IsAllDayEvent &&
                   RecurrenceRule == other.RecurrenceRule;
            return result;
        }

        public IAppointment Copy()
        {
            IAppointment appointment = new SqlAppointment();
            appointment.CopyFrom(this);
            return appointment;
        }

        public void CopyFrom(IAppointment other)
        {
            throw new System.NotImplementedException();
        }
    }

And it working now. I took the code from here https://github.com/telerik/xaml-sdk/tree/master/ScheduleView/Database/WPF_CS
The main thing is that the ICategory property should return the Category property, same for the TimeMarker
Thanks
0
Yana
Telerik team
answered on 20 Jun 2014, 08:52 AM
Hi Colin,

I am glad that you managed to resolve the issue. If you have any further questions, write to us again.

Regards,
Yana
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
ScheduleView
Asked by
Colin
Top achievements
Rank 2
Answers by
Colin
Top achievements
Rank 2
Yana
Telerik team
Share this question
or