示例#1
0
        private void ShowDetails()
        {
            WidgityType widgityType = GetWidgityType();

            tbName.Text              = widgityType.Name;
            tbDescription.Text       = widgityType.Description;
            lcCommands.SelectedValue = widgityType.EnabledLavaCommands;
            tbIcon.Text              = widgityType.Icon;
            ceMarkup.Text            = widgityType.Markdown;
            lbEntityTypes.SetValues(widgityType.EntityTypes.Select(w => w.Id.ToString()).ToList());
            pCategory.SetValue(widgityType.CategoryId);
            cbHasItems.Checked = widgityType.HasItems;
            pnlWidgityItemAttributes.Visible = cbHasItems.Checked;
        }
示例#2
0
        private WidgityType GetWidgityType(WidgityTypeService widgityTypeService)
        {
            var widgityType = widgityTypeService.Get(PageParameter(PageParameterKey.WidgityTypeId).AsInteger());

            if (widgityType == null)
            {
                widgityType = new WidgityType
                {
                    CategoryId  = 0,
                    EntityTypes = new List <EntityType>()
                };
            }
            return(widgityType);
        }
示例#3
0
        public WidgityItem GetEntity()
        {
            WidgityItem widgityItem = new WidgityItem()
            {
                Id              = Id,
                Guid            = Guid,
                WidgityTypeId   = WidgityTypeId,
                WidgityType     = WidgityType.GetEntity(),
                Order           = Order,
                Attributes      = Attributes,
                AttributeValues = AttributeValues
            };

            return(widgityItem);
        }
示例#4
0
        public Widgity GetEntity()
        {
            Widgity widgity = new Widgity()
            {
                Id              = Id,
                Guid            = Guid,
                EntityGuid      = EntityGuid,
                WidgityTypeId   = WidgityTypeId,
                WidgityType     = WidgityType.GetEntity(),
                Order           = Order,
                Attributes      = Attributes,
                AttributeValues = AttributeValues
            };

            return(widgity);
        }
示例#5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            RockContext rockContext = new RockContext();

            rockContext.WrapTransaction(() =>
            {
                WidgityTypeService widgityTypeService = new WidgityTypeService(rockContext);
                AttributeService attributeService     = new AttributeService(rockContext);
                WidgityType widgityType = GetWidgityType(widgityTypeService);

                if (widgityType.Id == 0)
                {
                    widgityTypeService.Add(widgityType);
                }

                widgityType.Name                = tbName.Text;
                widgityType.Description         = tbDescription.Text;
                widgityType.EnabledLavaCommands = lcCommands.SelectedValue;
                widgityType.Icon                = tbIcon.Text;
                widgityType.Markdown            = ceMarkup.Text;
                widgityType.HasItems            = cbHasItems.Checked;
                var _ = widgityType.EntityTypes.ToList(); //Attach the entity types to context
                widgityType.EntityTypes = new EntityTypeService(rockContext).GetByIds(lbEntityTypes.SelectedValuesAsInt).ToList();
                widgityType.CategoryId  = pCategory.SelectedValueAsId();
                rockContext.SaveChanges();

                //Widgity Attributes
                var widgityEntityTypeId = EntityTypeCache.Get(typeof(Widgity)).Id;

                var actualAttributes = attributeService.Queryable()
                                       .Where(a => a.EntityTypeId == widgityEntityTypeId && a.EntityTypeQualifierValue == widgityType.Id.ToString())
                                       .OrderBy(a => a.Order)
                                       .ToList();

                //Remove deleted attributes
                foreach (var attribute in actualAttributes)
                {
                    if (!WidgityAttributes.Where(a => a.Guid == attribute.Guid).Any())
                    {
                        attributeService.Delete(attribute);
                    }
                }

                //Update db from viewstate
                foreach (var attribute in WidgityAttributes)
                {
                    if (attribute.Id == 0)
                    {
                        attribute.Order = WidgityAttributes.IndexOf(attribute);
                        attribute.EntityTypeQualifierValue = widgityType.Id.ToString();
                        attributeService.Add(attribute);
                    }
                    else
                    {
                        var trackedAttribute = actualAttributes.Where(a => a.Guid == attribute.Guid).FirstOrDefault();
                        trackedAttribute.CopyPropertiesFrom(attribute);
                        foreach (var qualifier in trackedAttribute.AttributeQualifiers)
                        {
                            var value = attribute.AttributeQualifiers.Where(q => q.Key == qualifier.Key).FirstOrDefault();
                            if (value != null)
                            {
                                qualifier.Value = value.Value;
                            }
                        }
                        trackedAttribute.Order = WidgityAttributes.IndexOf(attribute);
                    }
                }
                rockContext.SaveChanges();


                //Widgity Item Attributes
                var widgityItemEntityTypeId = EntityTypeCache.Get(typeof(WidgityItem)).Id;

                var actualItemAttributes = attributeService.Queryable()
                                           .Where(a => a.EntityTypeId == widgityItemEntityTypeId && a.EntityTypeQualifierValue == widgityType.Id.ToString())
                                           .OrderBy(a => a.Order)
                                           .ToList();

                //Remove deleted attributes
                foreach (var attribute in actualItemAttributes)
                {
                    if (!WidgityItemAttributes.Where(a => a.Guid == attribute.Guid).Any())
                    {
                        attributeService.Delete(attribute);
                    }
                }

                //Update db from viewstate
                foreach (var attribute in WidgityItemAttributes)
                {
                    if (attribute.Id == 0)
                    {
                        attribute.Order = WidgityItemAttributes.IndexOf(attribute);
                        attribute.EntityTypeQualifierValue = widgityType.Id.ToString();
                        attributeService.Add(attribute);
                    }
                    else
                    {
                        var trackedAttribute = actualItemAttributes.Where(a => a.Guid == attribute.Guid).FirstOrDefault();
                        trackedAttribute.CopyPropertiesFrom(attribute);
                        foreach (var qualifier in trackedAttribute.AttributeQualifiers)
                        {
                            var value = attribute.AttributeQualifiers.Where(q => q.Key == qualifier.Key).FirstOrDefault();
                            if (value != null)
                            {
                                qualifier.Value = value.Value;
                            }
                        }
                        trackedAttribute.Order = WidgityItemAttributes.IndexOf(attribute);
                    }
                }
                rockContext.SaveChanges();
            });
            WidgityTypeCache.Clear();
            WidgityCache.Clear();
            WidgityItemCache.Clear();
            NavigateToParentPage();
        }