Excluding some result based on category
Hello,
I need to show the most viewed items based on some criteria I paste here....... I also wish to show only the items that don't belong to a specific category....how can I do this?
Thanks
int value = Math.Abs(giorniPrecedenti);
DateTime DataMinima = DateTime.Now.AddDays(-value);
var res1 = App.WorkWith().Documents().Where(o1 => o1.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && o1.ViewsCount > 0
&& o1.PublicationDate >= DataMinima && o1.PublicationDate <= DateTime.Now ).OrderByDescending(o2 => o2.ViewsCount);
res1 = res1.Take(numItems);
Hello Paolo,
1. Is there a problem with the query you posted above. I see that you use ViewCount property of the content item which shows how many items an items is view and data time comparison.
2. To get items that does not belong to a given category you can search through item's properties for the category, if it is not found, add it to a list
var ni = App.WorkWith().NewsItems().Where(cnt => cnt.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).Get();
foreach
(NewsItem itm
in
ni)
var cat = TypeDescriptor.GetProperties(itm).Find(
"SomeCategory"
,
false
);
if
(cat !=
null
)
// add this item to a list