/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed) { string formattedValue = string.Empty; if (!string.IsNullOrWhiteSpace(value)) { var names = new List <string>(); var guids = new List <Guid>(); foreach (string guidValue in value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { Guid?guid = guidValue.AsGuidOrNull(); if (guid.HasValue) { guids.Add(guid.Value); } } if (guids.Any()) { var schedules = guids.Select(a => NamedScheduleCache.Get(a)).ToList(); if (schedules.Any()) { formattedValue = string.Join(", ", (from schedule in schedules select schedule?.Name).ToArray()); } } } return(base.FormatValue(parentControl, formattedValue, null, condensed)); }
/// <summary> /// Sets the value from cache. /// </summary> /// <param name="schedule">The schedule.</param> private void SetValueFromCache(NamedScheduleCache schedule) { if (schedule != null) { // If setting the value to an inactive schedule, enable the "Show Inactive Schedules" checkbox. if (AllowInactiveSelection && !schedule.IsActive) { _cbShowInactiveSchedules.Checked = true; SetExtraRestParams(true); } ItemId = schedule.Id.ToString(); string parentCategoryIds = string.Empty; var parentCategory = schedule.Category; while (parentCategory != null) { parentCategoryIds = parentCategory.Id + "," + parentCategoryIds; parentCategory = parentCategory.ParentCategory; } ExpandedCategoryIds = parentCategoryIds.TrimEnd(new[] { ',' }); ItemName = schedule.Name; } else { ItemId = Constants.None.IdValue; ItemName = Constants.None.TextHtml; } }
/// <summary> /// Sets the value. /// </summary> /// <param name="schedule">The schedule.</param> public void SetValue(Schedule schedule) { if (schedule == null) { SetValueFromCache(null); } else { SetValueFromCache(NamedScheduleCache.Get(schedule.Id)); } }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed) { string formattedValue = string.Empty; var scheduleGuid = value.AsGuidOrNull(); if (scheduleGuid.HasValue) { return(NamedScheduleCache.Get(scheduleGuid.Value)?.Name); } return(base.FormatValue(parentControl, formattedValue, null, condensed)); }
/// <summary> /// Reads new values entered by the user for the field /// </summary> /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public override string GetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues) { var picker = control as SchedulePicker; if (picker != null) { int? itemId = picker.SelectedValue.AsIntegerOrNull(); Guid?itemGuid = null; if (itemId.HasValue && itemId > 0) { itemGuid = NamedScheduleCache.Get(itemId.Value)?.Guid; } return(itemGuid?.ToString() ?? string.Empty); } return(null); }
/// <summary> /// Sets the value. /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="value">The value.</param> public override void SetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues, string value) { var picker = control as SchedulePicker; if (picker != null) { Guid?itemGuid = value.AsGuidOrNull(); if (itemGuid.HasValue) { var itemId = NamedScheduleCache.GetId(itemGuid.Value); picker.SetValue(itemId); } else { picker.SetValue(( int? )null); } } }
/// <summary> /// Sets the value. /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="value">The value.</param> public override void SetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues, string value) { var picker = control as SchedulePicker; if (picker != null) { var guids = value?.SplitDelimitedValues().AsGuidList() ?? new List <Guid>(); if (guids.Any()) { var scheduleIds = guids.Select(g => NamedScheduleCache.GetId(g)).Where(a => a.HasValue).Select(a => a.Value).ToList(); picker.SetValues(scheduleIds); } else { // make sure that no schedules are selected picker.SetValues(new List <int>()); } } }
/// <summary> /// Reads new values entered by the user for the field /// </summary> /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public override string GetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues) { var picker = control as SchedulePicker; string result = string.Empty; if (picker != null) { var ids = picker.SelectedValuesAsInt().ToList(); var schedules = ids.Select(a => NamedScheduleCache.Get(a)).Where(a => a != null).ToList(); if (schedules.Any()) { result = schedules.Select(s => s.Guid.ToString()).ToList().AsDelimited(","); } return(result); } return(null); }
/// <summary> /// Sets the values on select. /// </summary> protected override void SetValuesOnSelect() { this.SetValuesFromCache(ItemIds.AsIntegerList().Select(a => NamedScheduleCache.Get(a)).ToList()); }
/// <summary> /// Sets the value on select. /// </summary> protected override void SetValueOnSelect() { SetValueFromCache(NamedScheduleCache.Get(ItemId.AsInteger())); }
/// <summary> /// Sets the values. /// </summary> /// <param name="schedules">The schedules.</param> public void SetValues(IEnumerable <Schedule> schedules) { SetValuesFromCache(schedules.Select(a => NamedScheduleCache.Get(a.Id)).ToList()); }
/// <summary> /// Method that will be called on an entity immediately before the item is saved by context /// </summary> protected override void PreSave() { PersonAttendanceHistoryChangeList = new History.HistoryChangeList(); _isDeleted = State == EntityContextState.Deleted; bool previousDidAttendValue; bool previouslyDeclined; if (State == EntityContextState.Added) { previousDidAttendValue = false; previouslyDeclined = false; } else { // get original values so we can detect whether the value changed previousDidAttendValue = ( bool )Entry.OriginalValues.GetReadOnlyValueOrDefault("DidAttend", false); previouslyDeclined = (Entry.OriginalValues.GetReadOnlyValueOrDefault("RSVP", null) as RSVP? ) == RSVP.No; } // if the record was changed to Declined, queue a GroupScheduleCancellationTransaction in PostSaveChanges _declinedScheduledAttendance = (previouslyDeclined == false) && Entity.IsScheduledPersonDeclined(); if (previousDidAttendValue == false && Entity.DidAttend == true) { var launchMemberAttendedGroupWorkflowMsg = GetLaunchMemberAttendedGroupWorkflowMessage(); launchMemberAttendedGroupWorkflowMsg.Send(); } var attendance = this.Entity; if (State == EntityContextState.Modified) { preSavePersonAliasId = attendance.PersonAliasId; var originalOccurrenceId = ( int? )OriginalValues[nameof(attendance.OccurrenceId)]; if (originalOccurrenceId.HasValue && attendance.OccurrenceId != originalOccurrenceId.Value) { var attendanceOccurrenceService = new AttendanceOccurrenceService(this.RockContext); var originalOccurrence = attendanceOccurrenceService.GetNoTracking(originalOccurrenceId.Value); var currentOccurrence = attendanceOccurrenceService.GetNoTracking(attendance.OccurrenceId); if (originalOccurrence != null && currentOccurrence != null) { if (originalOccurrence.GroupId != currentOccurrence.GroupId) { History.EvaluateChange(PersonAttendanceHistoryChangeList, "Group", originalOccurrence.Group?.Name, currentOccurrence.Group?.Name); } if (originalOccurrence.ScheduleId.HasValue && currentOccurrence.ScheduleId.HasValue && originalOccurrence.ScheduleId.Value != currentOccurrence.ScheduleId.Value) { History.EvaluateChange(PersonAttendanceHistoryChangeList, "Schedule", NamedScheduleCache.Get(originalOccurrence.ScheduleId.Value)?.Name, NamedScheduleCache.Get(currentOccurrence.ScheduleId.Value)?.Name); } if (originalOccurrence.LocationId.HasValue && currentOccurrence.LocationId.HasValue && originalOccurrence.LocationId.Value != currentOccurrence.LocationId.Value) { History.EvaluateChange(PersonAttendanceHistoryChangeList, "Location", NamedLocationCache.Get(originalOccurrence.LocationId.Value)?.Name, NamedLocationCache.Get(currentOccurrence.LocationId.Value)?.Name); } } } } else if (State == EntityContextState.Deleted) { preSavePersonAliasId = ( int? )OriginalValues[nameof(attendance.PersonAliasId)]; PersonAttendanceHistoryChangeList.AddChange(History.HistoryVerb.Delete, History.HistoryChangeType.Record, "Attendance"); } base.PreSave(); }