@inherits Custom.Hybrid.Razor14
@using ToSic.Razor.Blade;
@using System.Linq;
@{
// Tell the page that we need the 2sxc Js APIs
Kit.Page.Activate("2sxc.JsCore");
}
<!-- unimportant stuff, hidden -->
<div @Sys.PageParts.InfoWrapper()>
@Html.Partial("../shared/DefaultInfoSection.cshtml")
<div @Sys.PageParts.InfoIntro()>
<h2>Use the sxc data API to create metadata</h2>
<p>This page uses the sxc data API to create metadata in the backend.</p>
<br>
In this tutorial you'll learn how to:
<ul>
<li>
Create metadata for other entities using the javascript <code>.create(..., ...)</code> method
</li>
<li>
Delete existing items (so the demo doesn't grow uncontrollably) using the <code>.delete(...)</code> method
</li>
</ul>
<br>
Look at the content below to see the effect.
</div>
</div>
<table id="example-content" class="table">
<thead>
<tr>
<th>Name</th>
<th>Memberships</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var poet in AsList(App.Data["Poets"])) {
var membershipMd = AsList(poet.Metadata.OfType("DeadPoetSocietyMembership") as object);
<tr>
<td>@poet.Name</td>
<td>
@if (membershipMd.Any()) {
foreach (var membership in membershipMd) {
<span>
@membership.MembershipNumber
<a href="#" onclick="window.sxcDataTutorial240.del(@membership.EntityId)">delete</a>
</span>
}
} else {
<button type="button" class="btn btn-primary" onclick='window.sxcDataTutorial240.add("@poet.EntityGuid")'>
add membership (metadata)
</button>
}
</td>
</tr>
}
</tbody>
</table>
@* This tutorial uses turnOn, see turnOn tutorials *@
@{
var data = new {
moduleId = CmsContext.Module.Id
};
}
@Kit.Page.TurnOn("window.sxcDataTutorial240.init()", data: data)
<script src="@CmsContext.View.Path/310-create-metadata.js" @Kit.Page.AssetAttributes()></script>
@* Footer *@
@Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })