public IDataTypeDefinition BuildEntity(DataTypeDto dto)
        {
            var dataTypeDefinition = new DataTypeDefinition(dto.PropertyEditorAlias);


            try
            {
                dataTypeDefinition.DisableChangeTracking();

                dataTypeDefinition.CreateDate   = dto.NodeDto.CreateDate;
                dataTypeDefinition.DatabaseType = dto.DbType.EnumParse <DataTypeDatabaseType>(true);
                dataTypeDefinition.Id           = dto.DataTypeId;
                dataTypeDefinition.Key          = dto.NodeDto.UniqueId;
                dataTypeDefinition.Level        = dto.NodeDto.Level;
                dataTypeDefinition.UpdateDate   = dto.NodeDto.CreateDate;
                dataTypeDefinition.Name         = dto.NodeDto.Text;
                dataTypeDefinition.ParentId     = dto.NodeDto.ParentId;
                dataTypeDefinition.Path         = dto.NodeDto.Path;
                dataTypeDefinition.SortOrder    = dto.NodeDto.SortOrder;
                dataTypeDefinition.Trashed      = dto.NodeDto.Trashed;
                dataTypeDefinition.CreatorId    = dto.NodeDto.UserId.Value;

                //on initial construction we don't want to have dirty properties tracked
                // http://issues.umbraco.org/issue/U4-1946
                dataTypeDefinition.ResetDirtyProperties(false);
                return(dataTypeDefinition);
            }
            finally
            {
                dataTypeDefinition.EnableChangeTracking();
            }
        }
