My custom method looks like this and is working.
Now I am stuck with the ordering and filtering.
[System.Web.Http.AcceptVerbs("GET", "POST")]
[System.Web.Http.HttpGet]
[System.Web.Http.AllowAnonymous]
public ActionResult GetNewsByParentId(int Id,int PageIndex = 0,int PageSize = 10
, string orderby, string direction, string filter = null)
//are there children for this content id?
bool hasChildren = Services.ContentService.HasChildren(Id);
//get the first 10 childeren
IEnumerable<IContent> Children = Services.ContentService.GetPagedChildren(Id, PageIndex, PageSize, out long TotalChildren);
//create Json object
var result = new JsonResult
Data = new
TotalChildren
,PageIndex
,PageSize
,Children
JsonRequestBehavior = JsonRequestBehavior.AllowGet
return result;
Ordering:
I would like to now if I can filter by a 1 or multiple custom field
.OrderBy("Tag").ThenBy("Date")
Or can i only use the default properties (publisheddate, Name etc) (and where can I find a list with witch ones)
De filter function
How can I use to search on multiple tags / words / numbers (is this even possible?)
can i use where and or contains?
I hope somebody can help me with a nice example.
Services.ContentService.GetPagedChildren(Id, PageIndex, PageSize, out long TotalChildren,"?","?","?");
regards
Yes I did
public ActionResult GetNewsByParentId(int Id,int PageIndex = 0,int PageSize = 10, string filter = null)
//are there children for this content id?
bool hasChildren = Services.ContentService.HasChildren(Id);
IEnumerable<IContent> Children = Services.ContentService.GetPagedChildren(Id, PageIndex, PageSize, out long TotalChildren, null, Ordering.By("CreateDate", Direction.Descending, null, false));
//create Json object
var result = new JsonResult
Data = new
TotalChildren
,PageIndex
,PageSize
,Children
JsonRequestBehavior = JsonRequestBehavior.AllowGet
return result;
Then I get "The type name Query<> does not exits in the type SqlContext
For your question I think it implies you are using a non Static method.
public static string YourMethod() { ... }
or create a new instance (this is my working example)
public ActionResult GetNewsByParentId(int Id,int PageIndex = 0,int PageSize = 10, string filter = null)
var Filter = SqlContext.Query<IContent>();
if (filter != null)
Filter = Filter.Where(x => x.Name.Contains(filter));
Filter = null;
IEnumerable <IContent> Children = Services.ContentService.GetPagedChildren(Id, PageIndex, PageSize, out long TotalChildren, Filter, Ordering.By("CreateDate", Direction.Descending, null, false));
var result = new JsonResult
Data = new
TotalChildren
,PageIndex
,PageSize
,Children
JsonRequestBehavior = JsonRequestBehavior.AllowGet
return result;
On the otherhand:
I do not think Umbraco is going to fix this problem properly because al the data is saved as a Json object in the Database. And you can only query Json nativily from sql server 2016. So that you can write querys that can query Json object.
I think it would be a better solution to create a own stored procedure and add all the parameters you want to query. This will work better then the current native Umbraco function.
If you are using sql server 2016, you can use Json query (https://docs.microsoft.com/en-us/sql/t-sql/functions/json-query-transact-sql?view=sql-server-2016)
Otherwise ==> https://stackoverflow.com/a/23724200/2910930
regards
Thanks for your reply !
I actually ended up using the content service and quering and filtering on that.