protected void btAttributeSchemaNodeOK_Click(object sender, EventArgs e)
    {
        var attributeTypeID     = cmbAttributeTypes.TryGetGuidValue();
        var attributeCategoryID = cmbAttributeCategories.TryGetGuidValue();

        if (attributeTypeID == null || attributeCategoryID == null)
        {
            return;
        }

        var itemID = DataConverter.ToNullableGuid(hdAttributeSchemaNodeID.Value);

        var item = DataContext.UM_AttributesSchemaNodes.FirstOrDefault(n => n.ID == itemID);

        if (item == null)
        {
            item = new UM_AttributesSchemaNode
            {
                ID          = Guid.NewGuid(),
                DateCreated = DateTime.Now
            };

            DataContext.UM_AttributesSchemaNodes.InsertOnSubmit(item);
        }

        item.Name = tbAttributeSchemaNodeName.Text;
        item.AttributesSchemaID = Guid.Parse(hdAttributeSchemaNodeParentID.Value);

        item.AttributeCategoryID = attributeCategoryID.Value;
        item.AttributeTypeID     = attributeTypeID.Value;

        DataContext.SubmitChanges();

        FillAttributesTree();
    }
Ejemplo n.º 2
0
    protected void SetUserGlobalAttribute(Guid userID, String attributeName, String value)
    {
        var globalAttr = (from n in DataContext.UM_Users
                          where n.ID == userID
                          from m in n.UserAttributes
                          where m.DateDeleted == null
                          let node = m.AttributesSchemaNode
                                     let cat = node.AttributeCategory
                                               let type = node.AttributeType
                                                          where node != null &&
                                                          cat != null &&
                                                          type != null &&
                                                          cat.ProjectID == null &&
                                                          type.ProjectID == null &&
                                                          node.Name == attributeName
                                                          select m).FirstOrDefault();

        if (globalAttr == null)
        {
            globalAttr = new UM_UserAttribute
            {
                ID          = Guid.NewGuid(),
                DateCreated = DateTime.Now,
                UserID      = userID,
            };

            DataContext.UM_UserAttributes.InsertOnSubmit(globalAttr);

            var globalAttrNode = (from n in DataContext.UM_AttributesSchemaNodes
                                  where n.Name == attributeName &&
                                  n.DateDeleted == null
                                  let cat = n.AttributeCategory
                                            let type = n.AttributeType
                                                       where cat != null &&
                                                       type != null &&
                                                       cat.ProjectID == null &&
                                                       type.ProjectID == null
                                                       select n).SingleOrDefault();

            if (globalAttrNode == null)
            {
                var globalSchema = (from n in DataContext.UM_AttributesSchemas
                                    where n.DateDeleted == null &&
                                    n.ProjectID == null
                                    select n).Single();

                var globalType = (from n in DataContext.UM_AttributeTypes
                                  where n.DateDeleted == null &&
                                  n.ProjectID == null
                                  select n).Single();

                var globalCategory = (from n in DataContext.UM_AttributeCategories
                                      where n.DateDeleted == null &&
                                      n.ProjectID == null
                                      select n).Single();

                globalAttrNode = new UM_AttributesSchemaNode
                {
                    ID                = Guid.NewGuid(),
                    Name              = attributeName,
                    DateCreated       = DateTime.Now,
                    AttributeType     = globalType,
                    AttributeCategory = globalCategory,
                    AttributesSchema  = globalSchema,
                };
            }

            globalAttr.AttributesSchemaNode = globalAttrNode;
        }

        globalAttr.Value = value;

        DataContext.SubmitChanges();
    }