Ejemplo n.º 2
0
        public Guid Insert(DataTypeDto dto)
        {
            dto.Id = Guid.NewGuid();

            _connection.Query <int>(DataTypeDaoSql.Insert, new { Name = dto.Name, ClrType = dto.ClrType, Id = dto.Id }, _transaction);

            return(dto.Id);
        }
        public async Task <IActionResult> GetBy([FromRoute] int code)
        {
            DataTypeDto dataTypeDto = await this.dataTypeService.GetBy(code);

            if (dataTypeDto != null)
            {
                return(this.Ok(dataTypeDto));
            }

            return(this.NotFound("A data type w/ the given code was not found"));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Deletes a DataType entity
 /// </summary>
 /// <param name="item"></param>
 public void Delete(DataTypeDto item)
 {
     if (Unit != null)
     {
         Repository.Delete(item, false);
     }
     else
     {
         Repository.Delete(item);
     }
 }
Ejemplo n.º 5
0
    protected override void PersistNewItem(IDataType entity)
    {
        entity.AddingEntity();

        // ensure a datatype has a unique name before creating it
        entity.Name = EnsureUniqueNodeName(entity.Name) !;

        // TODO: should the below be removed?
        // Cannot add a duplicate data type
        Sql <ISqlContext> existsSql = Sql()
                                      .SelectCount()
                                      .From <DataTypeDto>()
                                      .InnerJoin <NodeDto>().On <DataTypeDto, NodeDto>((left, right) => left.NodeId == right.NodeId)
                                      .Where <NodeDto>(x => x.Text == entity.Name);
        var exists = Database.ExecuteScalar <int>(existsSql) > 0;

        if (exists)
        {
            throw new DuplicateNameException("A data type with the name " + entity.Name + " already exists");
        }

        DataTypeDto dto = DataTypeFactory.BuildDto(entity, _serializer);

        // Logic for setting Path, Level and SortOrder
        NodeDto?parent    = Database.First <NodeDto>("WHERE id = @ParentId", new { entity.ParentId });
        var     level     = parent.Level + 1;
        var     sortOrder =
            Database.ExecuteScalar <int>(
                "SELECT COUNT(*) FROM umbracoNode WHERE parentID = @ParentId AND nodeObjectType = @NodeObjectType",
                new { entity.ParentId, NodeObjectType = NodeObjectTypeId });

        // Create the (base) node data - umbracoNode
        NodeDto nodeDto = dto.NodeDto;

        nodeDto.Path      = parent.Path;
        nodeDto.Level     = short.Parse(level.ToString(CultureInfo.InvariantCulture));
        nodeDto.SortOrder = sortOrder;
        var o = Database.IsNew(nodeDto) ? Convert.ToInt32(Database.Insert(nodeDto)) : Database.Update(nodeDto);

        // Update with new correct path
        nodeDto.Path = string.Concat(parent.Path, ",", nodeDto.NodeId);
        Database.Update(nodeDto);

        // Update entity with correct values
        entity.Id        = nodeDto.NodeId; // Set Id on entity to ensure an Id is set
        entity.Path      = nodeDto.Path;
        entity.SortOrder = sortOrder;
        entity.Level     = level;

        dto.NodeId = nodeDto.NodeId;
        Database.Insert(dto);

        entity.ResetDirtyProperties();
    }
Ejemplo n.º 6
0
 public void Update(DataTypeDto item)
 {
     //if Unit is not null means that the method is called after another method in the service and so it should not save the changes and commit the transaction.
     if (Unit != null)
     {
         Repository.Update(item, false);
     }
     //if Unit is null means that the method is the first and only method in the transaction and it can save the changes and commit the transaction.
     else
     {
         Repository.Update(item);
     }
 }
Ejemplo n.º 7
0
    private void UpdateDataType(DataTypeDto dataType, ValueListConfiguration config, bool isMultiple)
    {
        dataType.DbType      = ValueStorageType.Nvarchar.ToString();
        dataType.EditorAlias = Constants.PropertyEditors.Aliases.DropDownListFlexible;

        var flexConfig = new DropDownFlexibleConfiguration {
            Items = config.Items, Multiple = isMultiple
        };

        dataType.Configuration = ConfigurationEditor.ToDatabase(flexConfig, _configurationEditorJsonSerializer);

        Database.Update(dataType);
    }
Ejemplo n.º 8
0
    public static DataTypeDto BuildDto(IDataType entity, IConfigurationEditorJsonSerializer serializer)
    {
        var dataTypeDto = new DataTypeDto
        {
            EditorAlias   = entity.EditorAlias,
            NodeId        = entity.Id,
            DbType        = entity.DatabaseType.ToString(),
            Configuration = ConfigurationEditor.ToDatabase(entity.Configuration, serializer),
            NodeDto       = BuildNodeDto(entity),
        };

        return(dataTypeDto);
    }
        public DataTypeDto BuildDto(IDataTypeDefinition entity)
        {
            var dataTypeDto = new DataTypeDto
            {
                PropertyEditorAlias = entity.PropertyEditorAlias,
                DataTypeId          = entity.Id,
                DbType  = entity.DatabaseType.ToString(),
                NodeDto = BuildNodeDto(entity)
            };

            if (_primaryKey > 0)
            {
                dataTypeDto.PrimaryKey = _primaryKey;
            }

            return(dataTypeDto);
        }
Ejemplo n.º 10
0
    protected override void PersistUpdatedItem(IDataType entity)
    {
        entity.Name = EnsureUniqueNodeName(entity.Name, entity.Id) !;

        // Cannot change to a duplicate alias
        Sql <ISqlContext> existsSql = Sql()
                                      .SelectCount()
                                      .From <DataTypeDto>()
                                      .InnerJoin <NodeDto>().On <DataTypeDto, NodeDto>((left, right) => left.NodeId == right.NodeId)
                                      .Where <NodeDto>(x => x.Text == entity.Name && x.NodeId != entity.Id);
        var exists = Database.ExecuteScalar <int>(existsSql) > 0;

        if (exists)
        {
            throw new DuplicateNameException("A data type with the name " + entity.Name + " already exists");
        }

        // Updates Modified date
        entity.UpdatingEntity();

        // Look up parent to get and set the correct Path if ParentId has changed
        if (entity.IsPropertyDirty("ParentId"))
        {
            NodeDto?parent = Database.First <NodeDto>("WHERE id = @ParentId", new { entity.ParentId });
            entity.Path  = string.Concat(parent.Path, ",", entity.Id);
            entity.Level = parent.Level + 1;
            var maxSortOrder =
                Database.ExecuteScalar <int>(
                    "SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId AND nodeObjectType = @NodeObjectType",
                    new { entity.ParentId, NodeObjectType = NodeObjectTypeId });
            entity.SortOrder = maxSortOrder + 1;
        }

        DataTypeDto dto = DataTypeFactory.BuildDto(entity, _serializer);

        // Updates the (base) node data - umbracoNode
        NodeDto nodeDto = dto.NodeDto;

        Database.Update(nodeDto);
        Database.Update(dto);

        entity.ResetDirtyProperties();
    }
Ejemplo n.º 11
0
    public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger <IDataType> logger, IConfigurationEditorJsonSerializer serializer)
    {
        // Check we have an editor for the data type.
        if (!editors.TryGet(dto.EditorAlias, out IDataEditor? editor))
        {
            logger.LogWarning(
                "Could not find an editor with alias {EditorAlias}, treating as Label. " + "The site may fail to boot and/or load data types and run.", dto.EditorAlias);

            // Create as special type, which downstream can be handled by converting to a LabelPropertyEditor to make clear
            // the situation to the user.
            editor = new MissingPropertyEditor();
        }

        var dataType = new DataType(editor, serializer);

        try
        {
            dataType.DisableChangeTracking();

            dataType.CreateDate   = dto.NodeDto.CreateDate;
            dataType.DatabaseType = dto.DbType.EnumParse <ValueStorageType>(true);
            dataType.Id           = dto.NodeId;
            dataType.Key          = dto.NodeDto.UniqueId;
            dataType.Level        = dto.NodeDto.Level;
            dataType.UpdateDate   = dto.NodeDto.CreateDate;
            dataType.Name         = dto.NodeDto.Text;
            dataType.ParentId     = dto.NodeDto.ParentId;
            dataType.Path         = dto.NodeDto.Path;
            dataType.SortOrder    = dto.NodeDto.SortOrder;
            dataType.Trashed      = dto.NodeDto.Trashed;
            dataType.CreatorId    = dto.NodeDto.UserId ?? Constants.Security.UnknownUserId;

            dataType.SetLazyConfiguration(dto.Configuration);

            // reset dirty initial properties (U4-1946)
            dataType.ResetDirtyProperties(false);
            return(dataType);
        }
        finally
        {
            dataType.EnableChangeTracking();
        }
    }
