Problems with user control Options
ChristophS
Posted: Friday, February 29, 2008 11:16:39 AM
Rank: Devotee

Joined: 2/4/2008
Posts: 38
Hi everyone,

I'm creating a user control so that when I create a page of a certain documenttype, it automatically creates a page of a documenttype as a subpage of the documenttype I just created.
E.g.: I create a page of documenttype 'Event detail' and I want the control to automatically create a page of documenttype 'Subscribe page' as a subpage of 'Event detail'.
I created a class library. This is the code:

Code:

using System;
using System.Collections.Generic;
using System.Text;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.property;
using umbraco;


namespace Subscribe_pages
{
    class Subscribe : umbraco.BusinessLogic.Actions.IActionHandler
    {
        string umbraco.BusinessLogic.Actions.IActionHandler.HandlerName()
        {
            return "Subscribe_pages.Subscribe";
        }

        umbraco.interfaces.IAction[] umbraco.BusinessLogic.Actions.IActionHandler.ReturnActions()
        {
            return new umbraco.interfaces.IAction[] { new umbraco.BusinessLogic.Actions.ActionNew() };
        }

        Boolean umbraco.BusinessLogic.Actions.IActionHandler.Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action)
        {
            if (documentObject.ContentType.Alias == "Event detail")
            {
                try
                {
                    umbraco.BusinessLogic.User u = new umbraco.BusinessLogic.User(0);
                    int parent = documentObject.Id;
                    //create subscribe page
                    DocumentType dtSubscribepage = new DocumentType(1127);
                    Document dSubscribepage = Document.MakeNew("Inschrijven", dtSubscribepage, u, parent);
                    dSubscribepage.Save();
                }
                catch (Exception)
                {
                    return false;
                }
                return true;
            }
            else
            {
                return false;
            }   
        }
    }
}


Is there something wrong with these code? Probably yes, it is a bit based on an other control I saw somewhere.
Anybody who can help me out with this one?
Thanks!
sjors
Posted: Friday, February 29, 2008 11:34:05 AM

Rank: Fanatic

Joined: 7/20/2006
Posts: 407
Location: Amsterdam
I think a action handler would be a better choice for this purpose, there is some code which does about the same by creating month/year folders for blogs created.
ChristophS
Posted: Friday, February 29, 2008 11:59:13 AM
Rank: Devotee

Joined: 2/4/2008
Posts: 38
I'm sorry, but aint this an action handler than?
Just was confused about the two terms 'user control' and 'action handler' and must have used the wrong one.
tim
Posted: Friday, February 29, 2008 12:11:21 PM

Rank: Addict

Joined: 2/19/2007
Posts: 586
Location: Belgium
Yup that would be an actionhandler.

Don't see what is wrong with your code, this is some working code of mine:

Code:


using System;
using System.Collections.Generic;
using System.Text;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.property;
using umbraco;
using System.Text.RegularExpressions;

namespace TG.Umb.ExpertSiteActionHandler
{
    class ApEsActionHandler : umbraco.BusinessLogic.Actions.IActionHandler
    {
        string umbraco.BusinessLogic.Actions.IActionHandler.HandlerName()
        {
            return "TG.Umb.ExpertSiteActionHandler.ApEsActionHandler";
        }
        umbraco.interfaces.IAction[] umbraco.BusinessLogic.Actions.IActionHandler.ReturnActions()
        {
            return new umbraco.interfaces.IAction[] { new umbraco.BusinessLogic.Actions.ActionNew() };
        }
        Boolean umbraco.BusinessLogic.Actions.IActionHandler.Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action)
        {

          
            // Als het een subsite is
            if (documentObject.ContentType.Alias == "SubSite" )
            {
                try
                {
                    umbraco.BusinessLogic.User u = new umbraco.BusinessLogic.User(0);
                    int parent = documentObject.Id;


                    string Situation = "Situering";
                    string MoreInfo = "Meer info";
                    string whois = "Wie is";
                

                    if (documentObject.Parent.Text == "fr")
                    {
                        Situation = "Apercu";
                        MoreInfo = "Plus d' infos";
                        whois = "Qui est";
                      
                    }



                    //create situation doc
                    DocumentType dtSituationPage = new DocumentType(1045);
                    Document dSituationPage = Document.MakeNew(Situation, dtSituationPage, u, parent);
                    dSituationPage.Save();

                    //create more info doc
                    DocumentType dtMoreInfoPage = new DocumentType(1047);
                    Document dMoreInfoPage = Document.MakeNew(MoreInfo, dtMoreInfoPage, u, parent);
                    
                    //create who is doc
                    DocumentType dtWhoIsPage = new DocumentType(1047);
                    Document dWhoIsPage = Document.MakeNew(whois, dtWhoIsPage, u, parent);






                }
                catch (Exception)
                {
                    return false;
                }
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}



Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
ChristophS
Posted: Friday, February 29, 2008 12:22:23 PM
Rank: Devotee

Joined: 2/4/2008
Posts: 38
Well Tim, that's exactly the code I based mine on.
But for me it doesn't make a subpage 'Subscribe page' :s.
tim
Posted: Friday, February 29, 2008 12:59:10 PM

Rank: Addict

Joined: 2/19/2007
Posts: 586
Location: Belgium
Should be a silly mistake then.

Try adding

using umbraco.BusinessLogic;

and write something to the log when the action get triggered.

Log.Add( ...


First check if the action get executed and then check if you get past the if condition ...

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
ChristophS
Posted: Monday, March 03, 2008 9:23:06 AM
Rank: Devotee

Joined: 2/4/2008
Posts: 38
It still ain't working :s.
Adding the umbraco.BusinessLogic isn't helping.
And by writing to the log, you did mean the umbracoLog in the database?
tim
Posted: Monday, March 03, 2008 12:56:01 PM

Rank: Addict

Joined: 2/19/2007
Posts: 586
Location: Belgium
Yup, to see if the actionhandlers gets executed.

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.