How to get Unpublished Contents from umbraco - umbraco

I'm the new to Umbraco and I'm struggling to get the unpublished contents.
I have created a document type article and article items as mentioned in our Umbraco tutorial. In content section I have created a five number of article items as a blog and unpublished two of them. I'm getting three published article items in the site. Now I want to get the unpublished contents instead of published one. How I can do this?

You can use the ContentService to get your unpublished content, but be very careful when using the ContentService as this service directly gets the data from the Umbraco database rather than the cache and this will cause a lot of problems on your site, like the website being very slow, especially if a lot of people are reaching to your website.
Here is an example to use the ContentService, You can take a look at this blog post for more details.
var contentService = new ContentService();
IContent content = contentService.GetById(123); // 123 is the nodeId
Here is another example;
var content = ApplicationContext.Current.Services.ContentService.GetById(123);
For the latest version of Umbraco (v9 as of today), you should use Dependency Injection in your constructor to get the ContentService:
public class MyClass
{
private IContentService _contentService;
public MyClass(IContentService contentService)
{
_contentService = contentService;
}
}
Update: Today I have had a chance to add some screenshots for an Umbraco v7 project, please see below how you can get the unpublished content via the ContentService - things could be a little different for an Umbraco v8 project:

Related

Getting content from umbraco to mvc backend

My client wants to be able to enter things into the admin section of umbraco and add things into the editor. From there how can I pull that data from the mvc backend? I am able to find the node, it's parent, etc, but cannot find the text he wrote in the tinymce editor. What is the best way to get that text? Thank you for
There are two ways of getting data in Umbraco now:
1) ContentService - get IContent object from database
2) Umbraco.TypedContent - get IPublishedContent object from XML cache
In your case the best way will be to use Content service object and get data from the database, I would do it like that:
var content = ApplicationContext.Services.ContentService.GetById(1234);
var propertyValue = content.GetValue<Type>("propertyAlias");
Don't use IPublishedContent at backend because you have to use actual data from the database for working in controllers.

umbraco one site different brands

I'm very new to Umbraco and have a requirement to set up a site where different customers will access the same site, but see it with their own brand. It must be the same site in IIS and re-using the same razor views and related code, but our business teams have a requirement to set up a new customer for the same site, with their own values for the configurable content data via Umbraco without relying on support or developer involvement.
eg. Site URL is www.mysite.com
Customer from ClientA visits (maybe via URL www.mysite.com/ClientA or perhaps www.mysite.com?brand=ClientA) and sees the version branded for them.
A customer from ClientB should be able to visit the same site but passing in their brand code instead and see their customized version.
My first question is: Is this acheivable? If so, what is the correct way to do it?
I want to maximise code re-use.
Any help or pointers would be hugely appreciated.
Thanks in advance.
You can do this is standard asp.net, add a code behind for the standard default.aspx page that umbraco uses to drive everything and then in the onpreinit event switch either the master page or theme to the correct branding; something like:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
int templateId = umbraco.NodeFactory.Node.GetCurrent().template;
umbraco.template template = new umbraco.template(templateId);
string templateName = template.TemplateAlias;
if (Request.QueryString["brand"] = "ClientA")
{
Page.MasterPageFile = string.format("~/MasterPages/clienta/{0}.master", templateName);
}
}
So all content is tagged to the standard set of masterpages in the masterpages folder; but if a "?brand=ClientA" url is requested it automatically changes the masterpage to the clienta folder - allowing you to brand the page based on the querystring.

Editing Master Detail Records using Linq-2-Sql

I'm using Linq-2-Sql as ORM in asp.net mvc-3 application. First have a look at the form:
This is a master-detail form for editing batch info. Master part (Batch table) includes BatchNo, SKUTitle, StageID and Date field. Detail part (BatchDetail) contains fields PackingInstruction, ExpectedYield, Units and TargetDate. I have managed to save this information on single page in create scenario like
public ActionResult CreateBatch(Batch batch, BatchDetail detail)
{
batch.BatchDetails.AddRange(detail.ToList());
ctx.Batches.InsertOnSubmit(batch);
ctx.SubmitChanges();
}
but edit scenario is quite tricky. in this form as shown in figure above, user can add new records in detail portion, delete and edit existing records and by the time data is posted to controller we have no way of knowing which records are newly added, which are modified and which are deleted. So, as a consequence I have to do something like
public ActionResult EditBatch(int id, BatchDetail detail)
{
var batch = ctx.Batches.SingleOrDefault(x=>x.BatchID == id);
ctx.BatchDetails.DeleteAllOnSubmit(ctx.BatchDetails.ToList());
UpdateModel(batch);
batch.BatchDetails.AddRange(detail);
ctx.SubmitChanges();
}
I hate that part of deleting detail records in this scenario. is there a way in Linq-2-Sql that I can get around deleting all records in similar scenarios? If not can I accomplish this in EF without unnecessary deletion?
Edit
I have been studying Attach method of System.Data.Linq.Table but can't seem to figure out anything.
In the MVC Music Store Demo there is a small part that covers deleting items from the shopping cart by using JQuery AJAX to call the delete Controller action. The example is in part 8 of this tutorial.
The actual AJAX call explanation is about 3/4 of the way down the page. The headline for the section is "Ajax Updates with jQuery" if you want to search and find it quickly.

