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

3 posts, 0 answers
  1. Colin
    Colin avatar
    19 posts
    Member since:
    Jun 2011

    Posted 17 Jun 2014 Link to this post

    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. Colin
    Colin avatar
    19 posts
    Member since:
    Jun 2011

    Posted 19 Jun 2014 in reply to Colin Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 20 Jun 2014 Link to this post

    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.
     
Back to Top