コード例 #1
0
        /// <summary>
        /// Reads the specified GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public static DefinedTypeCache Read(Guid guid)
        {
            ObjectCache cache    = MemoryCache.Default;
            object      cacheObj = cache[guid.ToString()];

            if (cacheObj != null)
            {
                return(Read((int)cacheObj));
            }
            else
            {
                var definedTypeService = new DefinedTypeService();
                var definedTypeModel   = definedTypeService
                                         .Queryable("DefinedValues")
                                         .Where(t => t.Guid == guid)
                                         .FirstOrDefault();

                if (definedTypeModel != null)
                {
                    definedTypeModel.LoadAttributes();
                    var definedType = new DefinedTypeCache(definedTypeModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(DefinedTypeCache.CacheKey(definedType.Id), definedType, cachePolicy);
                    cache.Set(definedType.Guid.ToString(), definedType.Id, cachePolicy);

                    return(definedType);
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #2
0
        private static int LoadByGuid2(Guid guid, RockContext rockContext)
        {
            var definedTypeService = new DefinedTypeService(rockContext);

            return(definedTypeService
                   .Queryable().AsNoTracking()
                   .Where(c => c.Guid.Equals(guid))
                   .Select(c => c.Id)
                   .FirstOrDefault());
        }
コード例 #3
0
        private static DefinedTypeCache LoadById2(int id, RockContext rockContext)
        {
            var definedTypeService = new DefinedTypeService(rockContext);
            var definedTypeModel   = definedTypeService
                                     .Queryable()
                                     .Where(t => t.Id == id)
                                     .FirstOrDefault();

            if (definedTypeModel != null)
            {
                return(new DefinedTypeCache(definedTypeModel));
            }

            return(null);
        }
コード例 #4
0
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            if (ddlCategoryFilter.SelectedItem == null)
            {
                ddlCategoryFilter.Items.Clear();
                ddlCategoryFilter.Items.Add("[All]");

                DefinedTypeService typeService = new DefinedTypeService();
                var items = typeService.Queryable().
                            Where(a => a.Category != "" && a.Category != null).
                            OrderBy(a => a.Category).
                            Select(a => a.Category).
                            Distinct().ToList();

                foreach (var item in items)
                {
                    ddlCategoryFilter.Items.Add(item);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Returns DefinedType object from cache.  If definedType does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static DefinedTypeCache Read(int id)
        {
            string cacheKey = DefinedTypeCache.CacheKey(id);

            ObjectCache      cache       = MemoryCache.Default;
            DefinedTypeCache definedType = cache[cacheKey] as DefinedTypeCache;

            if (definedType != null)
            {
                return(definedType);
            }
            else
            {
                var definedTypeService = new DefinedTypeService();
                var definedTypeModel   = definedTypeService
                                         .Queryable("DefinedValues")
                                         .Where(t => t.Id == id)
                                         .FirstOrDefault();

                if (definedTypeModel != null)
                {
                    definedTypeModel.LoadAttributes();
                    definedType = new DefinedTypeCache(definedTypeModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(cacheKey, definedType, cachePolicy);
                    cache.Set(definedType.Guid.ToString(), definedType.Id, cachePolicy);

                    return(definedType);
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #6
0
        protected void rptPartions_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                /*var ddlAttribute = ( DropDownList ) e.Item.FindControl( "ddlAttribute" );
                 * ddlAttribute.DataSource = attributes;
                 * ddlAttribute.DataTextField = "Value";
                 * ddlAttribute.DataValueField = "Key";
                 * ddlAttribute.DataBind();
                 */

                var         partition          = (( PartitionSettings )e.Item.DataItem);
                var         phPartitionControl = ( PlaceHolder )e.Item.FindControl("phPartitionControl");
                RockTextBox tbAttributeKey     = (( RockTextBox )e.Item.FindControl("tbAttributeKey"));
                switch (partition.PartitionType)
                {
                case "Campus":
                    phPartitionControl.Controls.Add(new LiteralControl("<div class='row'><div class='col-md-4'><strong>Name</strong></div><div class='col-md-8'><strong>Group</strong></div>"));

                    foreach (var campus in CampusCache.All())
                    {
                        phPartitionControl.Controls.Add(new LiteralControl("<div class='row'><div class='col-xs-4'>"));
                        var campusCbl = new CheckBox();
                        campusCbl.ID = campus.Guid.ToString() + "_" + partition.Guid + "_checkbox";
                        if (partition.PartitionValue != null)
                        {
                            campusCbl.Checked = partition.PartitionValue.Contains(campus.Guid.ToString());
                        }
                        campusCbl.Text            = campus.Name;
                        campusCbl.CheckedChanged += CampusCbl_CheckedChanged;
                        campusCbl.AutoPostBack    = true;
                        if (partition.PartitionValue != null)
                        {
                            campusCbl.Checked = partition.PartitionValue.Contains(campus.Guid.ToString());
                        }
                        phPartitionControl.Controls.Add(campusCbl);
                        phPartitionControl.Controls.Add(new LiteralControl("</div>"));

                        phPartitionControl.Controls.Add(new LiteralControl("<div class='col-xs-8'>"));
                        var ddlPlacementGroup = new RockDropDownList();
                        ddlPlacementGroup.ID = campus.Guid.ToString() + "_" + partition.Guid + "_group";
                        ddlPlacementGroup.SelectedIndexChanged += DdlPlacementGroup_SelectedIndexChanged;
                        ddlPlacementGroup.AutoPostBack          = true;
                        List <ListItem> groupList = getGroups().Select(g => new ListItem(String.Format("{0} ({1})", g.Name, g.Campus != null ? g.Campus.Name : "No Campus"), g.Id.ToString())).ToList();
                        groupList.Insert(0, new ListItem("Not Mapped", null));
                        ddlPlacementGroup.Items.AddRange(groupList.ToArray());
                        if (partition.GroupMap != null && partition.GroupMap.ContainsKey(campus.Guid.ToString()))
                        {
                            ddlPlacementGroup.SetValue(partition.GroupMap[campus.Guid.ToString()]);
                        }
                        phPartitionControl.Controls.Add(ddlPlacementGroup);
                        phPartitionControl.Controls.Add(new LiteralControl("</div></div>"));
                    }
                    phPartitionControl.Controls.Add(new LiteralControl("</div>"));
                    tbAttributeKey.ReadOnly = true;

                    break;

                case "Schedule":
                    phPartitionControl.Controls.Add(new LiteralControl("<strong>Schedule</strong><br />"));
                    var schedule = new SchedulePicker()
                    {
                        AllowMultiSelect = true, ID = partition.Guid.ToString()
                    };
                    schedule.SelectItem += Schedule_SelectItem;
                    if (!string.IsNullOrWhiteSpace(partition.PartitionValue))
                    {
                        ScheduleService scheduleService = new ScheduleService(new RockContext());
                        List <Guid>     scheduleGuids   = partition.PartitionValue.Split(',').Select(pv => pv.AsGuid()).ToList();

                        schedule.SetValues(scheduleService.GetByGuids(scheduleGuids).ToList().Select(s => s.Id).ToList());
                    }
                    phPartitionControl.Controls.Add(schedule);
                    break;

                case "DefinedType":
                    phPartitionControl.Controls.Add(new LiteralControl("<strong>Defined Type</strong><br />"));
                    var definedTypeRddl = new RockDropDownList()
                    {
                        ID = partition.Guid.ToString()
                    };
                    DefinedTypeService definedTypeService = new DefinedTypeService(new RockContext());
                    var listItems = definedTypeService.Queryable().Select(dt => new { Name = (dt.Category != null ? dt.Category.Name + ": " : "") + dt.Name, Guid = dt.Guid }).ToList();
                    listItems.Insert(0, new { Name = "Select One . . .", Guid = Guid.Empty });
                    definedTypeRddl.DataSource     = listItems;
                    definedTypeRddl.DataTextField  = "Name";
                    definedTypeRddl.DataValueField = "Guid";
                    definedTypeRddl.DataBind();
                    definedTypeRddl.AutoPostBack          = true;
                    definedTypeRddl.SelectedIndexChanged += DefinedTypeRddl_SelectedIndexChanged;
                    if (!string.IsNullOrWhiteSpace(partition.PartitionValue))
                    {
                        definedTypeRddl.SelectedValue = partition.PartitionValue;
                    }
                    phPartitionControl.Controls.Add(definedTypeRddl);
                    break;

                case "Role":
                    if (Settings.EntityTypeGuid == Rock.SystemGuid.EntityType.CONNECTION_OPPORTUNITY.AsGuid())
                    {
                        ConnectionOpportunity connection = ( ConnectionOpportunity )Settings.Entity();
                        var roles = connection.ConnectionOpportunityGroupConfigs.Where(cogc => cogc.GroupMemberRole != null).OrderBy(r => r.GroupTypeId).ThenBy(r => r.GroupMemberRole.Order).Select(r => new { Name = r.GroupType.Name + ": " + r.GroupMemberRole.Name, Guid = r.GroupMemberRole.Guid }).ToList();

                        phPartitionControl.Controls.Add(new LiteralControl("<div class='row'><div class='col-md-4'><strong>Name</strong></div><div class='col-md-8'><strong>Group</strong></div>"));

                        foreach (var role in roles)
                        {
                            phPartitionControl.Controls.Add(new LiteralControl("<div class='row'><div class='col-xs-4'>"));
                            var roleCbl = new CheckBox();
                            roleCbl.ID = role.Guid.ToString() + "_" + partition.Guid + "_checkbox";
                            if (!string.IsNullOrWhiteSpace(partition.PartitionValue))
                            {
                                roleCbl.Checked = partition.PartitionValue.Contains(role.Guid.ToString());
                            }
                            roleCbl.Text            = role.Name;
                            roleCbl.CheckedChanged += CampusCbl_CheckedChanged;
                            roleCbl.AutoPostBack    = true;
                            phPartitionControl.Controls.Add(roleCbl);
                            phPartitionControl.Controls.Add(new LiteralControl("</div>"));

                            phPartitionControl.Controls.Add(new LiteralControl("<div class='col-xs-8'>"));
                            var ddlPlacementGroup = new RockDropDownList();
                            ddlPlacementGroup.ID = role.Guid.ToString() + "_" + partition.Guid + "_group";
                            ddlPlacementGroup.SelectedIndexChanged += DdlPlacementGroup_SelectedIndexChanged;
                            ddlPlacementGroup.AutoPostBack          = true;

                            List <ListItem> groupList = getGroups().Select(g => new ListItem(String.Format("{0} ({1})", g.Name, g.Campus != null ? g.Campus.Name : "No Campus"), g.Id.ToString())).ToList();
                            groupList.Insert(0, new ListItem("Not Mapped", null));
                            ddlPlacementGroup.Items.AddRange(groupList.ToArray());
                            if (partition.GroupMap != null && partition.GroupMap.ContainsKey(role.Guid.ToString()))
                            {
                                ddlPlacementGroup.SetValue(partition.GroupMap[role.Guid.ToString()]);
                            }
                            phPartitionControl.Controls.Add(ddlPlacementGroup);
                            phPartitionControl.Controls.Add(new LiteralControl("</div></div>"));
                        }
                        phPartitionControl.Controls.Add(new LiteralControl("</div>"));
                        tbAttributeKey.ReadOnly = true;
                    }

                    break;
                }

                tbAttributeKey.ID   = "attribute_key_" + partition.Guid.ToString();
                tbAttributeKey.Text = partition.AttributeKey;
                (( LinkButton )e.Item.FindControl("bbPartitionDelete")).CommandArgument = partition.Guid.ToString();
            }
        }
コード例 #7
0
        private void BindFilter()
        {
            if ( ddlCategoryFilter.SelectedItem == null )
            {
                ddlCategoryFilter.Items.Clear();
                ddlCategoryFilter.Items.Add( "[All]" );

                DefinedTypeService typeService = new DefinedTypeService();
                var items = typeService.Queryable().
                    Where( a => a.Category != "" && a.Category != null ).
                    OrderBy( a => a.Category ).
                    Select( a => a.Category ).
                    Distinct().ToList();

                foreach ( var item in items )
                    ddlCategoryFilter.Items.Add( item );
            }
        }
コード例 #8
0
        /// <summary>
        /// Maps the Giftedness Program.
        /// </summary>
        /// <param name="tableData">The table data.</param>
        private void MapGiftednessProgram(IQueryable <Row> tableData)
        {
            int completed  = 0;
            int totalRows  = tableData.Count();
            int percentage = (totalRows - 1) / 100 + 1;

            ReportProgress(0, string.Format("Verifying Giftedness Program import ({0:N0} found).", totalRows));

            foreach (var row in tableData)
            {
                var rockContext      = new RockContext();
                var categoryList     = new CategoryService(rockContext).Queryable().ToList();
                var attributeList    = new AttributeService(rockContext).Queryable().ToList();
                var definedTypeList  = new DefinedTypeService(rockContext).Queryable().ToList();
                var definedValueList = new DefinedValueService(rockContext).Queryable().ToList();

                //check if category exists
                string category = row["CategoryName"] as string;
                if (categoryList.Find(c => c.Name == category) == null)
                {
                    var entityType = new EntityTypeService(rockContext);
                    //creates if category doesn't exist
                    var newCategory = new Category();
                    newCategory.IsSystem     = false;
                    newCategory.EntityTypeId = entityType.Queryable().Where(e => e.Name == "Rock.Model.Attribute").Select(e => e.Id).FirstOrDefault();
                    newCategory.EntityTypeQualifierColumn = "EntityTypeId";
                    newCategory.EntityTypeQualifierValue  = Convert.ToString(PersonEntityTypeId);   //Convert.ToString(entityType.Queryable().Where( e => e.Name == "Rock.Model.Person" ).Select( e => e.Id ).FirstOrDefault());
                    newCategory.Name        = category;
                    newCategory.Description = "Contains the spiritual gifts attributes";

                    //var newCategoryContext = new RockContext();
                    //newCategoryContext.WrapTransaction( () =>
                    //{
                    //    newCategoryContext.Configuration.AutoDetectChangesEnabled = false;
                    //    newCategoryContext.Categories.Add( newCategory );
                    //    newCategoryContext.SaveChanges( DisableAudit );
                    //} );
                    rockContext.WrapTransaction(() =>
                    {
                        rockContext.Configuration.AutoDetectChangesEnabled = false;
                        rockContext.Categories.Add(newCategory);
                        rockContext.SaveChanges(DisableAudit);
                    });
                }
                //Check if Attribute exists
                if (attributeList.Find(a => a.Key == "Rank1") == null || attributeList.Find(a => a.Key == "Rank2") == null || attributeList.Find(a => a.Key == "Rank3") == null || attributeList.Find(a => a.Key == "Rank4") == null)
                {
                    var fieldType        = new FieldTypeService(rockContext);
                    var newAttributeList = new List <Rock.Model.Attribute>();
                    var fieldTypeId      = fieldType.Queryable().Where(e => e.Name == "Defined Value").FirstOrDefault().Id;
                    var category2        = new CategoryService(rockContext).Queryable().Where(gt => gt.Name == "Spiritual Gifts").FirstOrDefault();


                    if (attributeList.Find(a => a.Key == "Rank1") == null)
                    {
                        //Creates if attribute doesn't exist
                        var newAttribute = new Rock.Model.Attribute();
                        newAttribute.Key                       = "Rank1";
                        newAttribute.Name                      = "Rank 1";
                        newAttribute.FieldTypeId               = fieldTypeId;
                        newAttribute.EntityTypeId              = PersonEntityTypeId;
                        newAttribute.EntityTypeQualifierValue  = string.Empty;
                        newAttribute.EntityTypeQualifierColumn = string.Empty;
                        newAttribute.Description               = "Rank 1";
                        newAttribute.DefaultValue              = string.Empty;
                        newAttribute.IsMultiValue              = false;
                        newAttribute.IsRequired                = false;
                        newAttribute.Categories                = new List <Category>();
                        newAttribute.Categories.Add(category2);

                        newAttributeList.Add(newAttribute);
                    }
                    if (attributeList.Find(a => a.Key == "Rank2") == null)
                    {
                        //Creates if attribute doesn't exist
                        var newAttribute = new Rock.Model.Attribute();
                        newAttribute.Key                       = "Rank2";
                        newAttribute.Name                      = "Rank 2";
                        newAttribute.FieldTypeId               = fieldTypeId;
                        newAttribute.EntityTypeId              = PersonEntityTypeId;
                        newAttribute.EntityTypeQualifierValue  = string.Empty;
                        newAttribute.EntityTypeQualifierColumn = string.Empty;
                        newAttribute.Description               = "Rank 2";
                        newAttribute.DefaultValue              = string.Empty;
                        newAttribute.IsMultiValue              = false;
                        newAttribute.IsRequired                = false;
                        newAttribute.Categories                = new List <Category>();
                        newAttribute.Categories.Add(category2);

                        newAttributeList.Add(newAttribute);
                    }
                    if (attributeList.Find(a => a.Key == "Rank3") == null)
                    {
                        //Creates if attribute doesn't exist
                        var newAttribute = new Rock.Model.Attribute();
                        newAttribute.Key                       = "Rank3";
                        newAttribute.Name                      = "Rank 3";
                        newAttribute.FieldTypeId               = fieldTypeId;
                        newAttribute.EntityTypeId              = PersonEntityTypeId;
                        newAttribute.EntityTypeQualifierValue  = string.Empty;
                        newAttribute.EntityTypeQualifierColumn = string.Empty;
                        newAttribute.Description               = "Rank 3";
                        newAttribute.DefaultValue              = string.Empty;
                        newAttribute.IsMultiValue              = false;
                        newAttribute.IsRequired                = false;
                        newAttribute.Categories                = new List <Category>();
                        newAttribute.Categories.Add(category2);

                        newAttributeList.Add(newAttribute);
                    }
                    if (attributeList.Find(a => a.Key == "Rank4") == null)
                    {
                        //Creates if attribute doesn't exist
                        var newAttribute = new Rock.Model.Attribute();
                        newAttribute.Key                       = "Rank4";
                        newAttribute.Name                      = "Rank 4";
                        newAttribute.FieldTypeId               = fieldTypeId;
                        newAttribute.EntityTypeId              = PersonEntityTypeId;
                        newAttribute.EntityTypeQualifierValue  = string.Empty;
                        newAttribute.EntityTypeQualifierColumn = string.Empty;
                        newAttribute.Description               = "Rank 4";
                        newAttribute.DefaultValue              = string.Empty;
                        newAttribute.IsMultiValue              = false;
                        newAttribute.IsRequired                = false;
                        newAttribute.Categories                = new List <Category>();
                        newAttribute.Categories.Add(category2);


                        newAttributeList.Add(newAttribute);
                    }

                    if (newAttributeList.Any())
                    {
                        //var newAttributeContext = new RockContext();
                        rockContext.WrapTransaction(() =>
                        {
                            rockContext.Configuration.AutoDetectChangesEnabled = false;
                            rockContext.Attributes.AddRange(newAttributeList);
                            rockContext.SaveChanges(DisableAudit);
                            newAttributeList.Clear();
                        });
                    }
                }
                //checks if Defined Type exists
                if (definedTypeList.Find(d => d.Name == "Spiritual Gifts") == null)
                {
                    var fieldTypeService = new FieldTypeService(rockContext);

                    //creates Defined Type
                    var newDefinedType = new DefinedType();
                    newDefinedType.IsSystem    = false;
                    newDefinedType.FieldTypeId = fieldTypeService.Queryable().Where(f => f.Name == "Text").Select(f => f.Id).FirstOrDefault();
                    newDefinedType.Name        = "Spiritual Gifts";
                    newDefinedType.Description = "Defined Type for Spiritual Gifts values";
                    newDefinedType.CategoryId  = categoryList.Find(c => c.Name == "Person").Id;

                    //var newDTContext = new RockContext();
                    rockContext.WrapTransaction(() =>
                    {
                        rockContext.Configuration.AutoDetectChangesEnabled = false;
                        rockContext.DefinedTypes.Add(newDefinedType);
                        rockContext.SaveChanges(DisableAudit);
                    });
                }
                //checks if Defined Value exists
                var    spiritualGiftsDefineType = new DefinedTypeService(rockContext).Queryable().Where(d => d.Name == "Spiritual Gifts").FirstOrDefault();
                string attributeName            = row["AttributeName"] as string;
                int?   giftAttributeId          = row["GiftAttributeID"] as int?;
                if (definedValueList.Find(d => d.DefinedTypeId == spiritualGiftsDefineType.Id && d.Value == attributeName) == null)
                {
                    var definedTypeService = new DefinedTypeService(rockContext);
                    //creates Defined Value
                    var newDefinedValue = new DefinedValue();
                    newDefinedValue.IsSystem      = false;
                    newDefinedValue.DefinedTypeId = definedTypeService.Queryable().Where(d => d.Name == "Spiritual Gifts").Select(d => d.Id).FirstOrDefault();
                    newDefinedValue.Value         = attributeName;
                    newDefinedValue.Description   = "Spiritual Gift attribute value: " + attributeName;
                    newDefinedValue.ForeignId     = Convert.ToString(giftAttributeId);

                    //var newDVContext = new RockContext();
                    rockContext.WrapTransaction(() =>
                    {
                        rockContext.Configuration.AutoDetectChangesEnabled = false;
                        rockContext.DefinedValues.Add(newDefinedValue);
                        rockContext.SaveChanges(DisableAudit);
                    });
                }

                completed++;

                if (completed % percentage < 1)
                {
                    int percentComplete = completed / percentage;
                    ReportProgress(percentComplete, string.Format("{0:N0} spiritual gifts attributes imported ({1}% complete).", completed, percentComplete));
                }
                else if (completed % ReportingNumber < 1)
                {
                    ReportPartialProgress();
                }
            }

            ReportProgress(100, string.Format("Finished spiritual gifts import: {0:N0} spiritual gifts attributes imported.", completed));
        }