Ejemplo n.º 12
0
 /// <summary>
 /// Insert a new DataType entity
 /// </summary>
 /// <param name="item">DataType entity</param>
 public void Insert(DataTypeDto item)
 {
     try
     {
         // if Unit is not null means that our service is called after another service.
         if (Unit != null)
         {
             this.Repository.Insert(item, false);  // call data access insert
         }
         // if Unit is null means that our service is the first service that is calling repository.
         else
         {
             this.Repository.Insert(item);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 13
0
        public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger logger)
        {
            if (!editors.TryGet(dto.EditorAlias, out var editor))
            {
                logger.Warn(typeof(DataType), "Could not find an editor with alias {EditorAlias}, treating as Label."
                            + " The site may fail to boot and / or load data types and run.", dto.EditorAlias);
                //convert to label
                editor = new LabelPropertyEditor(logger);
            }

            var dataType = new DataType(editor);

            try
            {
                dataType.DisableChangeTracking();

                dataType.CreateDate   = dto.NodeDto.CreateDate;
                dataType.DatabaseType = dto.DbType.EnumParse <ValueStorageType>(true);
                dataType.Id           = dto.NodeId;
                dataType.Key          = dto.NodeDto.UniqueId;
                dataType.Level        = dto.NodeDto.Level;
                dataType.UpdateDate   = dto.NodeDto.CreateDate;
                dataType.Name         = dto.NodeDto.Text;
                dataType.ParentId     = dto.NodeDto.ParentId;
                dataType.Path         = dto.NodeDto.Path;
                dataType.SortOrder    = dto.NodeDto.SortOrder;
                dataType.Trashed      = dto.NodeDto.Trashed;
                dataType.CreatorId    = dto.NodeDto.UserId ?? Constants.Security.UnknownUserId;

                dataType.SetLazyConfiguration(dto.Configuration);

                // reset dirty initial properties (U4-1946)
                dataType.ResetDirtyProperties(false);
                return(dataType);
            }
            finally
            {
                dataType.EnableChangeTracking();
            }
        }
        internal PropertyTypeGroupDto Map(PropertyTypeGroupDto a, PropertyTypeDto p, DataTypeDto d)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (a == null)
            {
                return(current);
            }

            //Set the PropertyTypeDto's DataTypeDto object
            if (p.DataTypeId == d.DataTypeId)
            {
                p.DataTypeDto = d;
            }

            // Is this the same Group as the current one we're processing
            if (current != null && current.Id == a.Id)
            {
                // Yes, just add this PropertyType to the current Group's collection of PropertyTypes
                current.PropertyTypeDtos.Add(p);

                // Return null to indicate we're not done with this Group yet
                return(null);
            }

            // This is a different Group to the current one, or this is the
            // first time through and we don't have a Tab yet

            // Save the current Group
            var prev = current;

            // Setup the new current Group
            current = a;
            current.PropertyTypeDtos = new List <PropertyTypeDto>();
            current.PropertyTypeDtos.Add(p);

            // Return the now populated previous Tab (or null if first time through)
            return(prev);
        }
Ejemplo n.º 15
0
        public void Insert_ShouldAddRecord_WithValidDataType()
        {
            //Arrange
            var dataType = new DataTypeDto()
            {
                Name = "Test Data Type", ClrType = "string"
            };

            //Act
            DataTypeDto result = null;

            _dao.WithTransaction(() =>
            {
                var guid = _dao.Insert(dataType);
                result   = _dao.Get(guid);
            }, null, true);


            //Assert
            Assert.Equal(dataType.Name, result.Name);
            Assert.Equal(dataType.ClrType, result.ClrType);
        }
Ejemplo n.º 16
0
        public IDataTypeDefinition BuildEntity(DataTypeDto dto)
        {
            var dataTypeDefinition = new DataTypeDefinition(dto.PropertyEditorAlias)
            {
                CreateDate   = dto.NodeDto.CreateDate,
                DatabaseType = dto.DbType.EnumParse <DataTypeDatabaseType>(true),
                Id           = dto.DataTypeId,
                Key          = dto.NodeDto.UniqueId,
                Level        = dto.NodeDto.Level,
                UpdateDate   = dto.NodeDto.CreateDate,
                Name         = dto.NodeDto.Text,
                ParentId     = dto.NodeDto.ParentId,
                Path         = dto.NodeDto.Path,
                SortOrder    = dto.NodeDto.SortOrder,
                Trashed      = dto.NodeDto.Trashed,
                CreatorId    = dto.NodeDto.UserId.Value
            };

            //on initial construction we don't want to have dirty properties tracked
            // http://issues.umbraco.org/issue/U4-1946
            dataTypeDefinition.ResetDirtyProperties(false);
            return(dataTypeDefinition);
        }
Ejemplo n.º 17
0
        public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors)
        {
            if (!editors.TryGet(dto.EditorAlias, out var editor))
            {
                throw new InvalidOperationException($"Could not find an editor with alias \"{dto.EditorAlias}\".");
            }

            var dataType = new DataType(editor);

            try
            {
                dataType.DisableChangeTracking();

                dataType.CreateDate   = dto.NodeDto.CreateDate;
                dataType.DatabaseType = dto.DbType.EnumParse <ValueStorageType>(true);
                dataType.Id           = dto.NodeId;
                dataType.Key          = dto.NodeDto.UniqueId;
                dataType.Level        = dto.NodeDto.Level;
                dataType.UpdateDate   = dto.NodeDto.CreateDate;
                dataType.Name         = dto.NodeDto.Text;
                dataType.ParentId     = dto.NodeDto.ParentId;
                dataType.Path         = dto.NodeDto.Path;
                dataType.SortOrder    = dto.NodeDto.SortOrder;
                dataType.Trashed      = dto.NodeDto.Trashed;
                dataType.CreatorId    = dto.NodeDto.UserId ?? Constants.Security.UnknownUserId;

                dataType.SetLazyConfiguration(dto.Configuration);

                // reset dirty initial properties (U4-1946)
                dataType.ResetDirtyProperties(false);
                return(dataType);
            }
            finally
            {
                dataType.EnableChangeTracking();
            }
        }
