/// <summary> /// Gets the edit value as the IEntity.Id /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public int?GetEditValueAsEntityId(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues) { Guid guid = GetEditValue(control, configurationValues).AsGuid(); var item = CampusCache.Read(guid); return(item != null ? item.Id : (int?)null); }
/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns() { bddlCampus.Items.Clear(); bddlWeekend.Items.Clear(); //bddlService.Items.Clear(); // Load Campuses foreach (var campus in GetCampuses()) { bddlCampus.Items.Add(new ListItem(campus.Name, campus.Id.ToString())); } bddlCampus.SetValue(_selectedCampusId.Value); bddlCampus.SelectedIndexChanged += BddlCampus_SelectedIndexChanged; // Load Weeks var weeksBack = GetAttributeValue("WeeksBack").AsInteger(); var weeksAhead = GetAttributeValue("WeeksAhead").AsInteger(); foreach (var date in GetWeekendDates(weeksBack, weeksAhead)) { bddlWeekend.Items.Add(new ListItem("Week Ending Sunday " + date.ToShortDateString(), date.ToString("o"))); } bddlWeekend.SetValue(_selectedWeekend.Value.ToString("o")); // Load service times foreach (var service in GetServices(CampusCache.Read(_selectedCampusId.Value))) { //bddlService.Items.Add( new ListItem( service.Name, service.Id.ToString() ) ); } //bddlService.SetValue( _selectedServiceId.Value ); }
/// <summary> /// Handles the filter display /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void rAccountFilter_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Campus": int?campusId = e.Value.AsIntegerOrNull(); if (campusId.HasValue) { var campus = CampusCache.Read(campusId.Value); if (campus != null) { e.Value = campus.Name; } } break; case "Account Name": case "Active": case "Public": case "Tax Deductible": e.Value = e.Value; break; default: e.Value = string.Empty; break; } }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { var rockContext = (RockContext)serviceInstance.Context; string[] selectionValues = selection.Split('|'); if (selectionValues.Length >= 1) { var campusGuidList = selectionValues[0].Split(',').AsGuidList(); List <int> campusIds = new List <int>(); foreach (var campusGuid in campusGuidList) { var campus = CampusCache.Read(campusGuid); if (campus != null) { campusIds.Add(campus.Id); } } if (!campusIds.Any()) { return(null); } var qry = new BenevolenceRequestService((RockContext)serviceInstance.Context).Queryable() .Where(p => campusIds.Contains(p.CampusId ?? 0)); Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.BenevolenceRequest>(qry, parameterExpression, "p"); return(extractedFilterExpression); } return(null); }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { var rockContext = (RockContext)serviceInstance.Context; string[] selectionValues = selection.Split('|'); if (selectionValues.Length >= 1) { var campus = CampusCache.Read(selectionValues[0].AsGuid()); if (campus == null) { return(null); } GroupMemberService groupMemberService = new GroupMemberService(rockContext); var groupMemberServiceQry = groupMemberService.Queryable() .Where(xx => xx.Group.GroupType.Guid == new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY)) .Where(xx => xx.Group.CampusId == campus.Id); var qry = new PersonService(rockContext).Queryable() .Where(p => groupMemberServiceQry.Any(xx => xx.PersonId == p.Id)); Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"); return(extractedFilterExpression); } return(null); }
/// <summary> /// Formats the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override string FormatSelection(Type entityType, string selection) { string result = "Campuses"; string[] selectionValues = selection.Split('|'); if (selectionValues.Length >= 1) { var campusGuidList = selectionValues[0].Split(',').AsGuidList(); List <string> campusNames = new List <string>(); foreach (var campusGuid in campusGuidList) { var campus = CampusCache.Read(campusGuid); if (campus != null) { campusNames.Add(campus.Name); } } if (campusNames.Any()) { result = "Campuses: " + campusNames.AsDelimited(", "); } } return(result); }
/// <summary> /// Updates the selection from page parameters. /// </summary> /// <param name="selection">The selection.</param> /// <param name="rockBlock">The rock block.</param> /// <returns></returns> public string UpdateSelectionFromPageParameters(string selection, Rock.Web.UI.RockBlock rockBlock) { string[] selectionValues = selection?.Split('|') ?? new string[] { "" }; if (selectionValues.Length >= 1) { var campusId = rockBlock.PageParameter("CampusId").AsIntegerOrNull(); if (campusId == null) { var campusEntity = rockBlock.ContextEntity <Campus>(); if (campusEntity != null) { campusId = campusEntity.Id; } } if (campusId.HasValue) { var selectedCampus = CampusCache.Read(campusId.Value); if (selectedCampus != null) { selectionValues[0] = selectedCampus.Guid.ToString(); return(selectionValues.ToList().AsDelimited("|")); } } } return(selection); }
/// <summary> /// Gfs the settings_ display filter value. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void gfSettings_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Campus": { if (!string.IsNullOrWhiteSpace(e.Value)) { e.Value = CampusCache.Read(int.Parse(e.Value)).Name; } break; } case "Agency Type": { int?valueId = gfSettings.GetUserPreference("Agency Type").AsInteger(false); if (valueId.HasValue) { var definedValue = DefinedValueCache.Read(valueId.Value); if (definedValue != null) { e.Value = definedValue.Name; } } break; } default: { e.Value = string.Empty; break; } } }
/// <summary> /// Handles the SelectionChanged event of the bddlCampus 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 bddlCampus_SelectionChanged(object sender, EventArgs e) { SetBlockUserPreference("Campus", bddlCampus.SelectedValue); var campus = CampusCache.Read(ExtensionMethods.SelectedValueAsInt(bddlCampus) ?? 0); bddlCampus.Title = campus != null ? campus.Name : "All Campuses"; BindGrid(); }
/// <summary> /// Formats the filter value value. /// </summary> /// <param name="configurationValues">The configuration values.</param> /// <param name="value">The value.</param> /// <returns></returns> public override string FormatFilterValueValue(Dictionary <string, ConfigurationValue> configurationValues, string value) { var campusGuids = value.SplitDelimitedValues().AsGuidList(); var campuses = campusGuids.Select(a => CampusCache.Read(a)).Where(c => c != null); return(campuses.Select(a => a.Name).ToList().AsDelimited(", ", " or ")); }
/// <summary> /// When setting a value, check to see if the value is in the list. If it's not, and it's a valid campus, /// Rebuild the list of items to include it. /// </summary> /// <param name="value">The value.</param> public void CheckItem(int?value) { if (value.HasValue && this.Items.FindByValue(value.Value.ToString()) == null && CampusCache.Read(value.Value) != null) { LoadItems(value); } }
/// <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); _occurrence = GetOccurrence(); if (!Page.IsPostBack) { pnlDetails.Visible = _canEdit; if (_canEdit) { if (_allowCampusFilter) { var campus = CampusCache.Read(GetBlockUserPreference("Campus").AsInteger()); if (campus != null) { bddlCampus.Title = campus.Name; ExtensionMethods.SetValue((ListControl)bddlCampus, campus.Id); } } BindLocations(); ShowDetails(); } else { nbNotice.Heading = "Sorry"; nbNotice.Text = "<p>You're not authorized to update the attendance for the selected group.</p>"; nbNotice.NotificationBoxType = NotificationBoxType.Danger; nbNotice.Visible = true; } } else { if (_attendees != null) { foreach (var item in lvMembers.Items) { var hfMember = item.FindControl("hfMember") as HiddenField; var cbMember = item.FindControl("cbMember") as CheckBox; if (hfMember != null && cbMember != null) { int personId = hfMember.ValueAsInt(); var attendance = _attendees.Where(a => a.PersonId == personId).FirstOrDefault(); if (attendance != null) { attendance.Attended = cbMember.Checked; } } } } } }
private bool CheckSelection() { // If campus and schedule have been selected before, assume current weekend if (_selectedCampusId.HasValue && _selectedServiceId.HasValue && !_selectedWeekend.HasValue) { _selectedWeekend = RockDateTime.Today.SundayDate(); } var options = new List <ServiceMetricSelectItem>(); if (!_selectedCampusId.HasValue) { lSelection.Text = "Select Location:"; foreach (var campus in GetCampuses()) { options.Add(new ServiceMetricSelectItem("Campus", campus.Id.ToString(), campus.Name)); } } if (!options.Any() && !_selectedWeekend.HasValue) { var weeksAhead = GetAttributeValue("WeeksAhead").AsInteger(); lSelection.Text = "Select Week of:"; foreach (var weekend in GetWeekendDates(1, weeksAhead)) { options.Add(new ServiceMetricSelectItem("Weekend", weekend.ToString("o"), "Sunday " + weekend.ToShortDateString())); } } if (!options.Any() && !_selectedServiceId.HasValue) { lSelection.Text = "Select Service Time:"; foreach (var service in GetServices(CampusCache.Read(_selectedCampusId.Value))) { options.Add(new ServiceMetricSelectItem("Service", service.Id.ToString(), service.Name)); } } if (options.Any()) { rptrSelection.DataSource = options; rptrSelection.DataBind(); pnlSelection.Visible = true; pnlMetrics.Visible = false; return(false); } else { pnlSelection.Visible = false; pnlMetrics.Visible = true; return(true); } }
/// <summary> /// Rs the filter_ display filter value. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void rFilter_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e) { if (AvailableAttributes != null) { var attribute = AvailableAttributes.FirstOrDefault(a => MakeKeyUniqueToGroup(a.Key) == e.Key); if (attribute != null) { try { var values = JsonConvert.DeserializeObject <List <string> >(e.Value); e.Value = attribute.FieldType.Field.FormatFilterValues(attribute.QualifierValues, values); return; } catch { // intentionally ignore } } } if (e.Key == MakeKeyUniqueToGroup("First Name")) { return; } else if (e.Key == MakeKeyUniqueToGroup("Last Name")) { return; } else if (e.Key == MakeKeyUniqueToGroup("Role")) { e.Value = ResolveValues(e.Value, cblRole); } else if (e.Key == MakeKeyUniqueToGroup("Status")) { e.Value = ResolveValues(e.Value, cblGroupMemberStatus); } else if (e.Key == MakeKeyUniqueToGroup("Campus")) { var campusId = e.Value.AsIntegerOrNull(); if (campusId.HasValue) { var campusCache = CampusCache.Read(campusId.Value); e.Value = campusCache.Name; } else { e.Value = null; } } else { e.Value = string.Empty; } }
/// <summary> /// Sets the edit value from IEntity.Id value /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="id">The identifier.</param> public void SetEditValueFromEntityId(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues, int?id) { CampusCache item = null; if (id.HasValue) { item = CampusCache.Read(id.Value); } string guidValue = item != null?item.Guid.ToString() : string.Empty; SetEditValue(control, configurationValues, guidValue); }
/// <summary> /// Handles the DisplayFilterValue event of the gfBatchFilter control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs"/> instance containing the event data.</param> protected void gfBatchFilter_DisplayFilterValue(object sender, Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Status": e.Value = e.Value.ConvertToEnum <BatchStatus>().ConvertToString(); break; case "Campus": e.Value = CampusCache.Read(int.Parse(e.Value)).Name; break; } }
/// <summary> /// Sets the value. /// Expects value as a Campus.Guid as string /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="value">The value.</param> public override void SetEditValue(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues, string value) { CampusPicker campusPicker = control as CampusPicker; if (campusPicker != null) { Guid guid = value.AsGuid(); // get the item (or null) and set it var campus = CampusCache.Read(guid); campusPicker.SelectedCampusId = campus == null ? 0 : campus.Id; } }
/// <summary> /// Puts the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="group">The group.</param> public override void Put(int id, Group group) { var familyGroupType = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()); if (familyGroupType != null && familyGroupType.Id == group.GroupTypeId) { SetProxyCreation(true); var rockContext = (RockContext)Service.Context; var existingGroup = Service.Get(id); if (existingGroup != null) { var changes = new List <string>(); string oldCampus = existingGroup.Campus != null ? existingGroup.Campus.Name : string.Empty; string newCampus = group.Campus != null ? group.Campus.Name : string.Empty; if (group.CampusId.HasValue && string.IsNullOrWhiteSpace(newCampus)) { var campus = CampusCache.Read(group.CampusId.Value); newCampus = campus != null ? campus.Name : string.Empty; } History.EvaluateChange(changes, "Campus", oldCampus, newCampus); if (changes.Any()) { System.Web.HttpContext.Current.Items.Add("CurrentPerson", GetPerson()); int?modifiedByPersonAliasId = group.ModifiedAuditValuesAlreadyUpdated ? group.ModifiedByPersonAliasId : (int?)null; foreach (var fm in existingGroup.Members) { HistoryService.SaveChanges( rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_FAMILY_CHANGES.AsGuid(), fm.PersonId, changes, existingGroup.Name, typeof(Group), existingGroup.Id, true, modifiedByPersonAliasId); } } } } base.Put(id, group); }
/// <summary> /// Gets the campus identifier from selection. /// </summary> /// <param name="selectionValues">The selection values.</param> /// <returns></returns> private static int?GetCampusIdFromSelection(string[] selectionValues) { Guid?campusGuid = selectionValues[0].AsGuidOrNull(); int? campusId = null; if (campusGuid.HasValue) { var campus = CampusCache.Read(campusGuid.Value); if (campus != null) { campusId = campus.Id; } } return(campusId); }
/// <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(System.Web.UI.Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed) { string formattedValue = value; if (!string.IsNullOrWhiteSpace(value)) { var campus = CampusCache.Read(value.AsGuid()); if (campus != null) { formattedValue = campus.Name; } } return(base.FormatValue(parentControl, formattedValue, configurationValues, condensed)); }
/// <summary> /// Checks the items. /// </summary> /// <param name="values">The values.</param> public void CheckItems(List <int> values) { if (values.Any()) { foreach (int value in values) { if (this.Items.FindByValue(value.ToString()) == null && CampusCache.Read(value) != null) { LoadItems(values); return; } } } }
/// <summary> /// Gets the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="controls">The controls.</param> /// <returns></returns> public override string GetSelection(Type entityType, Control[] controls) { var campusId = (controls[0] as CampusPicker).SelectedCampusId; if (campusId.HasValue) { var campus = CampusCache.Read(campusId.Value); if (campus != null) { return(campus.Guid.ToString()); } } return(string.Empty); }
/// <summary> /// Handles the DisplayFilterValue event of the gfBatchFilter control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs"/> instance containing the event data.</param> protected void gfBatchFilter_DisplayFilterValue(object sender, Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Row Limit": { // row limit filter was removed, so hide it just in case e.Value = null; break; } case "Date Range": { e.Value = DateRangePicker.FormatDelimitedValues(e.Value); break; } case "Status": { var status = e.Value.ConvertToEnumOrNull <BatchStatus>(); if (status.HasValue) { e.Value = status.ConvertToString(); } else { e.Value = string.Empty; } break; } case "Campus": { var campus = CampusCache.Read(e.Value.AsInteger()); if (campus != null) { e.Value = campus.Name; } else { e.Value = string.Empty; } break; } } }
/// <summary> /// Sets the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="controls">The controls.</param> /// <param name="selection">The selection.</param> public override void SetSelection(Type entityType, Control[] controls, string selection) { string[] selectionValues = selection.Split('|'); if (selectionValues.Length >= 1) { var campusPicker = controls[0] as CampusPicker; var selectedCampus = CampusCache.Read(selectionValues[0].AsGuid()); if (selectedCampus != null) { campusPicker.SelectedCampusId = selectedCampus.Id; } else { campusPicker.SelectedCampusId = null; } } }
/// <summary> /// Gets the defined value value. /// </summary> /// <param name="campus">The defined value.</param> /// <param name="campusId">The defined value identifier.</param> /// <param name="blankValue">The blank value.</param> /// <returns></returns> public static string GetCampusValue(Campus campus, int?campusId, string blankValue) { if (campus != null) { return(campus.Name); } if (campusId.HasValue) { var dv = CampusCache.Read(campusId.Value); if (dv != null) { return(dv.Name); } } return(blankValue); }
/// <summary> /// Formats the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override string FormatSelection(Type entityType, string selection) { string result = "Campus"; string[] selectionValues = selection.Split('|'); if (selectionValues.Length >= 1) { Guid campusGuid = selectionValues[0].AsGuid(); var campus = CampusCache.Read(campusGuid); if (campus != null) { result = "Campus: " + campus.Name; } } return(result); }
public Template LocationByGuid(string guid) { try { RockContext rockContext = new RockContext(); LocationService locationService = new LocationService(rockContext); var location = locationService.Get(guid.AsGuid()); var campus = CampusCache.Read(location.CampusId ?? 0); return(new Template() { Name = location.Name, Id = location.Id, Description = campus?.Name ?? "" }); } catch (Exception e) { ExceptionLogService.LogException(e, System.Web.HttpContext.Current); return(new Template()); } }
/// <summary> /// Handles the filter display /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void rAccountFilter_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Campus": int?campusId = e.Value.AsIntegerOrNull(); if (campusId.HasValue) { var campus = CampusCache.Read(campusId.Value); if (campus != null) { e.Value = campus.Name; } } break; } }
/// <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) { if (_allowCampusFilter) { var campus = CampusCache.Read(GetBlockUserPreference("Campus").AsInteger()); if (campus != null) { bddlCampus.Title = campus.Name; bddlCampus.SetValue(campus.Id); } } ShowContent(); } }
/// <summary> /// Reads new values entered by the user for the field /// returns Campus.Guid as string /// </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(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues) { CampusPicker campusPicker = control as CampusPicker; if (campusPicker != null) { int?campusId = campusPicker.SelectedCampusId; if (campusId.HasValue) { var campus = CampusCache.Read(campusId.Value); if (campus != null) { return(campus.Guid.ToString()); } } } return(string.Empty); }