/// <summary> /// Loads the attribute values /// </summary> /// <param name="exportOptions">The export options.</param> /// <param name="rockContext">The rock context.</param> /// <param name="modelExportList">The model export list.</param> /// <param name="pagedEntityQry">The paged entity query.</param> public static void LoadAttributeValues(ExportOptions exportOptions, RockContext rockContext, IEnumerable <ModelExport> modelExportList, IQueryable <IEntity> pagedEntityQry) { if (exportOptions.AttributeList?.Any() != true) { return; } var attributeIdsList = exportOptions.AttributeList.Select(a => a.Id).ToList(); var attributeValuesQuery = new AttributeValueService(rockContext).Queryable() .Where(a => attributeIdsList.Contains(a.AttributeId)) .Where(a => pagedEntityQry.Any(p => p.Id == a.EntityId.Value)) .Select(a => new { EntityId = a.EntityId.Value, AttributeId = a.AttributeId, AttributeValue = a.Value }); var attributeValuesList = attributeValuesQuery.ToList(); var attributeValuesLookup = attributeValuesList.GroupBy(a => a.EntityId).ToDictionary(k => k.Key, v => v.Select(a => new AttributeValueCache { AttributeId = a.AttributeId, EntityId = a.EntityId, Value = a.AttributeValue })); Dictionary <string, object> defaultAttributeValues; if (exportOptions.AttributeReturnType == AttributeReturnType.Formatted) { defaultAttributeValues = exportOptions.AttributeList.ToDictionary(k => k.Key, v => ( object )v.DefaultValueAsFormatted); } else { defaultAttributeValues = exportOptions.AttributeList.ToDictionary(k => k.Key, v => v.DefaultValueAsType); } foreach (var modelExport in modelExportList) { var databaseAttributeValues = attributeValuesLookup.GetValueOrNull(modelExport.Id); modelExport.AttributesExport = new AttributesExport(); // initialize with DefaultValues modelExport.AttributesExport.AttributeValues = new Dictionary <string, object>(defaultAttributeValues); // update with values specific to Person if (databaseAttributeValues?.Any() == true) { foreach (var databaseAttributeValue in databaseAttributeValues) { var attributeCache = AttributeCache.Get(databaseAttributeValue.AttributeId); if (exportOptions.AttributeReturnType == AttributeReturnType.Formatted) { modelExport.AttributesExport.AttributeValues[attributeCache.Key] = databaseAttributeValue.ValueFormatted; } else { modelExport.AttributesExport.AttributeValues[attributeCache.Key] = databaseAttributeValue.ValueAsType; } } } } }
/// <summary> /// Update the Disc Adaptive Score /// </summary> public void UpdateDiscAdaptiveScore() { //Adaptive D using (var rockContext = new Rock.Data.RockContext()) { var attribute = new AttributeService(rockContext).Get(new Guid("EDE5E199-37BE-424F-A788-5CDCC064157C")); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(b => b.AttributeId == attribute.Id && b.Value != string.Empty); attributeValues.ToList().ForEach(a => { a.Value = DiscService.GetAdaptiveScoreValue(DiscService.AttributeKeys.AdaptiveD, Convert.ToInt32(Math.Round(a.Value.AsDecimal() * 0.28m, 0))).ToString(); }); rockContext.SaveChanges(); } //Adaptive S using (var rockContext = new Rock.Data.RockContext()) { var attribute = new AttributeService(rockContext).Get(new Guid("2512DAC6-BBC4-4D0E-A01D-E92F94C534BD")); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(b => b.AttributeId == attribute.Id && b.Value != string.Empty); attributeValues.ToList().ForEach(a => { a.Value = DiscService.GetAdaptiveScoreValue(DiscService.AttributeKeys.AdaptiveS, Convert.ToInt32(Math.Round(a.Value.AsDecimal() * 0.28m, 0))).ToString(); }); rockContext.SaveChanges(); } //Adaptive I using (var rockContext = new Rock.Data.RockContext()) { var attribute = new AttributeService(rockContext).Get(new Guid("7F0A1794-0150-413B-9AE1-A6B0D6373DA6")); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(b => b.AttributeId == attribute.Id && b.Value != string.Empty); attributeValues.ToList().ForEach(a => { a.Value = DiscService.GetAdaptiveScoreValue(DiscService.AttributeKeys.AdaptiveI, Convert.ToInt32(Math.Round(a.Value.AsDecimal() * 0.28m, 0))).ToString(); }); rockContext.SaveChanges(); } //Adaptive C using (var rockContext = new Rock.Data.RockContext()) { var attribute = new AttributeService(rockContext).Get(new Guid("4A2E1539-4ECC-40B9-9EBD-C0C84EC8DA36")); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(b => b.AttributeId == attribute.Id && b.Value != string.Empty); attributeValues.ToList().ForEach(a => { a.Value = DiscService.GetAdaptiveScoreValue(DiscService.AttributeKeys.AdaptiveC, Convert.ToInt32(Math.Round(a.Value.AsDecimal() * 0.28m, 0))).ToString(); }); rockContext.SaveChanges(); } }
/// <summary> /// Update the Disc Natural Score /// </summary> public void UpdateDiscNaturalScore() { //Natural D using (var rockContext = new Rock.Data.RockContext()) { var attribute = new AttributeService(rockContext).Get(new Guid("86670F7D-07BA-4ECE-9BB9-9D94B5FB5F26")); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(b => b.AttributeId == attribute.Id && b.Value != string.Empty); attributeValues.ToList().ForEach(a => { a.Value = DiscService.GetNaturalScoreValue(DiscService.AttributeKeys.NaturalD, Convert.ToInt32(Math.Round((27 - a.Value.AsDecimal() * 0.78m), 0))).ToString(); }); rockContext.SaveChanges(); } //Natural S using (var rockContext = new Rock.Data.RockContext()) { var attribute = new AttributeService(rockContext).Get(new Guid("FA4341B4-28C7-409E-A101-548BB5759BE6")); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(b => b.AttributeId == attribute.Id && b.Value != string.Empty); attributeValues.ToList().ForEach(a => { a.Value = DiscService.GetNaturalScoreValue(DiscService.AttributeKeys.NaturalS, Convert.ToInt32(Math.Round((27 - a.Value.AsDecimal() * 0.78m), 0))).ToString(); }); rockContext.SaveChanges(); } //Natural I using (var rockContext = new Rock.Data.RockContext()) { var attribute = new AttributeService(rockContext).Get(new Guid("3EFF4FEF-EE4C-40E2-8DBD-80F3276852DA")); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(b => b.AttributeId == attribute.Id && b.Value != string.Empty); attributeValues.ToList().ForEach(a => { a.Value = DiscService.GetNaturalScoreValue(DiscService.AttributeKeys.NaturalI, Convert.ToInt32(Math.Round((26 - a.Value.AsDecimal() * 0.78m), 0))).ToString(); }); rockContext.SaveChanges(); } //Natural C using (var rockContext = new Rock.Data.RockContext()) { var attribute = new AttributeService(rockContext).Get(new Guid("3A10ECFB-8CAB-4CCA-8B29-298756CD3251")); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(b => b.AttributeId == attribute.Id && b.Value != string.Empty); attributeValues.ToList().ForEach(a => { a.Value = DiscService.GetNaturalScoreValue(DiscService.AttributeKeys.NaturalC, Convert.ToInt32(Math.Round((26 - a.Value.AsDecimal() * 0.78m), 0))).ToString(); }); rockContext.SaveChanges(); } }
public List <RockEventbriteEvent> Events(bool loadEventbriteEvent = false) { var retVar = new List <RockEventbriteEvent>(); var ebFieldType = FieldTypeCache.Get(EBGuid.FieldType.EVENTBRITE_EVENT.AsGuid()); if (ebFieldType != null) { using (RockContext rockContext = new RockContext()) { var attributes = new AttributeService(rockContext).GetByFieldTypeId(ebFieldType.Id).Select(a => a.Id); var attributeValues = new AttributeValueService(rockContext).Queryable().Where(av => attributes.Contains(av.AttributeId) && av.EntityId.HasValue && av.Value != "").Select(av => av.EntityId.Value); var groups = new GroupService(rockContext).GetListByIds(attributeValues.ToList()); foreach (var group in groups) { retVar.Add(new RockEventbriteEvent(group, loadEventbriteEvent)); } } } return(retVar); }