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 Calendar(TenantId tenantId, CalendarId calendarId, string name, string description, Owner owner,
            IEnumerable<CalendarSharer> sharedWith = null)
        {
            AssertionConcern.NotNull(tenantId, "The tenant must be provided.");
            AssertionConcern.NotNull(calendarId, "The calendar id must be provided.");
            AssertionConcern.NotEmpty(name, "The name must be provided.");
            AssertionConcern.NotEmpty(description, "The description must be provided.");
            AssertionConcern.NotNull(owner, "The owner must be provided.");

            this.Apply(new CalendarCreated(tenantId, calendarId, name, description, owner, sharedWith));
        }
        public CalendarCreated(TenantId tenantId, CalendarId calendarId, string name, string description, Owner owner, IEnumerable<CalendarSharer> sharedWith)
        {
            this.TenantId = tenantId;
            this.CalendarId = calendarId;
            this.Name = name;
            this.Description = description;
            this.Owner = owner;
            this.SharedWith = sharedWith;

            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(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>());
 }