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

IAppoinment implementation

1 Answer 53 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 24 Apr 2012, 08:26 AM

Hi,

I'm having a few difficulties getting the ScheduleView to work properly when my appointment class implements IAppoinment. I don't really want to inherit from AppoinmentBase because my appointment object already inherits from another class (its basically a DTO returned from a WCF service), which is why I've opted to implement the IAppointment interface instead (implemented in a partial class).

With all the examples I find, the appoinment class inherits from AppointmentBase. I CAN get things to work when I wrap my DTO in a AppointmentBase subclass (i.e. AppoinmentWrapper), but I dont really like this abstraction - I'd rather just implement IAppoinment.

Basically, Im getting a ManagedRuntimeError which is a null reference exception. I suspect I'm not implementing something correctly in my IAppointment implementation, which is below.

Any ideas as to why this may be happening.

Cheers.

***

    public partial class Booking : IAppointment
    {
        public Booking()
        {
            IsAllDayEvent = false;
            RecurrenceRule = new RecurrenceRule(new RecurrencePattern());
            Resources = new ResourceCollection();
            TimeZone = TimeZoneInfo.Utc;
            Subject = "somethign";
        }

        public DateTime End
        {
            get { return !EndDate.HasValue ? DateTime.MinValue : EndDate.Value; }
            set { EndDate = value; }
        }

        public bool IsAllDayEvent { get; set; }

        public IRecurrenceRule RecurrenceRule { get; set; }

        public event EventHandler RecurrenceRuleChanged;

        public IList Resources { get; private set; }

        public DateTime Start
        {
            get { return !StartDate.HasValue ? DateTime.MinValue : StartDate.Value; }
            set { StartDate = value; }
        }

        public string Subject { get; set; }

        public TimeZoneInfo TimeZone { get; set; }

        public void BeginEdit()
        {
            throw new NotImplementedException();
        }

        public void CancelEdit()
        {
            throw new NotImplementedException();
        }

        public void EndEdit()
        {
            throw new NotImplementedException();
        }

        public bool Equals(IAppointment other)
        {
            if (other is Booking)
            {
                var booking = other as Booking;

                return
                    Interviewer == booking.Interviewer &&
                    StartDate == booking.StartDate &&
                    EndDate == booking.EndDate &&
                    Type == booking.Type;
            }

            return false;
        }

        public IAppointment Copy()
        {
            IAppointment appointment = new Booking();
            appointment.CopyFrom(this);

            return appointment;
        }

        public void CopyFrom(IAppointment other)
        {
            var appointment = other as Booking;
            if (appointment == null) return;

            EndDate = appointment.EndDate;
            Interviewer = appointment.Interviewer;
            Lead = appointment.Lead;
            Office = appointment.Office;
            Result = appointment.Result;
            ResultDate = appointment.ResultDate;
            ResultUser = appointment.ResultUser;
            StartDate = appointment.StartDate;
            Type = appointment.Type;
        }
    }

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 26 Apr 2012, 08:47 AM
Hello Steven,

I am not sure what could cause the null reference exception, but I would suggest referring to the following:
In this example the WPF RIA services are used and the entities implement the IAppointment interface (the scenario is very similar to the given one). You could refer to it and see how the interfaces are implemented - it could shed some light on the problem. 

Hope this helps. Please do not hesitate to contact us if you have any additional questions.


Greetings,
George
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ScheduleView
Asked by
Steven
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or