private EventItemOccurrence EventItemOccurrenceAddOrUpdateInstance(RockContext rockContext, Guid scheduleGuid, bool deleteExistingInstance) { // Get existing schedules. var scheduleService = new ScheduleService(rockContext); var schedule = scheduleService.Get(scheduleGuid); // Get Event "Rock Solid Finances". var eventItemService = new EventItemService(rockContext); var eventItemOccurrenceService = new EventItemOccurrenceService(rockContext); var financeEvent = eventItemService.Get(EventFinancesClassGuid.AsGuid()); // Add a new occurrence of this event. var financeEvent1 = eventItemOccurrenceService.Get(FinancesClassOccurrenceTestGuid.AsGuid()); if (financeEvent1 != null && deleteExistingInstance) { eventItemOccurrenceService.Delete(financeEvent1); rockContext.SaveChanges(); } financeEvent1 = new EventItemOccurrence(); var mainCampusId = CampusCache.GetId(MainCampusGuidString.AsGuid()); financeEvent1.Location = "Meeting Room 1"; financeEvent1.ForeignKey = TestDataForeignKey; financeEvent1.ScheduleId = schedule.Id; financeEvent1.Guid = FinancesClassOccurrenceTestGuid.AsGuid(); financeEvent1.CampusId = mainCampusId; financeEvent.EventItemOccurrences.Add(financeEvent1); return(financeEvent1); }
private void ShowEditDetails(EventItemOccurrence eventItemOccurrence) { if (eventItemOccurrence == null) { eventItemOccurrence = new EventItemOccurrence(); } if (eventItemOccurrence.Id == 0) { lActionTitle.Text = ActionTitle.Add("Event Occurrence").FormatAsHtmlTitle(); } else { lActionTitle.Text = ActionTitle.Edit("Event Occurrence").FormatAsHtmlTitle(); } SetEditMode(true); hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString(); ddlCampus.SetValue(eventItemOccurrence.CampusId ?? -1); tbLocation.Text = eventItemOccurrence.Location; if (eventItemOccurrence.Schedule != null) { sbSchedule.iCalendarContent = eventItemOccurrence.Schedule.iCalendarContent; lScheduleText.Text = eventItemOccurrence.Schedule.FriendlyScheduleText; } else { sbSchedule.iCalendarContent = string.Empty; lScheduleText.Text = string.Empty; } ppContact.SetValue(eventItemOccurrence.ContactPersonAlias != null ? eventItemOccurrence.ContactPersonAlias.Person : null); pnPhone.Text = eventItemOccurrence.ContactPhone; tbEmail.Text = eventItemOccurrence.ContactEmail; htmlOccurrenceNote.Text = eventItemOccurrence.Note; LinkageState = new EventItemOccurrenceGroupMap { Guid = Guid.Empty }; var registration = eventItemOccurrence.Linkages.FirstOrDefault(); if (registration != null) { LinkageState = registration.Clone(false); LinkageState.RegistrationInstance = registration.RegistrationInstance != null?registration.RegistrationInstance.Clone(false) : new RegistrationInstance(); LinkageState.RegistrationInstance.RegistrationTemplate = registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null? registration.RegistrationInstance.RegistrationTemplate.Clone(false) : new RegistrationTemplate(); LinkageState.Group = registration.Group != null?registration.Group.Clone(false) : new Group(); } DisplayRegistration(); }
public static Schedule SyncSchedule( ESpace.Occurrence eSpaceOccurrence, EventItemOccurrence rockOccurrence, out bool changed ) { changed = false; if (rockOccurrence.Schedule == null) { rockOccurrence.Schedule = new Schedule { ForeignKey = ForeignKey_eSpaceOccurrenceId, ForeignId = eSpaceOccurrence.OccurrenceId.Value }; changed = true; } var schedule = rockOccurrence.Schedule; if (schedule.EffectiveStartDate != eSpaceOccurrence.EventStart) { schedule.EffectiveStartDate = eSpaceOccurrence.EventStart; changed = true; } if (schedule.EffectiveEndDate != eSpaceOccurrence.EventEnd) { schedule.EffectiveEndDate = eSpaceOccurrence.EventEnd; changed = true; } var scheduleName = ""; if (schedule.Name != scheduleName) { schedule.Name = scheduleName; changed = true; } var iCalEvent = SyncICalEvent(eSpaceOccurrence, schedule, out var iCalChanged); if (iCalChanged) { // Serialize the event var calendar = new DDay.iCal.iCalendar(); calendar.Events.Add(iCalEvent); var serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer(calendar); schedule.iCalendarContent = serializer.SerializeToString(calendar); changed = true; } return(schedule); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="eventItemId">The eventItem identifier.</param> public void ShowDetail(int eventItemOccurrenceId) { pnlDetails.Visible = true; EventItemOccurrence eventItemOccurrence = null; var rockContext = new RockContext(); if (!eventItemOccurrenceId.Equals(0)) { eventItemOccurrence = new EventItemOccurrenceService(rockContext).Get(eventItemOccurrenceId); } if (eventItemOccurrence == null) { eventItemOccurrence = new EventItemOccurrence { Id = 0 }; } bool canEdit = UserCanEdit || eventItemOccurrence.IsAuthorized(Authorization.EDIT, CurrentPerson); bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (!canEdit) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(EventItemOccurrence.FriendlyTypeName); } if (readOnly) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails(eventItemOccurrence); } else { btnEdit.Visible = true; btnDelete.Visible = true; if (!eventItemOccurrenceId.Equals(0)) { ShowReadonlyDetails(eventItemOccurrence); } else { ShowEditDetails(eventItemOccurrence); } } }
/// <summary> /// Handles the RowSelected event of the gCalendarItemOccurrenceList control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void gCalendarItemOccurrenceList_RowSelected(object sender, RowEventArgs e) { using (RockContext rockContext = new RockContext()) { EventItemOccurrenceService eventItemOccurrenceService = new EventItemOccurrenceService(rockContext); EventItemOccurrence eventItemOccurrence = eventItemOccurrenceService.Get(e.RowKeyId); if (eventItemOccurrence != null) { var qryParams = new Dictionary <string, string>(); qryParams.Add("EventCalendarId", PageParameter("EventCalendarId")); qryParams.Add("EventItemId", _eventItem.Id.ToString()); qryParams.Add("EventItemOccurrenceId", eventItemOccurrence.Id.ToString()); NavigateToLinkedPage("DetailPage", qryParams); } } }
private void ShowReadonlyDetails(EventItemOccurrence eventItemOccurrence) { SetEditMode(false); hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString(); lActionTitle.Text = "Event Occurrence".FormatAsHtmlTitle(); var leftDesc = new DescriptionList(); leftDesc.Add("Campus", eventItemOccurrence.Campus != null ? eventItemOccurrence.Campus.Name : "All"); leftDesc.Add("Location Description", eventItemOccurrence.Location); leftDesc.Add("Schedule", eventItemOccurrence.Schedule != null ? eventItemOccurrence.Schedule.FriendlyScheduleText : string.Empty); if (eventItemOccurrence.Linkages.Any()) { var linkage = eventItemOccurrence.Linkages.First(); if (linkage.RegistrationInstance != null) { var qryParams = new Dictionary <string, string>(); qryParams.Add("RegistrationInstanceId", linkage.RegistrationInstance.Id.ToString()); leftDesc.Add("Registration", string.Format("<a href='{0}'>{1}</a>", LinkedPageUrl("RegistrationInstancePage", qryParams), linkage.RegistrationInstance.Name)); } if (linkage.Group != null) { var qryParams = new Dictionary <string, string>(); qryParams.Add("GroupId", linkage.Group.Id.ToString()); leftDesc.Add("Group", string.Format("<a href='{0}'>{1}</a>", LinkedPageUrl("GroupDetailPage", qryParams), linkage.Group.Name)); } } lLeftDetails.Text = leftDesc.Html; var rightDesc = new DescriptionList(); rightDesc.Add("Contact", eventItemOccurrence.ContactPersonAlias != null && eventItemOccurrence.ContactPersonAlias.Person != null ? eventItemOccurrence.ContactPersonAlias.Person.FullName : ""); rightDesc.Add("Phone", eventItemOccurrence.ContactPhone); rightDesc.Add("Email", eventItemOccurrence.ContactEmail); lRightDetails.Text = rightDesc.Html; lOccurrenceNotes.Visible = !string.IsNullOrWhiteSpace(eventItemOccurrence.Note); lOccurrenceNotes.Text = eventItemOccurrence.Note; }
/// <summary> /// Creates the event description from the lava template. Default is used if one is not specified in the request. /// </summary> /// <param name="eventItem">The event item.</param> /// <param name="occurrence">The occurrence.</param> /// <returns></returns> private string CreateEventDescription(EventItem eventItem, EventItemOccurrence occurrence) { // get the lava template int templateDefinedValueId = 0; var iCalTemplateDefinedValue = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEFAULT_ICAL_DESCRIPTION); if (request.QueryString["templateid"] != null) { int.TryParse(request.QueryString["templateid"], out templateDefinedValueId); if (templateDefinedValueId > 0) { iCalTemplateDefinedValue = DefinedValueCache.Get(templateDefinedValueId); } } var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null); mergeFields.Add("EventItem", eventItem); mergeFields.Add("EventItemOccurrence", occurrence); return(iCalTemplateDefinedValue.GetAttributeValue("Template").ResolveMergeFields(mergeFields)); }
/// <summary> /// Handles the Delete event of the gCalendarItemOccurrenceList control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void gCalendarItemOccurrenceList_Delete(object sender, RowEventArgs e) { using (RockContext rockContext = new RockContext()) { EventItemOccurrenceService eventItemOccurrenceService = new EventItemOccurrenceService(rockContext); EventItemOccurrence eventItemOccurrence = eventItemOccurrenceService.Get(e.RowKeyId); if (eventItemOccurrence != null) { string errorMessage; if (!eventItemOccurrenceService.CanDelete(eventItemOccurrence, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } eventItemOccurrenceService.Delete(eventItemOccurrence); rockContext.SaveChanges(); } } BindCampusGrid(); }
/// <summary>s /// Adds columns for any Account attributes marked as Show In Grid /// </summary> protected void AddAttributeColumns() { // Remove attribute columns foreach (var column in gCalendarItemOccurrenceList.Columns.OfType <AttributeField>().ToList()) { gCalendarItemOccurrenceList.Columns.Remove(column); } int entityTypeId = new EventItemOccurrence().TypeId; foreach (var attribute in new AttributeService(new RockContext()).Queryable() .Where(a => a.EntityTypeId == entityTypeId && a.IsGridColumn ) .OrderBy(a => a.Order) .ThenBy(a => a.Name)) { string dataFieldExpression = attribute.Key; bool columnExists = gCalendarItemOccurrenceList.Columns.OfType <AttributeField>().FirstOrDefault(a => a.DataField.Equals(dataFieldExpression)) != null; if (!columnExists) { AttributeField boundField = new AttributeField(); boundField.DataField = dataFieldExpression; boundField.AttributeId = attribute.Id; boundField.HeaderText = attribute.Name; var attributeCache = Rock.Web.Cache.AttributeCache.Get(attribute.Id); if (attributeCache != null) { boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue; } gCalendarItemOccurrenceList.Columns.Add(boundField); } } }
/// <summary> /// Handles the Click event of the btnDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnDelete_Click(object sender, EventArgs e) { using (var rockContext = new RockContext()) { EventItemOccurrenceService eventItemOccurrenceService = new EventItemOccurrenceService(rockContext); EventItemOccurrence eventItemOccurrence = eventItemOccurrenceService.Get(hfEventItemOccurrenceId.Value.AsInteger()); if (eventItemOccurrence != null) { string errorMessage; if (!eventItemOccurrenceService.CanDelete(eventItemOccurrence, out errorMessage)) { mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); return; } eventItemOccurrenceService.Delete(eventItemOccurrence); rockContext.SaveChanges(); } } NavigateToParentPage(); }
private void DisplayDetails() { var registrationSlug = PageParameter("Slug"); var eventItemOccurrenceId = PageParameter("EventOccurrenceId").AsInteger(); if (eventItemOccurrenceId == 0 && registrationSlug.IsNullOrWhiteSpace()) { lOutput.Text = "<div class='alert alert-warning'>No event was available from the querystring.</div>"; return; } EventItemOccurrence eventItemOccurrence = null; Dictionary <int, int> registrationCounts = null; using (var rockContext = new RockContext()) { var eventItemOccurrenceService = new EventItemOccurrenceService(rockContext); var qry = eventItemOccurrenceService .Queryable("EventItem, EventItem.Photo, Campus, Linkages") .Include(e => e.Linkages.Select(l => l.RegistrationInstance)); if (eventItemOccurrenceId > 0) { qry = qry.Where(i => i.Id == eventItemOccurrenceId); } else { qry = qry.Where(i => i.Linkages.Any(l => l.UrlSlug == registrationSlug)); } eventItemOccurrence = qry.FirstOrDefault(); registrationCounts = qry .SelectMany(o => o.Linkages) .SelectMany(l => l.RegistrationInstance.Registrations) .Select(r => new { r.RegistrationInstanceId, RegistrantCount = r.Registrants.Where(reg => !reg.OnWaitList).Count() }) .GroupBy(r => r.RegistrationInstanceId) .Select(r => new { RegistrationInstanceId = r.Key, TotalRegistrantCount = r.Sum(rr => rr.RegistrantCount) }) .ToDictionary(r => r.RegistrationInstanceId, r => r.TotalRegistrantCount); if (eventItemOccurrence == null) { lOutput.Text = "<div class='alert alert-warning'>We could not find that event.</div>"; return; } var mergeFields = new Dictionary <string, object>(); mergeFields.Add("RegistrationPage", LinkedPageRoute("RegistrationPage")); var campusEntityType = EntityTypeCache.Get("Rock.Model.Campus"); var contextCampus = RockPage.GetCurrentContext(campusEntityType) as Campus; if (contextCampus != null) { mergeFields.Add("CampusContext", contextCampus); } // determine registration status (Register, Full, or Join Wait List) for each unique registration instance Dictionary <int, string> registrationStatusLabels = new Dictionary <int, string>(); var registrationInstances = eventItemOccurrence .Linkages .Where(l => l.RegistrationInstanceId != null) .Select(a => a.RegistrationInstance) .Distinct(); foreach (var registrationInstance in registrationInstances) { int?maxRegistrantCount = null; var currentRegistrationCount = 0; if (registrationInstance != null) { maxRegistrantCount = registrationInstance.MaxAttendees; } int?registrationSpotsAvailable = null; int registrationCount = 0; if (maxRegistrantCount.HasValue && registrationCounts.TryGetValue(registrationInstance.Id, out registrationCount)) { currentRegistrationCount = registrationCount; registrationSpotsAvailable = maxRegistrantCount - currentRegistrationCount; } string registrationStatusLabel = "Register"; if (registrationSpotsAvailable.HasValue && registrationSpotsAvailable.Value < 1) { if (registrationInstance.RegistrationTemplate.WaitListEnabled) { registrationStatusLabel = "Join Wait List"; } else { registrationStatusLabel = "Full"; } } registrationStatusLabels.Add(registrationInstance.Id, registrationStatusLabel); } // Status of first registration instance mergeFields.Add("RegistrationStatusLabel", registrationStatusLabels.Values.FirstOrDefault()); // Status of each registration instance mergeFields.Add("RegistrationStatusLabels", registrationStatusLabels); mergeFields.Add("EventItemOccurrence", eventItemOccurrence); mergeFields.Add("Event", eventItemOccurrence != null ? eventItemOccurrence.EventItem : null); mergeFields.Add("CurrentPerson", CurrentPerson); lOutput.Text = GetAttributeValue("LavaTemplate").ResolveMergeFields(mergeFields); if (GetAttributeValue("SetPageTitle").AsBoolean()) { string pageTitle = eventItemOccurrence != null ? eventItemOccurrence.EventItem.Name : "Event"; RockPage.PageTitle = pageTitle; RockPage.BrowserTitle = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name); RockPage.Header.Title = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name); } } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { EventItemOccurrence eventItemOccurrence = null; using (var rockContext = new RockContext()) { bool newItem = false; var eventItemOccurrenceService = new EventItemOccurrenceService(rockContext); var eventItemOccurrenceGroupMapService = new EventItemOccurrenceGroupMapService(rockContext); var registrationInstanceService = new RegistrationInstanceService(rockContext); var scheduleService = new ScheduleService(rockContext); int eventItemOccurrenceId = hfEventItemOccurrenceId.ValueAsInt(); if (eventItemOccurrenceId != 0) { eventItemOccurrence = eventItemOccurrenceService .Queryable("Linkages") .Where(i => i.Id == eventItemOccurrenceId) .FirstOrDefault(); } if (eventItemOccurrence == null) { newItem = true; eventItemOccurrence = new EventItemOccurrence { EventItemId = PageParameter("EventItemId").AsInteger() }; eventItemOccurrenceService.Add(eventItemOccurrence); } int?newCampusId = ddlCampus.SelectedValueAsInt(); if (eventItemOccurrence.CampusId != newCampusId) { eventItemOccurrence.CampusId = newCampusId; if (newCampusId.HasValue) { var campus = new CampusService(rockContext).Get(newCampusId.Value); eventItemOccurrence.Campus = campus; } else { eventItemOccurrence.Campus = null; } } eventItemOccurrence.Location = tbLocation.Text; string iCalendarContent = sbSchedule.iCalendarContent; var calEvent = ScheduleICalHelper.GetCalenderEvent(iCalendarContent); if (calEvent != null && calEvent.DTStart != null) { if (eventItemOccurrence.Schedule == null) { eventItemOccurrence.Schedule = new Schedule(); } eventItemOccurrence.Schedule.iCalendarContent = iCalendarContent; } else { if (eventItemOccurrence.ScheduleId.HasValue) { var oldSchedule = scheduleService.Get(eventItemOccurrence.ScheduleId.Value); if (oldSchedule != null) { scheduleService.Delete(oldSchedule); } } } if (!eventItemOccurrence.ContactPersonAliasId.Equals(ppContact.PersonAliasId)) { PersonAlias personAlias = null; eventItemOccurrence.ContactPersonAliasId = ppContact.PersonAliasId; if (eventItemOccurrence.ContactPersonAliasId.HasValue) { personAlias = new PersonAliasService(rockContext).Get(eventItemOccurrence.ContactPersonAliasId.Value); } if (personAlias != null) { eventItemOccurrence.ContactPersonAlias = personAlias; } } eventItemOccurrence.ContactPhone = PhoneNumber.FormattedNumber(PhoneNumber.DefaultCountryCode(), pnPhone.Number); eventItemOccurrence.ContactEmail = tbEmail.Text; eventItemOccurrence.Note = htmlOccurrenceNote.Text; // Remove any linkage no longer in UI Guid uiLinkageGuid = LinkageState != null ? LinkageState.Guid : Guid.Empty; foreach (var linkage in eventItemOccurrence.Linkages.Where(l => !l.Guid.Equals(uiLinkageGuid)).ToList()) { eventItemOccurrence.Linkages.Remove(linkage); eventItemOccurrenceGroupMapService.Delete(linkage); } // Add/Update linkage in UI if (!uiLinkageGuid.Equals(Guid.Empty)) { var linkage = eventItemOccurrence.Linkages.Where(l => l.Guid.Equals(uiLinkageGuid)).FirstOrDefault(); if (linkage == null) { linkage = new EventItemOccurrenceGroupMap(); eventItemOccurrence.Linkages.Add(linkage); } linkage.CopyPropertiesFrom(LinkageState); // update registration instance if (LinkageState.RegistrationInstance != null) { if (LinkageState.RegistrationInstance.Id != 0) { linkage.RegistrationInstance = registrationInstanceService.Get(LinkageState.RegistrationInstance.Id); } if (linkage.RegistrationInstance == null) { var registrationInstance = new RegistrationInstance(); registrationInstanceService.Add(registrationInstance); linkage.RegistrationInstance = registrationInstance; } linkage.RegistrationInstance.CopyPropertiesFrom(LinkageState.RegistrationInstance); } } if (!Page.IsValid) { return; } if (!eventItemOccurrence.IsValid) { // Controls will render the error messages return; } rockContext.SaveChanges(); var qryParams = new Dictionary <string, string>(); qryParams.Add("EventCalendarId", PageParameter("EventCalendarId")); qryParams.Add("EventItemId", PageParameter("EventItemId")); if (newItem) { NavigateToParentPage(qryParams); } else { qryParams.Add("EventItemOccurrenceId", eventItemOccurrence.Id.ToString()); NavigateToPage(RockPage.Guid, qryParams); } } }
public void RockCleanup_Execute_ShouldUpdateEventItemOccurrences() { var referenceDate = new DateTime(2020, 1, 1); // Get the sample data schedule for Saturday 4:30pm. var rockContext = new RockContext(); var scheduleService = new ScheduleService(rockContext); var schedule = scheduleService.Get(TestGuids.Schedules.ScheduleSat1630Guid.AsGuid()); // Create a new inactive schedule. var scheduleInactive = scheduleService.Get(testScheduleGuid); if (scheduleInactive == null) { scheduleInactive = new Schedule(); scheduleService.Add(scheduleInactive); } scheduleInactive.Name = "Test Schedule"; scheduleInactive.Guid = testScheduleGuid; scheduleInactive.IsActive = false; rockContext.SaveChanges(); // Create the Test Events. var eventItemService = new EventItemService(rockContext); // Test Event 1 (active) var testEvent1 = eventItemService.Get(testEvent1Guid); if (testEvent1 != null) { eventItemService.Delete(testEvent1); rockContext.SaveChanges(); } testEvent1 = new EventItem(); testEvent1.Guid = testEvent1Guid; testEvent1.Name = "Test Event 1"; eventItemService.Add(testEvent1); // Add an occurrence with a future schedule and no NextDateTime value. // When the cleanup task executes, this should be updated to the next occurrence after the reference date. var testOccurrence11 = new EventItemOccurrence(); testOccurrence11.ScheduleId = schedule.Id; testOccurrence11.Guid = testEventOccurrence11Guid; testOccurrence11.NextStartDateTime = null; testEvent1.EventItemOccurrences.Add(testOccurrence11); // Add an occurrence with a NextDateTime that is prior to the reference date. // When the cleanup task executes, this should be updated to the next occurrence after the reference date. var testOccurrence12 = new EventItemOccurrence(); testOccurrence12.ScheduleId = schedule.Id; testOccurrence12.Guid = testEventOccurrence12Guid; testOccurrence12.NextStartDateTime = referenceDate.AddDays(-1); testEvent1.EventItemOccurrences.Add(testOccurrence12); // Add an occurrence with a NextDateTime and an inactive Schedule. // When the cleanup task executes, the NextDateTime should be set to null. var testOccurrence13 = new EventItemOccurrence(); testOccurrence13.ScheduleId = scheduleInactive.Id; testOccurrence13.Guid = testEventOccurrence13Guid; testOccurrence13.NextStartDateTime = referenceDate.AddDays(7); testEvent1.EventItemOccurrences.Add(testOccurrence13); // Test Event 2 (inactive) var testEvent2 = eventItemService.Get(testEvent2Guid); if (testEvent2 != null) { eventItemService.Delete(testEvent2); rockContext.SaveChanges(); } testEvent2 = new EventItem(); testEvent2.Guid = testEvent2Guid; testEvent2.Name = "Test Event 2"; testEvent2.IsActive = false; eventItemService.Add(testEvent2); // Add an occurrence with a future schedule and a NextDateTime value. // When the cleanup task executes, the NextDateTime should be set to null. var testOccurrence21 = new EventItemOccurrence(); testOccurrence21.ScheduleId = schedule.Id; testOccurrence21.Guid = testEventOccurrence21Guid; testOccurrence21.NextStartDateTime = referenceDate; testEvent2.EventItemOccurrences.Add(testOccurrence21); // Save changes without triggering the pre-save, to avoid updating the NextEventDate field. rockContext.SaveChanges(new SaveChangesArgs { DisablePrePostProcessing = true }); // Run the cleanup task to verify the results for the reference date. RunRockCleanupTaskUpdateEventNextOccurrenceDatesAndVerify(referenceDate); // Re-run the task to verify that the results are adjusted for the current date. RunRockCleanupTaskUpdateEventNextOccurrenceDatesAndVerify(RockDateTime.Now); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { // Get any querystring variables ContentItemId = PageParameter("ContentItemId").AsIntegerOrNull(); EventItemOccurrenceId = PageParameter("EventItemOccurrenceId").AsIntegerOrNull(); EventItemId = PageParameter("EventItemId").AsIntegerOrNull(); EventCalendarId = PageParameter("EventCalendarId").AsIntegerOrNull(); // Determine current page number based on querystring values if (ContentItemId.HasValue) { PageNumber = 5; } else if (EventItemOccurrenceId.HasValue) { PageNumber = 4; } else if (EventItemId.HasValue) { PageNumber = 3; } else if (EventCalendarId.HasValue) { PageNumber = 2; } else { PageNumber = 1; } // Load objects neccessary to display names using (var rockContext = new RockContext()) { ContentChannelItem contentItem = null; EventItemOccurrence eventItemOccurrence = null; EventItem eventItem = null; EventCalendar eventCalendar = null; if (ContentItemId.HasValue && ContentItemId.Value > 0) { var contentChannel = new ContentChannelItemService(rockContext).Get(ContentItemId.Value); } if (EventItemOccurrenceId.HasValue && EventItemOccurrenceId.Value > 0) { eventItemOccurrence = new EventItemOccurrenceService(rockContext).Get(EventItemOccurrenceId.Value); if (eventItemOccurrence != null) { eventItem = eventItemOccurrence.EventItem; if (eventItem != null && !EventItemId.HasValue) { EventItemId = eventItem.Id; } } } if (eventItem == null && EventItemId.HasValue && EventItemId.Value > 0) { eventItem = new EventItemService(rockContext).Get(EventItemId.Value); } if (EventCalendarId.HasValue && EventCalendarId.Value > 0) { eventCalendar = new EventCalendarService(rockContext).Get(EventCalendarId.Value); } // Set the names based on current object values lCalendarName.Text = eventCalendar != null ? eventCalendar.Name : "Calendar"; lCalendarItemName.Text = eventItem != null ? eventItem.Name : "Event"; lEventOccurrenceName.Text = eventItemOccurrence != null ? (eventItemOccurrence.Campus != null ? eventItemOccurrence.Campus.Name : "All Campuses") : "Event Occurrence"; lContentItemName.Text = contentItem != null ? contentItem.Title : "Content Item"; } } divCalendars.Attributes["class"] = GetDivClass(1); divCalendar.Attributes["class"] = GetDivClass(2); divCalendarItem.Attributes["class"] = GetDivClass(3); divEventOccurrence.Attributes["class"] = GetDivClass(4); divContentItem.Attributes["class"] = GetDivClass(5); }
private void ShowEditDetails( EventItemOccurrence eventItemOccurrence ) { LinkageState = new EventItemOccurrenceGroupMap { Guid = Guid.Empty }; if ( eventItemOccurrence == null ) { eventItemOccurrence = new EventItemOccurrence(); } if ( eventItemOccurrence.Id == 0 ) { lActionTitle.Text = ActionTitle.Add( "Event Occurrence" ).FormatAsHtmlTitle(); var copyFromOccurrenceId = PageParameter( "CopyFromId" ).AsInteger(); if ( copyFromOccurrenceId > 0 ) { var oldOccurrence = new EventItemOccurrenceService( new RockContext() ).Get( copyFromOccurrenceId ); if ( oldOccurrence != null ) { // clone the workflow type eventItemOccurrence = oldOccurrence.Clone( false ); eventItemOccurrence.Schedule = oldOccurrence.Schedule; eventItemOccurrence.EventItem = oldOccurrence.EventItem; eventItemOccurrence.ContactPersonAlias = oldOccurrence.ContactPersonAlias; eventItemOccurrence.CreatedByPersonAlias = null; eventItemOccurrence.CreatedByPersonAliasId = null; eventItemOccurrence.CreatedDateTime = RockDateTime.Now; eventItemOccurrence.ModifiedByPersonAlias = null; eventItemOccurrence.ModifiedByPersonAliasId = null; eventItemOccurrence.ModifiedDateTime = RockDateTime.Now; eventItemOccurrence.Id = 0; eventItemOccurrence.Guid = Guid.NewGuid(); // Clone the linkage var linkage = oldOccurrence.Linkages.FirstOrDefault(); if ( linkage != null ) { LinkageState = linkage.Clone( false ); LinkageState.EventItemOccurrenceId = 0; LinkageState.CreatedByPersonAlias = null; LinkageState.CreatedByPersonAliasId = null; LinkageState.CreatedDateTime = RockDateTime.Now; LinkageState.ModifiedByPersonAlias = null; LinkageState.ModifiedByPersonAliasId = null; LinkageState.ModifiedDateTime = RockDateTime.Now; LinkageState.Id = 0; LinkageState.Guid = Guid.NewGuid(); LinkageState.RegistrationInstance = linkage.RegistrationInstance != null ? linkage.RegistrationInstance.Clone( false ) : new RegistrationInstance(); LinkageState.RegistrationInstance.RegistrationTemplate = linkage.RegistrationInstance != null && linkage.RegistrationInstance.RegistrationTemplate != null ? linkage.RegistrationInstance.RegistrationTemplate.Clone( false ) : new RegistrationTemplate(); LinkageState.Group = linkage.Group != null ? linkage.Group.Clone( false ) : new Group(); } } } } else { lActionTitle.Text = ActionTitle.Edit( "Event Occurrence" ).FormatAsHtmlTitle(); var registration = eventItemOccurrence.Linkages.FirstOrDefault(); if ( registration != null ) { LinkageState = registration.Clone( false ); LinkageState.RegistrationInstance = registration.RegistrationInstance != null ? registration.RegistrationInstance.Clone( false ) : new RegistrationInstance(); LinkageState.RegistrationInstance.RegistrationTemplate = registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null ? registration.RegistrationInstance.RegistrationTemplate.Clone( false ) : new RegistrationTemplate(); LinkageState.Group = registration.Group != null ? registration.Group.Clone( false ) : new Group(); } } SetEditMode( true ); hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString(); ddlCampus.SetValue( eventItemOccurrence.CampusId ?? -1 ); tbLocation.Text = eventItemOccurrence.Location; if ( eventItemOccurrence.Schedule != null ) { sbSchedule.iCalendarContent = eventItemOccurrence.Schedule.iCalendarContent; lScheduleText.Text = eventItemOccurrence.Schedule.FriendlyScheduleText; } else { sbSchedule.iCalendarContent = string.Empty; lScheduleText.Text = string.Empty; } ppContact.SetValue( eventItemOccurrence.ContactPersonAlias != null ? eventItemOccurrence.ContactPersonAlias.Person : null ); pnPhone.Text = eventItemOccurrence.ContactPhone; tbEmail.Text = eventItemOccurrence.ContactEmail; htmlOccurrenceNote.Text = eventItemOccurrence.Note; DisplayRegistration(); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="eventItemId">The eventItem identifier.</param> public void ShowDetail( int eventItemOccurrenceId ) { pnlDetails.Visible = true; EventItemOccurrence eventItemOccurrence = null; var rockContext = new RockContext(); bool canEdit = UserCanEdit; if ( !eventItemOccurrenceId.Equals( 0 ) ) { eventItemOccurrence = new EventItemOccurrenceService( rockContext ).Get( eventItemOccurrenceId ); } if ( eventItemOccurrence == null ) { eventItemOccurrence = new EventItemOccurrence { Id = 0 }; } if ( !canEdit ) { int? calendarId = PageParameter( "EventCalendarId" ).AsIntegerOrNull(); if ( calendarId.HasValue ) { var calendar = new EventCalendarService( rockContext ).Get( calendarId.Value ); if ( calendar != null ) { canEdit = calendar.IsAuthorized( Authorization.EDIT, CurrentPerson ); } } } bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( !canEdit ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( EventItemOccurrence.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails( eventItemOccurrence ); } else { btnEdit.Visible = true; btnDelete.Visible = true; if ( !eventItemOccurrenceId.Equals( 0)) { ShowReadonlyDetails( eventItemOccurrence ); } else { ShowEditDetails( eventItemOccurrence ); } } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { EventItemOccurrence eventItemOccurrence = null; using ( var rockContext = new RockContext() ) { bool newItem = false; var eventItemOccurrenceService = new EventItemOccurrenceService( rockContext ); var eventItemOccurrenceGroupMapService = new EventItemOccurrenceGroupMapService( rockContext ); var registrationInstanceService = new RegistrationInstanceService( rockContext ); var scheduleService = new ScheduleService( rockContext ); int eventItemOccurrenceId = hfEventItemOccurrenceId.ValueAsInt(); if ( eventItemOccurrenceId != 0 ) { eventItemOccurrence = eventItemOccurrenceService .Queryable( "Linkages" ) .Where( i => i.Id == eventItemOccurrenceId ) .FirstOrDefault(); } if ( eventItemOccurrence == null ) { newItem = true; eventItemOccurrence = new EventItemOccurrence{ EventItemId = PageParameter("EventItemId").AsInteger() }; eventItemOccurrenceService.Add( eventItemOccurrence ); } int? newCampusId = ddlCampus.SelectedValueAsInt(); if ( eventItemOccurrence.CampusId != newCampusId ) { eventItemOccurrence.CampusId = newCampusId; if ( newCampusId.HasValue ) { var campus = new CampusService( rockContext ).Get( newCampusId.Value ); eventItemOccurrence.Campus = campus; } else { eventItemOccurrence.Campus = null; } } eventItemOccurrence.Location = tbLocation.Text; string iCalendarContent = sbSchedule.iCalendarContent; var calEvent = ScheduleICalHelper.GetCalenderEvent( iCalendarContent ); if ( calEvent != null && calEvent.DTStart != null ) { if ( eventItemOccurrence.Schedule == null ) { eventItemOccurrence.Schedule = new Schedule(); } eventItemOccurrence.Schedule.iCalendarContent = iCalendarContent; } else { if ( eventItemOccurrence.ScheduleId.HasValue ) { var oldSchedule = scheduleService.Get( eventItemOccurrence.ScheduleId.Value ); if ( oldSchedule != null ) { scheduleService.Delete( oldSchedule ); } } } if ( !eventItemOccurrence.ContactPersonAliasId.Equals( ppContact.PersonAliasId )) { PersonAlias personAlias = null; eventItemOccurrence.ContactPersonAliasId = ppContact.PersonAliasId; if ( eventItemOccurrence.ContactPersonAliasId.HasValue ) { personAlias = new PersonAliasService( rockContext ).Get( eventItemOccurrence.ContactPersonAliasId.Value ); } if ( personAlias != null ) { eventItemOccurrence.ContactPersonAlias = personAlias; } } eventItemOccurrence.ContactPhone = PhoneNumber.FormattedNumber( PhoneNumber.DefaultCountryCode(), pnPhone.Number ); eventItemOccurrence.ContactEmail = tbEmail.Text; eventItemOccurrence.Note = htmlOccurrenceNote.Text; // Remove any linkage no longer in UI Guid uiLinkageGuid = LinkageState != null ? LinkageState.Guid : Guid.Empty; foreach( var linkage in eventItemOccurrence.Linkages.Where( l => !l.Guid.Equals(uiLinkageGuid)).ToList()) { eventItemOccurrence.Linkages.Remove( linkage ); eventItemOccurrenceGroupMapService.Delete( linkage ); } // Add/Update linkage in UI if ( !uiLinkageGuid.Equals( Guid.Empty )) { var linkage = eventItemOccurrence.Linkages.Where( l => l.Guid.Equals( uiLinkageGuid)).FirstOrDefault(); if ( linkage == null ) { linkage = new EventItemOccurrenceGroupMap(); eventItemOccurrence.Linkages.Add( linkage ); } linkage.CopyPropertiesFrom( LinkageState ); // update registration instance if ( LinkageState.RegistrationInstance != null ) { if ( LinkageState.RegistrationInstance.Id != 0 ) { linkage.RegistrationInstance = registrationInstanceService.Get( LinkageState.RegistrationInstance.Id ); } if ( linkage.RegistrationInstance == null ) { var registrationInstance = new RegistrationInstance(); registrationInstanceService.Add( registrationInstance ); linkage.RegistrationInstance = registrationInstance; } linkage.RegistrationInstance.CopyPropertiesFrom( LinkageState.RegistrationInstance ); } } if ( !Page.IsValid ) { return; } if ( !eventItemOccurrence.IsValid ) { // Controls will render the error messages return; } rockContext.SaveChanges(); var qryParams = new Dictionary<string, string>(); qryParams.Add( "EventCalendarId", PageParameter( "EventCalendarId" ) ); qryParams.Add( "EventItemId", PageParameter( "EventItemId" ) ); if ( newItem ) { NavigateToParentPage( qryParams ); } else { qryParams.Add( "EventItemOccurrenceId", eventItemOccurrence.Id.ToString() ); NavigateToPage( RockPage.Guid, qryParams ); } } }
private void ShowReadonlyDetails( EventItemOccurrence eventItemOccurrence ) { SetEditMode( false ); hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString(); lActionTitle.Text = "Event Occurrence".FormatAsHtmlTitle(); var leftDesc = new DescriptionList(); leftDesc.Add( "Campus", eventItemOccurrence.Campus != null ? eventItemOccurrence.Campus.Name : "All" ); leftDesc.Add( "Location Description", eventItemOccurrence.Location ); leftDesc.Add( "Schedule", eventItemOccurrence.Schedule != null ? eventItemOccurrence.Schedule.FriendlyScheduleText : string.Empty ); if ( eventItemOccurrence.Linkages.Any() ) { var linkage = eventItemOccurrence.Linkages.First(); if ( linkage.RegistrationInstance != null ) { var qryParams = new Dictionary<string, string>(); qryParams.Add( "RegistrationInstanceId", linkage.RegistrationInstance.Id.ToString() ); leftDesc.Add( "Registration", string.Format( "<a href='{0}'>{1}</a>", LinkedPageUrl( "RegistrationInstancePage", qryParams ), linkage.RegistrationInstance.Name ) ); } if ( linkage.Group != null ) { var qryParams = new Dictionary<string, string>(); qryParams.Add( "GroupId", linkage.Group.Id.ToString() ); leftDesc.Add( "Group", string.Format( "<a href='{0}'>{1}</a>", LinkedPageUrl( "GroupDetailPage", qryParams ), linkage.Group.Name ) ); } } lLeftDetails.Text = leftDesc.Html; var rightDesc = new DescriptionList(); rightDesc.Add( "Contact", eventItemOccurrence.ContactPersonAlias != null && eventItemOccurrence.ContactPersonAlias.Person != null ? eventItemOccurrence.ContactPersonAlias.Person.FullName : "" ); rightDesc.Add( "Phone", eventItemOccurrence.ContactPhone ); rightDesc.Add( "Email", eventItemOccurrence.ContactEmail ); lRightDetails.Text = rightDesc.Html; lOccurrenceNotes.Visible = !string.IsNullOrWhiteSpace( eventItemOccurrence.Note ); lOccurrenceNotes.Text = eventItemOccurrence.Note; }
public static EventItemOccurrence SyncOccurrence( ESpace.Event eSpaceEvent, ESpace.Occurrence eSpaceOccurrence, EventItem rockEvent, CampusCache campus, Person contactPerson, string occurrenceApprovedAttributeKey, out bool changed, out bool attributeChanged ) { attributeChanged = false; changed = false; // Get or create the linked Rock occurrence var rockOccurrence = rockEvent.EventItemOccurrences.FirstOrDefault(e => e.ForeignKey == ForeignKey_eSpaceOccurrenceId && e.ForeignId == eSpaceOccurrence.OccurrenceId.Value && e.CampusId == campus.Id ); if (rockOccurrence == null) { rockOccurrence = new EventItemOccurrence { ForeignKey = ForeignKey_eSpaceOccurrenceId, ForeignId = eSpaceOccurrence.OccurrenceId.Value, CampusId = campus.Id }; rockEvent.EventItemOccurrences.Add(rockOccurrence); changed = true; } // Update the linked Contact Person if (rockOccurrence.ContactPersonAliasId != contactPerson?.PrimaryAliasId) { rockOccurrence.ContactPersonAliasId = contactPerson?.PrimaryAliasId; changed = true; } // Get the contact data var eventContact = eSpaceEvent.Contacts.FirstOrDefault(); // Update the Contact Email var eventContactEmail = eventContact?.Email ?? ""; if (rockOccurrence.ContactEmail != eventContactEmail) { rockOccurrence.ContactEmail = eventContactEmail; changed = true; } // Update the Contact Phone var eventContactPhone = PhoneNumber.FormattedNumber(null, eventContact?.Phone, false); if (rockOccurrence.ContactPhone != eventContactPhone) { rockOccurrence.ContactPhone = eventContactPhone; changed = true; } // Update the event location var eventLocation = eSpaceEvent.OffsiteLocation ?? ""; if (rockOccurrence.Location != eventLocation) { rockOccurrence.Location = eventLocation; changed = true; } // Sync the schedule SyncSchedule(eSpaceOccurrence, rockOccurrence, out var scheduleChanged); changed = changed || scheduleChanged; // Check the approved attribute if (!string.IsNullOrEmpty(occurrenceApprovedAttributeKey)) { rockOccurrence.LoadAttributes(); var eSpaceApprovedValue = eSpaceOccurrence.OccurrenceStatus == ESpaceStatus_Approved ? "Approved" : ""; var rockApprovedValue = rockOccurrence.GetAttributeValue(occurrenceApprovedAttributeKey); if (rockApprovedValue != eSpaceApprovedValue) { rockOccurrence.SetAttributeValue(occurrenceApprovedAttributeKey, eSpaceApprovedValue); attributeChanged = true; } } return(rockOccurrence); }
private void ShowEditDetails( EventItemOccurrence eventItemOccurrence ) { if ( eventItemOccurrence == null ) { eventItemOccurrence = new EventItemOccurrence(); } if ( eventItemOccurrence.Id == 0 ) { lActionTitle.Text = ActionTitle.Add( "Event Occurrence" ).FormatAsHtmlTitle(); } else { lActionTitle.Text = ActionTitle.Edit( "Event Occurrence" ).FormatAsHtmlTitle(); } SetEditMode( true ); hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString(); ddlCampus.SetValue( eventItemOccurrence.CampusId ?? -1 ); tbLocation.Text = eventItemOccurrence.Location; if ( eventItemOccurrence.Schedule != null ) { sbSchedule.iCalendarContent = eventItemOccurrence.Schedule.iCalendarContent; lScheduleText.Text = eventItemOccurrence.Schedule.FriendlyScheduleText; } else { sbSchedule.iCalendarContent = string.Empty; lScheduleText.Text = string.Empty; } ppContact.SetValue( eventItemOccurrence.ContactPersonAlias != null ? eventItemOccurrence.ContactPersonAlias.Person : null ); pnPhone.Text = eventItemOccurrence.ContactPhone; tbEmail.Text = eventItemOccurrence.ContactEmail; htmlOccurrenceNote.Text = eventItemOccurrence.Note; LinkageState = new EventItemOccurrenceGroupMap { Guid = Guid.Empty }; var registration = eventItemOccurrence.Linkages.FirstOrDefault(); if ( registration != null ) { LinkageState = registration.Clone( false ); LinkageState.RegistrationInstance = registration.RegistrationInstance != null ? registration.RegistrationInstance.Clone( false ) : new RegistrationInstance(); LinkageState.RegistrationInstance.RegistrationTemplate = registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null ? registration.RegistrationInstance.RegistrationTemplate.Clone( false ) : new RegistrationTemplate(); LinkageState.Group = registration.Group != null ? registration.Group.Clone( false ) : new Group(); } DisplayRegistration(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { // Get any querystring variables ContentItemId = PageParameter("ContentItemId").AsIntegerOrNull(); EventItemOccurrenceId = PageParameter("EventItemOccurrenceId").AsIntegerOrNull(); EventItemId = PageParameter("EventItemId").AsIntegerOrNull(); EventCalendarId = PageParameter("EventCalendarId").AsIntegerOrNull(); // Load objects necessary to display names using (var rockContext = new RockContext()) { ContentChannelItem contentItem = null; EventItemOccurrence eventItemOccurrence = null; EventItem eventItem = null; EventCalendar eventCalendar = null; if (ContentItemId.HasValue && ContentItemId.Value > 0) { PageNumber = 5; var contentChannel = new ContentChannelItemService(rockContext).Get(ContentItemId.Value); } if (EventItemOccurrenceId.HasValue && EventItemOccurrenceId.Value > 0) { PageNumber = PageNumber ?? 4; eventItemOccurrence = new EventItemOccurrenceService(rockContext).Get(EventItemOccurrenceId.Value); if (eventItemOccurrence != null) { eventItem = eventItemOccurrence.EventItem; if (eventItem != null && !EventItemId.HasValue) { EventItemId = eventItem.Id; } } } if (EventItemId.HasValue && EventItemId.Value > 0) { PageNumber = PageNumber ?? 3; if (eventItem == null) { eventItem = new EventItemService(rockContext).Get(EventItemId.Value); } if (!EventCalendarId.HasValue) { foreach (var cal in eventItem.EventCalendarItems) { EventCalendarId = EventCalendarId ?? cal.EventCalendarId; if (cal.EventCalendar.IsAuthorized(Authorization.EDIT, CurrentPerson)) { EventCalendarId = cal.EventCalendarId; break; } } } } if (EventCalendarId.HasValue && EventCalendarId.Value > 0) { PageNumber = PageNumber ?? 2; eventCalendar = new EventCalendarService(rockContext).Get(EventCalendarId.Value); } PageNumber = PageNumber ?? 1; // Set the names based on current object values lCalendarName.Text = eventCalendar != null ? eventCalendar.Name : "Calendar"; lCalendarItemName.Text = eventItem != null ? eventItem.Name : "Event"; lEventOccurrenceName.Text = eventItemOccurrence != null ? (eventItemOccurrence.Campus != null ? eventItemOccurrence.Campus.Name : "All Campuses") : "Event Occurrence"; lContentItemName.Text = contentItem != null ? contentItem.Title : "Content Item"; } } divCalendars.Attributes["class"] = GetDivClass(1); divCalendar.Attributes["class"] = GetDivClass(2); divCalendarItem.Attributes["class"] = GetDivClass(3); divEventOccurrence.Attributes["class"] = GetDivClass(4); divContentItem.Attributes["class"] = GetDivClass(5); }
/// <summary> /// Modifies the Rock Solid Finances Class to add multiple schedules and campuses. /// </summary> private static void InitializeEventRockSolidFinancesClassTestData() { var rockContext = new RockContext(); // Add a new campus var campusService = new CampusService(rockContext); var campus2 = campusService.Get(SecondaryCampusGuidString.AsGuid()); if (campus2 == null) { campus2 = new Campus(); campusService.Add(campus2); } campus2.Name = "Stepping Stone"; campus2.Guid = SecondaryCampusGuidString.AsGuid(); rockContext.SaveChanges(); // Get existing schedules. var scheduleService = new ScheduleService(rockContext); var scheduleSat1630Id = scheduleService.GetId(ScheduleSat1630Guid.AsGuid()); var scheduleSat1800Id = scheduleService.GetId(ScheduleSun1200Guid.AsGuid()); // Get Event "Rock Solid Finances". var eventItemService = new EventItemService(rockContext); var eventItemOccurrenceService = new EventItemOccurrenceService(rockContext); var financeEvent = eventItemService.Get(EventFinancesClassGuid.AsGuid()); // Add an occurrence of this event for each Schedule. var financeEvent1 = eventItemOccurrenceService.Get(FinancesClassOccurrenceSat1630Guid.AsGuid()); if (financeEvent1 == null) { financeEvent1 = new EventItemOccurrence(); } var mainCampusId = CampusCache.GetId(MainCampusGuidString.AsGuid()); var secondCampusId = CampusCache.GetId(SecondaryCampusGuidString.AsGuid()); financeEvent1.Location = "Meeting Room 1"; financeEvent1.ForeignKey = TestDataForeignKey; financeEvent1.ScheduleId = scheduleSat1630Id; financeEvent1.Guid = FinancesClassOccurrenceSat1630Guid.AsGuid(); financeEvent1.CampusId = mainCampusId; financeEvent.EventItemOccurrences.Add(financeEvent1); var financeEvent2 = eventItemOccurrenceService.Get(FinancesClassOccurrenceSun1200Guid.AsGuid()); if (financeEvent2 == null) { financeEvent2 = new EventItemOccurrence(); } financeEvent2.Location = "Meeting Room 2"; financeEvent2.ForeignKey = TestDataForeignKey; financeEvent2.ScheduleId = scheduleSat1800Id; financeEvent2.Guid = FinancesClassOccurrenceSun1200Guid.AsGuid(); financeEvent2.CampusId = secondCampusId; financeEvent.EventItemOccurrences.Add(financeEvent2); rockContext.SaveChanges(); }