Ejemplo n.º 18
0
 private void UpdateDataType(DataTypeDto dataType)
 {
     dataType.DbType = ValueStorageType.Nvarchar.ToString();
     Database.Update(dataType);
 }
Ejemplo n.º 19
0
        private void CreateDataTypeData()
        {
            void InsertDataTypeDto(int id, string editorAlias, string dbType, string configuration = null)
            {
                var dataTypeDto = new DataTypeDto
                {
                    NodeId      = id,
                    EditorAlias = editorAlias,
                    DbType      = dbType
                };

                if (configuration != null)
                {
                    dataTypeDto.Configuration = configuration;
                }

                _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto);
            }

            //layouts for the list view
            const string cardLayout = "{\"name\": \"Grid\",\"path\": \"views/propertyeditors/listview/layouts/grid/grid.html\", \"icon\": \"icon-thumbnails-small\", \"isSystem\": 1, \"selected\": true}";
            const string listLayout = "{\"name\": \"List\",\"path\": \"views/propertyeditors/listview/layouts/list/list.html\",\"icon\": \"icon-list\", \"isSystem\": 1,\"selected\": true}";
            const string layouts    = "[" + cardLayout + "," + listLayout + "]";

            // TODO: Check which of the DataTypeIds below doesn't exist in umbracoNode, which results in a foreign key constraint errors.
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = Constants.DataTypes.Boolean, EditorAlias = Constants.PropertyEditors.Aliases.Boolean, DbType = "Integer"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = -51, EditorAlias = Constants.PropertyEditors.Aliases.Integer, DbType = "Integer"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId        = -87, EditorAlias = Constants.PropertyEditors.Aliases.TinyMce, DbType = "Ntext",
                Configuration = "{\"value\":\",code,undo,redo,cut,copy,mcepasteword,stylepicker,bold,italic,bullist,numlist,outdent,indent,mcelink,unlink,mceinsertanchor,mceimage,umbracomacro,mceinserttable,umbracoembed,mcecharmap,|1|1,2,3,|0|500,400|1049,|true|\"}"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = Constants.DataTypes.Textbox, EditorAlias = Constants.PropertyEditors.Aliases.TextBox, DbType = "Nvarchar"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = Constants.DataTypes.Textarea, EditorAlias = Constants.PropertyEditors.Aliases.TextArea, DbType = "Ntext"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = Constants.DataTypes.Upload, EditorAlias = Constants.PropertyEditors.Aliases.UploadField, DbType = "Nvarchar"
            });
            InsertDataTypeDto(Constants.DataTypes.LabelString, Constants.PropertyEditors.Aliases.Label, "Nvarchar", "{\"umbracoDataValueType\":\"STRING\"}");
            InsertDataTypeDto(Constants.DataTypes.LabelInt, Constants.PropertyEditors.Aliases.Label, "Integer", "{\"umbracoDataValueType\":\"INT\"}");
            InsertDataTypeDto(Constants.DataTypes.LabelBigint, Constants.PropertyEditors.Aliases.Label, "Nvarchar", "{\"umbracoDataValueType\":\"BIGINT\"}");
            InsertDataTypeDto(Constants.DataTypes.LabelDateTime, Constants.PropertyEditors.Aliases.Label, "Date", "{\"umbracoDataValueType\":\"DATETIME\"}");
            InsertDataTypeDto(Constants.DataTypes.LabelDecimal, Constants.PropertyEditors.Aliases.Label, "Decimal", "{\"umbracoDataValueType\":\"DECIMAL\"}");
            InsertDataTypeDto(Constants.DataTypes.LabelTime, Constants.PropertyEditors.Aliases.Label, "Date", "{\"umbracoDataValueType\":\"TIME\"}");
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = Constants.DataTypes.DateTime, EditorAlias = Constants.PropertyEditors.Aliases.DateTime, DbType = "Date"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = -37, EditorAlias = Constants.PropertyEditors.Aliases.ColorPicker, DbType = "Nvarchar"
            });
            InsertDataTypeDto(Constants.DataTypes.DropDownSingle, Constants.PropertyEditors.Aliases.DropDownListFlexible, "Nvarchar", "{\"multiple\":false}");
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = -40, EditorAlias = Constants.PropertyEditors.Aliases.RadioButtonList, DbType = "Nvarchar"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = -41, EditorAlias = "Umbraco.DateTime", DbType = "Date", Configuration = "{\"format\":\"YYYY-MM-DD\"}"
            });
            InsertDataTypeDto(Constants.DataTypes.DropDownMultiple, Constants.PropertyEditors.Aliases.DropDownListFlexible, "Nvarchar", "{\"multiple\":true}");
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = -43, EditorAlias = Constants.PropertyEditors.Aliases.CheckBoxList, DbType = "Nvarchar"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId        = Constants.DataTypes.Tags, EditorAlias = Constants.PropertyEditors.Aliases.Tags, DbType = "Ntext",
                Configuration = "{\"group\":\"default\", \"storageType\":\"Json\"}"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = Constants.DataTypes.ImageCropper, EditorAlias = Constants.PropertyEditors.Aliases.ImageCropper, DbType = "Ntext"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId        = Constants.DataTypes.DefaultContentListView, EditorAlias = Constants.PropertyEditors.Aliases.ListView, DbType = "Nvarchar",
                Configuration = "{\"pageSize\":100, \"orderBy\":\"updateDate\", \"orderDirection\":\"desc\", \"layouts\":" + layouts + ", \"includeProperties\":[{\"alias\":\"updateDate\",\"header\":\"Last edited\",\"isSystem\":1},{\"alias\":\"owner\",\"header\":\"Updated by\",\"isSystem\":1}]}"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId        = Constants.DataTypes.DefaultMediaListView, EditorAlias = Constants.PropertyEditors.Aliases.ListView, DbType = "Nvarchar",
                Configuration = "{\"pageSize\":100, \"orderBy\":\"updateDate\", \"orderDirection\":\"desc\", \"layouts\":" + layouts + ", \"includeProperties\":[{\"alias\":\"updateDate\",\"header\":\"Last edited\",\"isSystem\":1},{\"alias\":\"owner\",\"header\":\"Updated by\",\"isSystem\":1}]}"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId        = Constants.DataTypes.DefaultMembersListView, EditorAlias = Constants.PropertyEditors.Aliases.ListView, DbType = "Nvarchar",
                Configuration = "{\"pageSize\":10, \"orderBy\":\"username\", \"orderDirection\":\"asc\", \"includeProperties\":[{\"alias\":\"username\",\"isSystem\":1},{\"alias\":\"email\",\"isSystem\":1},{\"alias\":\"updateDate\",\"header\":\"Last edited\",\"isSystem\":1}]}"
            });

            //New UDI pickers with newer Ids
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = 1046, EditorAlias = Constants.PropertyEditors.Aliases.ContentPicker, DbType = "Nvarchar"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = 1047, EditorAlias = Constants.PropertyEditors.Aliases.MemberPicker, DbType = "Nvarchar"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = 1048, EditorAlias = Constants.PropertyEditors.Aliases.MediaPicker, DbType = "Ntext"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId        = 1049, EditorAlias = Constants.PropertyEditors.Aliases.MediaPicker, DbType = "Ntext",
                Configuration = "{\"multiPicker\":1}"
            });
            _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto {
                NodeId = 1050, EditorAlias = Constants.PropertyEditors.Aliases.MultiUrlPicker, DbType = "Ntext"
            });
        }
