I've created a simple forum in Umbraco using page nodes as threads with the child pages acting as replies. I'd like to sort the most recent activities by to latest created or latest replied, like any forum does it. I'm really terrible at LINQ and was hoping you could help me out with the syntax. This is about as far as I've gotten (ordering the first level) but I'm not sure how to include the child pages of each child of CurrentPage in it. Any input to help me along the way?
var childPages = CurrentPage.Children.OrderBy(x => x.CreateDate);
Related
I've been refactoring an existing Umbraco project to use more performant querying when getting back document data as everything was previously being returned using LINQ. I have been using a combination of Umbraco's querying via XPaths and Examine.
I am currently stumped on trying to get child documents using the Umbraco.ContentAtXPath() method. What I would like to do is get child document based on a path I parse to the method. This is what I have currently:
IEnumerable<IPublishedContent> umbracoPages = Umbraco.ContentAtXPath("//* [#isDoc]/descendant::/About [#isDoc]");
Running this returns a "Object reference not set to an instance of an object." error and unable to see exactly where I'm going wrong (new to this form of querying in Umbraco).
Ideally, I'd like to enhance the querying to also carry out sorting using the non-LINQ approach, as demonstrated here.
Up until Umbraco 8, content was cached in an XML file, which made XPath perfect for querying content efficiently. In v8, however, the so called "NuCache" is not file based nor XML based, so the XPath query support is only there for ... well... Old times sake, I guess? Either way it's probably not going to be super efficient and (I'd advise) not something to "aim for". That said I of course don't know what you are changing from (Linq can be a lot of things) :-/
It certainly depends on how big your dataset is.
As Umbraco has moved away from the XML backed cache, you should look into Linq queries against your content models. Make sure you use ModelsBuilder to generate the models.
On a small dataset Linq will be much quicker than examine. On a large dataset Examine/Lucene will be much more steady on performance.
Querying NuCache is pretty fast in Umbraco 8, only beaten by an Examine search.
Assuming you're using Models Builder, and your About page is a child of Home page, you could use:
var homePage = (HomePage) Model.Root();
var aboutPage = homePage?.Children<AboutPage>().FirstOrDefault();
var umbracoPages = aboutPage.Children();
Where HomePage is your home page Document Type Alias and AboutPage is your About page Document Type alias.
I'm building a web service for a client that pulls data from the Sitefinity CMS. The problem is they want to pass in a Guid for the service and receive the info about this item. No problem except I only have been able to locate the "live" Guid for one Item (and that was by combing through the HTML in the back end).
I was going to look at the tables in SQL Server but I'm not sure which table to look at. The content items have several tables all related of course and there isn't any documentation on how to look at this. I can find plenty of documentation on querying the master Guid, but no place to find it.
Oh, and these are custom content types built by the Module Builder.
Any Help would be SOOOOO appreciated!
var master = DynamicModuleManager.GetManager().Lifecycle.GetMaster(<liveGuidHere>);
One of the biggest consumers of Sitefinity webservices is Sitefinity. The best place to start looking for that guid is to take a look at what web service calls are being made when you pull up your custom content item list in the backend. I used the chrome developer tools and check in the network tab.
One I found for a stores module made with module builder was something to the effect of http://www.testsite.com/Sitefinity/Services/DynamicModules/Data.svc/?managerType=Telerik.Sitefinity.DynamicModules.DynamicModuleManager&providerName=OpenAccessProvider&itemType=Telerik.Sitefinity.DynamicTypes.Model.Stores.Store&provider=OpenAccessProvider&sortExpression=LastModified%20DESC&skip=0&take=50
The json this returns is a list of all the masters with their ids (note in the list that the content items all have have a status of 0) http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/modules/content-lifecycle
When you go to Administration / Module Builder / Your Module, you will see a link to the API on the top right corner.
This link goes to a page full of API examples for your particular module which is kind of cool.
Basically you would have to find your item first using LINQ and the GetValue extension method.
Once you have the item you can get its ID or any other property.
using Telerik.Sitefinity.Utilities.TypeConverters;
using Telerik.Sitefinity.DynamicModules;
using Telerik.Sitefinity.Model;
....
var mgr = DynamicModuleManager.GetManager();
var countrymasters = from ctry in mgr.GetDataItems(TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Destinations.Destination"))
where ctry.GetValue<string>("culture") == siteid &&
(ctry.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && ctry.Visible == true)
select new
{
airport_cd = ctry.GetValue<string>("airport_cd"),
country_master_cd = ctry.GetValue<string>("country_master_cd")
};
I'm brand new to .NET 4.5, bootstrap, and LINQ and I've come across an issue I don't know how to handle elegantly. I was hoping somebody could confirm or correct my thought process, and if you're feeling particularly charitable, point me to a resource that could help me achieve my aim.
I'm developing a page on a web app that is going to link to multiple outside applications. The way I've decided to group the apps is by using a bootstrap Tab control, and making each tab a logical group. I've written the LINQ query that returns all of the information about the apps I need (Title, Description, Link, etc.), but now I need to group the results by another field (which we call ContainerID) and put the groups in their proper Repeater control inside the correct Bootstrap tab.
As of now I'm putting one Repeater inside of each tab, which feels a little clunky, but I can't think of a better way to do it. My idea was to do the following:
1) do a foreach loop on the objects returned by the LINQ query
2) inside the foreach loop, write an if statement like "if ContainerID=" then add the result to a list or array and use that as the datasource for the corresponding Repeater and bind it
3) rinse and repeat for however many categories I need.
As I started down this path it looks to me like there's no such thing as a foreach with LINQ, so I'm dead at step 1. Any thoughts on the best way to accomplish my aim? Thanks in advance...
EDIT: I should mention I'm not tied to any of this. If there's a better UI design to accomplish my purpose, I'm all for it. I'm just looking for the cleanest way to implement it.
The results of a linq query is just the query itself. There are no results until you iterate over the result. You should then be able to iterate over the results like this:
var items = Your LINQ Query
foreach(var item in items)
{
if(ContainerID == item.id)
{
//do work
}
}
Or you can do a items.ToList() which will iterate the query and turn it into a list of objects that you can work with. Hope this helps.
Is there a viable way to search an Umbraco 5 site? I've read a lot on XLST search, but nothing using MVC3. It also seems that Examine is coming a little bit buggy, as even the backoffice has lost the search box that was present in v4. Any ideas?
As you know Umbraco V5 is retire; you can try 4.x and do the above with user controls that do search logic using umbraco node factory.
Hope you get my views.
I've created a very basic search, it might not be best way but it gives the results I need.
var results = Hive.QueryContent().OfRevisionType(FixedStatusTypes.Published).ToList().Where(c => c.AllAncestorIds().Any() && c.Name.ToLowerInvariant().Contains(query.ToLowerInvariant()) && c.Attribute<bool>("excludeFromSearch") == false).ToList();
OfRevisionType(FixedStatusTypes.Published) returns published pages
c.AllAncestorIds().Any() stops deleted items being returned
I have an "examinations" table, its consultation_id relates to "consulsations" table, which in turn its consulation_id relates to the "patients" table.
Now, when I am in the add.ctp, edit.ctp or view.ctp of the "Examinations" Views I need to pull the "patients" details in so that some patient info can appear as to who the form pertains to as patient.
I have tried joins. Not to say they dont work. I am new to cakephp and I really need help as to how it will appear within the controller and how the view.ctp will display it.
I thought of elements but they are just .ctp files right?
Please if anyone can help regarding this it would be so appreciated. I've been trying to do this now for a week and I know there is something simple I am dont doing or thinking rights about.
So you just want to pull in related data? Pretty simple.
In your ExaminationsController methods.
$patients = $this->Examination->Consultation->Patient->find('all',
array('conditions'=>array('consultation_id'=>$id,'examination_id'=>$e_id)));
Something similar to this, not quite sure on which id you need to pass, as it will depend on how your models are linked up. http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
However, if your models are linked up properly, you should get this data anyway. If not set your models recursion to be higher.
$this->Model->recursive = 2;