Ektron CMS asp.net : How to get list of child taxonomies under parent taxonomy recursively - ektron

I'm working on Ektron CMS asp.net web forms(not mvc).
I want to get list of child taxonomies under parent taxonomy recursively.
Could anyone help me on this.

This should work:
using Ektron.Cms.Framework.Organization;
using Ektron.Cms.Organization;
using System.Collections.Generic;
Code:
long parentID = 2147486197; // This is the parent taxonomy's ID
TaxonomyManager taxMan = new TaxonomyManager();
TaxonomyCriteria criteria = new TaxonomyCriteria();
criteria.AddFilter(TaxonomyProperty.ParentId, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, parentID);
List<Ektron.Cms.TaxonomyData> resultsList = taxMan.GetList(criteria);

Related

Pass list from Razor page to code behind to bulk insert using Dapper

So I've created an HTML table on a Razor page as shown below. Basically I'm just calling a method that returns a list and then using a foreach to go create the rows and controls. The part I'm completely lost on is how I go about posting this data back to the server and on the code behind using that data to insert back to SQL Server. I'm using Dapper and I'd like each row of the table to represent a data row, or one object, but how do I get the data from the Razor page passed back as a list of a class? Not sure if my terminology is accurate here but can you model bind on a list of a type? Would appreciate some assistance thanks!
It seems I'm so far off track (or so few people use asp.net core and Dapper) that I'm not getting any help. But someone very helpful marked down my question without commenting - thanks so much.
I realised the key thing I was doing wrong was trying to circumvent model binding, so I created a class/type Rating that represents each row (each column as a property) and then an Assessment type/class that contains a List as one of the properties.
On the Razor page:
#foreach (Comp c in Model.GetComps())
{
count++;
Model.assessment.Ratings.Add(new Rating());
Model.assessment.Ratings[count].AchievedCompetencyID = c.AchievedCompetencyID;
Code behind:
public void OnPost()
{
using (IDbConnection con = new SqlConnection(Startup.conStr))
{
long assessID = con.Insert(assessment);
foreach (Rating r in assessment.Ratings)
{
r.AssessmentID = Convert.ToInt32(assessID);
con.Insert(r);
}
}
}

Categories list in Piranha CMS?

I'm using Piranha Core 8 with Aspnetcore 3. So far everything is going well. (I love Piranha!)
My current problem is when building a Sidebar with a list of categories.
I can't figure out how to retrieve all categories from the Api.
So far, I can get a list of posts, and perhaps iterate over them to collect the categories but this seems inefficient.
Any one know how to retrieve a list of all the categories from the cshtml pages?
You can get the full list of taxonomies per Archive by calling the Api.
var categories = await api.GetAllCategoriesAsync(archiveId);
var tags = await api.GetAllTagsAsync(archiveId);
Best regards
From the razor page I got it working this way :
#{
var archiveId = WebApp.CurrentPost == null ? WebApp.CurrentPage.Id : WebApp.CurrentPost.BlogId;
var categories = await WebApp.Api.Posts.GetAllCategoriesAsync(archiveId);
var tags = await WebApp.Api.Posts.GetAllTagsAsync(archiveId);
}

How to map colums in a table database in to Properties and relation with Fields

I'm studying Sensenet Framework and installed successfull on my computer, and now I'm developing our website based on this framework.I read documents on wiki and understood relationship between Database <-> Properties <--> Fields <-> View (you can see the image in this link: http://wiki.sensenet.com/Field_-_for_Developers). For suppose, if I added a new table in to Sensenet's database and desiderate show all datas inside this table to our page, but I don't know how to dev flow by this model: Database <=> Property <=> Field <=> View. ? can you show steps to help me?
Please consider storing your data in the SenseNet Content Repository instead of keeping custom tables in the database. It is much easier to work with regular content items and you will have all the feature the repo offers - e.g. indexing, permissions, and of course an existing UI. To do this, you will have to take the following steps:
Define content types in SenseNet for every entity type you have in your existing db (in the example below this is the Car type).
Create a container in the Content Repository where you want to put your content (in this case this is a Cars custom list under the default site).
Create a command line tool using the SenseNet Client library to migrate your existing data to the Content Repository.
To see the example in detail, please check out this article:
How to migrate an existing database to the Content Repository
The core of the example is really a few lines of code that actually saves content items into the Content Repository (through the REST API):
using (var conn = new SqlConnection(ConnectionString))
{
await conn.OpenAsync();
using (var command = new SqlCommand("SELECT * FROM Cars", conn))
{
using (var reader = await command.ExecuteReaderAsync())
{
while (await reader.ReadAsync())
{
var id = reader.GetInt32(0);
var make = reader.GetString(1);
var model = reader.GetString(2);
var price = reader.GetInt32(3);
// Build a new content in memory and fill custom metadata fields. No need to create
// strongly typed objects here as the client Content is a dynamic type.
// Parent path is a Content Repository path, e.g. "/Root/Sites/Default_Site/Cars"
dynamic car = Content.CreateNew(ParentPath, "Car", "Car-" + id);
car.Make = make;
car.Model = model;
car.Price = price;
// save it through the HTTP REST API
await car.SaveAsync();
Console.WriteLine("Car-" + id + " saved.");
}
}
}
}

MVC Routing with wildcard

I am developing a website on Asp MVC4
I have a link like that www.myhostname/category/{some arbitrary text}_ProductId
(e.g: www.myhostname.com/electronics/the-new-ipad_12345, in which 12345 is the ProductId that I need to extract)
Is the any way to register one route that give my directly the Id ?
I tried
routes.MapRoute(
name: "productRoute",
url: "{category}/*_{ProductId}",
defaults: new { Controller = "Home", action = "Product" }
);
But of course, it doesn't work
Note : as a work around, I used "{category}/{ProductLink}", to get the whole segment (e.g: the-new-ipad_12345) and extracted this ProductId on my action
Thanks & regards,
You are better off using attribute based routing. You can add regex to [Route] attribute and parse the product id.
It is part of Web API 2 now. If you are using older version of Web API, you can add reference to - http://attributerouting.net/
The final solution will look something like..
[Route("electronics/{productId:int:regex(_([0-9]+))}")]
public ProductDto GetProduct(int productId)
{
// ...
}

Dynamic Crm 2013 : Get Attributes (only the attr in Form) in MetaData of Entity

I want to Retrive Metadata Attributes of Entity , but XrmServiceToolkit gave me all attributes , i want to fillter only the Active Attributes that on the Form and not all attributes.
which parameter tell me if the Attribute in Form or Not in Form ?
The Metadata of an entity contains always all the attributes. Dynamics CRM 2011/2013 support multiple forms, so you need to query the specific form (SystemForm entity) and parse the formxml result to know which attributes are inside the form.
If you are executing the JavaScript inside the form you want to query, you can also access the Xrm.Page.data.entity.attributes collection without querying the metadata.
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes) {
//
}