Ejemplo n.º 20
0
 public void Delete(DataTypeDto dto)
 {
     _connection.Query <int>(DataTypeDaoSql.Delete, new { Id = dto.Id }, _transaction);
 }
Ejemplo n.º 21
0
 public void Update(DataTypeDto dto)
 {
     _connection.Query <int>(DataTypeDaoSql.Update, new { Name = dto.Name, ClrType = dto.ClrType }, _transaction);
 }
Ejemplo n.º 22
0
 public ActionResult Delete(DataTypeDto categoryViewModel)
 {
     //var categoryService = new CategoryService();
     _dataTypeService.Delete(c => c.Id.Equals(categoryViewModel.Id));
     return(RedirectToAction("List"));
 }
Ejemplo n.º 23
0
 public ActionResult Edit(DataTypeDto categoryViewModel)
 {
     _dataTypeService.Update(categoryViewModel);
     return(RedirectToAction("List"));
 }
Ejemplo n.º 24
0
 public ActionResult Create(DataTypeDto categoryViewModel)
 {
     _dataTypeService.Insert(categoryViewModel);
     return(RedirectToAction("List"));
 }
        public void Issue8370Test()
        {
            // fixme maybe we need to create some content?
            // yes otherwise cannot get it to fail!

            var n = new NodeDto
            {
                Text       = "text",
                CreateDate = DateTime.Now,
                Path       = "-1",
                ParentId   = -1,
                UniqueId   = Guid.NewGuid()
            };

            DatabaseContext.Database.Insert(n);
            var ct = new ContentTypeDto
            {
                Alias     = "alias",
                NodeId    = n.NodeId,
                Thumbnail = "thumb"
            };

            DatabaseContext.Database.Insert(ct);
            n = new NodeDto
            {
                Text       = "text",
                CreateDate = DateTime.Now,
                Path       = "-1",
                ParentId   = -1,
                UniqueId   = Guid.NewGuid()
            };
            DatabaseContext.Database.Insert(n);
            var dt = new DataTypeDto
            {
                PropertyEditorAlias = Constants.PropertyEditors.RelatedLinksAlias,
                DbType     = "x",
                DataTypeId = n.NodeId
            };

            DatabaseContext.Database.Insert(dt);
            var pt = new PropertyTypeDto
            {
                Alias         = "alias",
                ContentTypeId = ct.NodeId,
                DataTypeId    = dt.DataTypeId
            };

            DatabaseContext.Database.Insert(pt);
            n = new NodeDto
            {
                Text       = "text",
                CreateDate = DateTime.Now,
                Path       = "-1",
                ParentId   = -1,
                UniqueId   = Guid.NewGuid()
            };
            DatabaseContext.Database.Insert(n);
            var data = new PropertyDataDto
            {
                NodeId         = n.NodeId,
                PropertyTypeId = pt.Id,
                Text           = "text",
                VersionId      = Guid.NewGuid()
            };

            DatabaseContext.Database.Insert(data);
            data = new PropertyDataDto
            {
                NodeId         = n.NodeId,
                PropertyTypeId = pt.Id,
                Text           = "<root><node title=\"\" type=\"\" newwindow=\"\" link=\"\" /></root>",
                VersionId      = Guid.NewGuid()
            };
            DatabaseContext.Database.Insert(data);

            var migration = new UpdateRelatedLinksData(SqlSyntax, Logger);

            migration.UpdateRelatedLinksDataDo(DatabaseContext.Database);

            data = DatabaseContext.Database.Fetch <PropertyDataDto>("SELECT * FROM cmsPropertyData WHERE id=" + data.Id).FirstOrDefault();
            Assert.IsNotNull(data);
            Debug.Print(data.Text);
            Assert.AreEqual("[{\"title\":\"\",\"caption\":\"\",\"link\":\"\",\"newWindow\":false,\"type\":\"external\",\"internal\":null,\"edit\":false,\"isInternal\":false}]",
                            data.Text);
        }
