I have a content item the has a field with a library of files. I created a separate content item to store the metadata for the files, which includes an integer field called SortOrder that is used for controlling the order of images on the page.
To make the sorting faster at the client's request, I created a page for admins with a jQuery sortable grid of the images that enables drag-and-drop ordering. This works very well by updating the metadata each time an image is dragged.
The problem is that a metadata entry isn't automatically created each time a new image is dragged into the library, so in this case there is no metadata to update. I can manually create the content item, but there doesn't seem to be a way in the API to tag it as belonging to a particular library item.
Hopefully someone can help me find a way using the 2SXC WebAPI or c# code to add metadata to any library item that doesn't exist. I see in the database that the entities are linked in the ToSIC_EAV_Entities using the AssignmentObjectTypeID and KeyString fields, but I would prefer to not make direct database changes. These changes also seem to require clearing the cache and restarting the application pool to be reflected in the UI.
答案 0 :(得分:1)
因此,到目前为止,这实际上是REST API中缺少的细节,但是App.Data.Create对此有一个重载。查看https://github.com/2sic/eav-server/blob/master/ToSic.Eav.AppEngine/DataSources/App.cs#L26
因此它并不完美,但您现在应该可以继续工作。
答案 1 :(得分:0)
根据您的指针,我能够使用自定义WebAPI创建解决方案:
var contentTypeName = "PhotoDetails";
var userName = Dnn.User.Username;
var fileId = metadata.FileId.ToString();
MetadataFor target = new MetadataFor()
{
TargetType = 10, // hardcoded based on other content item metadata for no until further understood
KeyString = "file:" + fileId // file number comes from dnn's file table
};
var values = new Dictionary<string, object>()
{
{"Title", metadata.Title},
{"SortOrder", (fileId+99)}, // make new images appear at the end by adding 99 to the fileid so they stay in the upload order
{"IsPrimary", false} // image is not a primary photo by default
};
App.Data.Create(contentTypeName, values, userName, target);
再次感谢您的建议!