Have master page label display last edit date of child page being displayed

i'm building an asp.net site with master pages. When visitors views a page, I'd like to show the date and time the child page was last updated. I'd also like to do this all at the master page level so no code for getting this information needs to be added to each child page.
Is this possible? what would be the best way to do it?
Thank you in advanced!
Page.Request.PhysicalPath will give you the physical path of the page.
And the FileInfo class can be used to get its last update date.
There are caveats if you are redirecting using Server.Execute or Server.Transfer, in which case there are several alternative ways of doing this, including the one described in the Remarks section of the MSDN documentation for HttpRequest.PhysicalPath.
Typically, this is what I put in my *_master.vb code-behind files. And I use a base MainMaster.vb class with the Public LastUpdate As DateTimeproperty.
Protected Overrides Sub OnLoad(e As System.EventArgs)
MyBase.OnLoad(e)
Dim fi As System.IO.FileInfo = New System.IO.FileInfo(Page.Request.PhysicalPath)
LastUpdate = fi.LastWriteTime
label_lastUpdate.Text = String.Format("{0} à {1}", LastUpdate.ToLongDateString(), LastUpdate.ToLongTimeString())
End Sub

Showing 1:N and M:N relationships with Symfony 1.2.9 admin generator

I am using Symfony 1.2.9 (with Propel ORM) to create a website. I have started using the admin generator to implement the admin functionality. I am having all manner of problems getting the admin manager to display an object (blog) that has one 1:N relation (blogposts) and one N:M relationship (blogroll).
This is proving to be far more difficult than I had ever imagined (and I daresay, than it needs to be). I have already spent two days on this problem and have not made much progress. I am trying to generate admin functionality for a blog.
I have posted an abridged version of my schema here. Hopefully it will help clarify the problem I am having (maybe I am not explaining the problem clearly enough - but hopefully, the schema should clarify the problem I am facing, and what I'm trying to do).
A blog has 0 to 1 blog rolls, 0 to N blog posts attached to it. Each blog post has 0 to M comments attached to it. Currently, I can view a list of blogs. But I want to add 2 interactions (or links) that can make me:
view the blogroll (which is a list of blogs attached to the blog)
view the list of blogposts attached to a blog.
When a blogpost list is shown, I want link to show a link (same functionality as before), that allows me to show the list of comments for the selected blogpost.
I am sure I am not the first (or only) person that has tried to do this before. Am I going about it the wrong way, is there a better (i.e. more intuitie for the user) way of displaying and performing CRUD on objects with such relationships?. Can anyone out there help?
Why don't you do it as you have proposed by yourself in your other question.
(This is again for Doctrine but for Propel it should be similar).
Create an object action in your generator.yml:
list:
object_actions:
bloglist: {label: Bloglist}
Then in your actions.class.php you have to add a function:
public function executeListBloglist(sfWebRequest $request) {
$blog = $this->getRoute()->getObject();
// retrieve the blogposts via a PEER method (I don't have any clue about Propel ;))
$this->blogposts = however.you.get.the.blogposts();
}
Then create a template bloglistSuccess.php where you show the posts.
Or, you can redirect or forward to the admin module for the blogposts if you have such a module. There you have probably to override the list action to accept the ID parameter of the blog and extend the query to filter posts by this blog id.
There is nothing wrong in doing a redirect or forward, it is not a hack ;)
Edit after comment:
I would also suggest that you forward the request.
No you don't have to change the routing you can just append the parameter like you suggested.
For overriding I reconsidered that it would be better if you override the buildQuery method (again). (I can't remember how this method was called with Propel, I hope you get what I mean).
So it would look like this:
class blogpostAdminActions extends autoBlogpostAdminActions
{
//...
protected function buildQuery()
{
$query = parent::buildQuery();
$request = $this->getRequest(); // <- I am not sure about this method call but there is one that gives you the webRequest.
if ($request->hasParamter('blog_id'))
{
$query->andWhere('blog_id = ?', $request->getParameter('blog_id'));
}
return $query;
}
}
Of course you have to change this to Propel criteria, but I assume you can do that ;)
Hope this helps you.

Resources