Ejemplo n.º 26
0
        protected override void Migrate()
        {
            // insert other label datatypes

            void InsertNodeDto(int id, int sortOrder, string uniqueId, string text)
            {
                var nodeDto = new NodeDto
                {
                    NodeId         = id,
                    Trashed        = false,
                    ParentId       = -1,
                    UserId         = -1,
                    Level          = 1,
                    Path           = "-1,-" + id,
                    SortOrder      = sortOrder,
                    UniqueId       = new Guid(uniqueId),
                    Text           = text,
                    NodeObjectType = Cms.Core.Constants.ObjectTypes.DataType,
                    CreateDate     = DateTime.Now
                };

                Database.Insert(Cms.Core.Constants.DatabaseSchema.Tables.Node, "id", false, nodeDto);
            }

            if (SqlSyntax.SupportsIdentityInsert())
            {
                Database.Execute(new Sql($"SET IDENTITY_INSERT {SqlSyntax.GetQuotedTableName(Cms.Core.Constants.DatabaseSchema.Tables.Node)} ON "));
            }

            InsertNodeDto(Cms.Core.Constants.DataTypes.LabelInt, 36, "8e7f995c-bd81-4627-9932-c40e568ec788", "Label (integer)");
            InsertNodeDto(Cms.Core.Constants.DataTypes.LabelBigint, 36, "930861bf-e262-4ead-a704-f99453565708", "Label (bigint)");
            InsertNodeDto(Cms.Core.Constants.DataTypes.LabelDateTime, 37, "0e9794eb-f9b5-4f20-a788-93acd233a7e4", "Label (datetime)");
            InsertNodeDto(Cms.Core.Constants.DataTypes.LabelTime, 38, "a97cec69-9b71-4c30-8b12-ec398860d7e8", "Label (time)");
            InsertNodeDto(Cms.Core.Constants.DataTypes.LabelDecimal, 39, "8f1ef1e1-9de4-40d3-a072-6673f631ca64", "Label (decimal)");

            if (SqlSyntax.SupportsIdentityInsert())
            {
                Database.Execute(new Sql($"SET IDENTITY_INSERT {SqlSyntax.GetQuotedTableName(Cms.Core.Constants.DatabaseSchema.Tables.Node)} OFF "));
            }

            void InsertDataTypeDto(int id, string dbType, string configuration = null)
            {
                var dataTypeDto = new DataTypeDto
                {
                    NodeId      = id,
                    EditorAlias = Cms.Core.Constants.PropertyEditors.Aliases.Label,
                    DbType      = dbType
                };

                if (configuration != null)
                {
                    dataTypeDto.Configuration = configuration;
                }

                Database.Insert(Cms.Core.Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto);
            }

            InsertDataTypeDto(Cms.Core.Constants.DataTypes.LabelInt, "Integer", "{\"umbracoDataValueType\":\"INT\"}");
            InsertDataTypeDto(Cms.Core.Constants.DataTypes.LabelBigint, "Nvarchar", "{\"umbracoDataValueType\":\"BIGINT\"}");
            InsertDataTypeDto(Cms.Core.Constants.DataTypes.LabelDateTime, "Date", "{\"umbracoDataValueType\":\"DATETIME\"}");
            InsertDataTypeDto(Cms.Core.Constants.DataTypes.LabelDecimal, "Decimal", "{\"umbracoDataValueType\":\"DECIMAL\"}");
            InsertDataTypeDto(Cms.Core.Constants.DataTypes.LabelTime, "Date", "{\"umbracoDataValueType\":\"TIME\"}");

            // flip known property types

            var labelPropertyTypes = Database.Fetch <PropertyTypeDto>(Sql()
                                                                      .Select <PropertyTypeDto>(x => x.Id, x => x.Alias)
                                                                      .From <PropertyTypeDto>()
                                                                      .Where <PropertyTypeDto>(x => x.DataTypeId == Cms.Core.Constants.DataTypes.LabelString));

            var intPropertyAliases    = new[] { Cms.Core.Constants.Conventions.Media.Width, Cms.Core.Constants.Conventions.Media.Height, Cms.Core.Constants.Conventions.Member.FailedPasswordAttempts };
            var bigintPropertyAliases = new[] { Cms.Core.Constants.Conventions.Media.Bytes };
            var dtPropertyAliases     = new[] { Cms.Core.Constants.Conventions.Member.LastLockoutDate, Cms.Core.Constants.Conventions.Member.LastLoginDate, Cms.Core.Constants.Conventions.Member.LastPasswordChangeDate };

            var intPropertyTypes    = labelPropertyTypes.Where(pt => intPropertyAliases.Contains(pt.Alias)).Select(pt => pt.Id).ToArray();
            var bigintPropertyTypes = labelPropertyTypes.Where(pt => bigintPropertyAliases.Contains(pt.Alias)).Select(pt => pt.Id).ToArray();
            var dtPropertyTypes     = labelPropertyTypes.Where(pt => dtPropertyAliases.Contains(pt.Alias)).Select(pt => pt.Id).ToArray();

            Database.Execute(Sql().Update <PropertyTypeDto>(u => u.Set(x => x.DataTypeId, Cms.Core.Constants.DataTypes.LabelInt)).WhereIn <PropertyTypeDto>(x => x.Id, intPropertyTypes));
            Database.Execute(Sql().Update <PropertyTypeDto>(u => u.Set(x => x.DataTypeId, Cms.Core.Constants.DataTypes.LabelInt)).WhereIn <PropertyTypeDto>(x => x.Id, intPropertyTypes));
            Database.Execute(Sql().Update <PropertyTypeDto>(u => u.Set(x => x.DataTypeId, Cms.Core.Constants.DataTypes.LabelBigint)).WhereIn <PropertyTypeDto>(x => x.Id, bigintPropertyTypes));
            Database.Execute(Sql().Update <PropertyTypeDto>(u => u.Set(x => x.DataTypeId, Cms.Core.Constants.DataTypes.LabelDateTime)).WhereIn <PropertyTypeDto>(x => x.Id, dtPropertyTypes));

            // update values for known property types
            // depending on the size of the site, that *may* take time
            // but we want to parse in C# not in the database
            var values = Database.Fetch <PropertyDataValue>(Sql()
                                                            .Select <PropertyDataDto>(x => x.Id, x => x.VarcharValue)
                                                            .From <PropertyDataDto>()
                                                            .WhereIn <PropertyDataDto>(x => x.PropertyTypeId, intPropertyTypes));

            foreach (var value in values)
            {
                Database.Execute(Sql()
                                 .Update <PropertyDataDto>(u => u
                                                           .Set(x => x.IntegerValue, string.IsNullOrWhiteSpace(value.VarcharValue) ? (int?)null : int.Parse(value.VarcharValue, NumberStyles.Any, CultureInfo.InvariantCulture))
                                                           .Set(x => x.TextValue, null)
                                                           .Set(x => x.VarcharValue, null))
                                 .Where <PropertyDataDto>(x => x.Id == value.Id));
            }

            values = Database.Fetch <PropertyDataValue>(Sql().Select <PropertyDataDto>(x => x.Id, x => x.VarcharValue).From <PropertyDataDto>().WhereIn <PropertyDataDto>(x => x.PropertyTypeId, dtPropertyTypes));
            foreach (var value in values)
            {
                Database.Execute(Sql()
                                 .Update <PropertyDataDto>(u => u
                                                           .Set(x => x.DateValue, string.IsNullOrWhiteSpace(value.VarcharValue) ? (DateTime?)null : DateTime.Parse(value.VarcharValue, CultureInfo.InvariantCulture, DateTimeStyles.None))
                                                           .Set(x => x.TextValue, null)
                                                           .Set(x => x.VarcharValue, null))
                                 .Where <PropertyDataDto>(x => x.Id == value.Id));
            }

            // anything that's custom... ppl will have to figure it out manually, there isn't much we can do about it
        }