public CalendarEntry ScheduleCalendarEntry(CalendarIdentityService calendarIdentityService, string description,
     string location, Owner owner, DateRange timeSpan, Repetition repetition, Alarm alarm,
     IEnumerable<Participant> invitees = null)
 {
     return new CalendarEntry(this._tenantId, this._calendarId, calendarIdentityService.GetNextCalendarEntryId(),
         description, location, owner, timeSpan, repetition, alarm, invitees);
 }
        public CalendarEntryRescheduled(TenantId tenantId, CalendarId calendarId, CalendarEntryId calendarEntryId,
            DateRange timeSpan, Repetition repetition, Alarm alarm)
        {
            this.TenantId = tenantId;
            this.CalendarId = calendarId;
            this.CalendarEntryId = calendarEntryId;
            this.TimeSpan = timeSpan;
            this.Repetition = repetition;
            this.Alarm = alarm;

            this.EventVersion = 1;
            this.OccurredOn = DateTime.Now;
        }
        public CalendarEntryScheduled(TenantId tenantId, CalendarId calendarId, CalendarEntryId calendarEntryId,
            string description, string location, Owner owner, DateRange timeSpan, Repetition repetition, Alarm alarm,
            IEnumerable<Participant> invitees)
        {
            this.TenantId = tenantId;
            this.CalendarId = calendarId;
            this.CalendarEntryId = calendarEntryId;
            this.Description = description;
            this.Location = location;
            this.Owner = owner;
            this.TimeSpan = timeSpan;
            this.Repetition = repetition;
            this.Alarm = alarm;
            this.Invitees = invitees;

            this.EventVersion = 1;
            this.OccurredOn = DateTime.Now;
        }
        public CalendarEntry(TenantId tenantId, CalendarId calendarId, CalendarEntryId calendarEntryId,
            string description, string location, Owner owner, DateRange timeSpan, Repetition repetition, 
            Alarm alarm, IEnumerable<Participant> invitees = null)
        {
            AssertionConcern.NotNull(tenantId, "The tenant must be provided.");
            AssertionConcern.NotNull(calendarId, "The calendar id must be provided.");
            AssertionConcern.NotNull(calendarEntryId, "The calendar entry id must be provided.");
            AssertionConcern.NotEmpty(description, "The description must be provided.");
            AssertionConcern.NotEmpty(location, "The location must be provided.");
            AssertionConcern.NotNull(owner, "The owner must be provided.");
            AssertionConcern.NotNull(timeSpan, "The time span must be provided.");
            AssertionConcern.NotNull(repetition, "The repetition must be provided.");
            AssertionConcern.NotNull(alarm, "The alarm must be provided.");

            if(repetition.Repeats==RepeatType.DoesNotRepeat) {
                repetition = Repetition.DoesNotRepeat(timeSpan.Ends);
            }

            AssertTimeSpans(repetition, timeSpan);

            this.Apply(new CalendarEntryScheduled(tenantId, calendarId, calendarEntryId, description, location, owner,
                timeSpan, repetition, alarm, invitees));
        }
 private void When(CalendarEntryRescheduled e)
 {
     this._timeSpan = e.TimeSpan;
     this._repetition = e.Repetition;
     this._alarm = e.Alarm;
 }
 private void When(CalendarEntryScheduled e)
 {
     this._tenantId = e.TenantId;
     this._calendarId = e.CalendarId;
     this._calendarEntryId = e.CalendarEntryId;
     this._description = e.Description;
     this._location = e.Location;
     this._owner = e.Owner;
     this._timeSpan = e.TimeSpan;
     this._repetition = e.Repetition;
     this._alarm = e.Alarm;
     this._invitees = new HashSet<Participant>(e.Invitees ?? Enumerable.Empty<Participant>());
 }
 private void AssertTimeSpans(Repetition repetition, DateRange timeSpan)
 {
     if(repetition.Repeats==RepeatType.DoesNotRepeat) {
         AssertionConcern.Equals(repetition.Ends, timeSpan.Ends, "Non-repeating entry must end with time span end.");
     }
     else {
         AssertionConcern.False(timeSpan.Ends>repetition.Ends, "Time span must end when or before repetition ends.");
     }
 }
        public void Reshedule(string description, string location, DateRange timeSpan, Repetition repetition,
            Alarm alarm)
        {
            AssertionConcern.NotNull(timeSpan, "The time span must be provided.");
            AssertionConcern.NotNull(repetition, "The repetition must be provided.");
            AssertionConcern.NotNull(alarm, "The alarm must be provided.");

            if(repetition.Repeats == RepeatType.DoesNotRepeat) {
                repetition = Repetition.DoesNotRepeat(timeSpan.Ends);
            }

            this.AssertTimeSpans(repetition, timeSpan);

            this.ChangeDescription(description);
            this.Relocate(location);

            this.Apply(new CalendarEntryRescheduled(this._tenantId, this._calendarId, this._calendarEntryId, timeSpan,
                repetition, alarm));
        }