protected void btUserAttributesOK_Click(object sender, EventArgs eventArgs) { Guid nodeID; Guid.TryParse(cmbAttributeSchemaNodes.SelectedItem.Value.ToString(), out nodeID); var userAttribute = GetRelatedAttributes(); if (userAttribute != null) { userAttribute.DateDeleted = DateTime.Now; } var newUserAttribute = new UM_UserAttribute { ID = Guid.NewGuid(), DateCreated = DateTime.Now, UserID = UserId.Value, AttributesSchemaNodeID = nodeID, Value = tbUserAttributesValue.Text }; DataContext.UM_UserAttributes.InsertOnSubmit(newUserAttribute); DataContext.SubmitChanges(); }
public static UserAttributeContract ToContract(this UM_UserAttribute entity) { if (entity == null) { return(null); } var contract = new UserAttributeContract(); contract.DateChanged = entity.DateChanged; contract.DateCreated = entity.DateCreated; contract.DateDeleted = entity.DateDeleted; contract.ID = entity.ID; contract.UserID = entity.UserID; return(contract); }
public static UM_UserAttribute ToEntity(this UserAttributeContract contract) { if (contract == null) { return(null); } var entity = new UM_UserAttribute(); entity.DateChanged = contract.DateChanged; entity.DateCreated = contract.DateCreated; entity.DateDeleted = contract.DateDeleted; entity.ID = contract.ID; entity.UserID = contract.UserID; entity.AttributesSchemaNodeID = contract.AttributeSchemaNodeID; entity.Value = contract.Value; return(entity); }
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(); }