Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Aug 24, 2011 @ 20:17
    Bjarne Fyrstenborg
    0

    Show/hide button if member is/is not related to event

    Hi..

    I have a event signup, where members are able to signup for events, where I have used the code from this video: http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco/relations/event-signup-with-relations

    I am able to hide one of the buttons (coming and clear) when the member click on one of the buttons.

    protected void setStatus(object sender, CommandEventArgs e)
            {
                Node n = Node.GetCurrent();
                Member m = Member.GetCurrentMember();
    
                clear.Visible = true;
                coming.Visible = false;
    
                if (e.CommandArgument == "coming")
                {
                    Helper.RelateMemberToEvent(m.Id, n.Id, m.Text + " can come to " + n.Name);
                    EventStatuslbl.Text = "Du er nu tilmeldt eventen.";
                }
                else
                {
                    Helper.DeclineComingToEvent(m.Id, n.Id, m.Text + " declined coming to " + n.Name);
                }
            }
    
            protected void clearRelations(object sender, EventArgs e)
            {
                Node n = Node.GetCurrent();
                Member m = Member.GetCurrentMember();
    
                clear.Visible = false;
                coming.Visible = true;
    
                Helper.ClearRelations(m.Id, n.Id);
                EventStatuslbl.Text = "Du er nu fjernet fra eventen.";
            }

    I also want that the clear button isn't visible if the member isn't related to the event... and the coming button isn't visible if the member already is signed up for the event.

    Just like I have when the member click on one of the buttons and a message is shown in the label EventStatuslbl.
    So I need somehow on page load to get if the member is signed up or not.

    Bjarne

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Aug 25, 2011 @ 18:37
    Bo Damgaard Mortensen
    0

    Hi Bjarne,

    Not sure here for the given situation, but maybe you can use the Relation.IsRelated() method to see if the current member is related to a specific event? :-)

    - Bo

    Taken from Hendy Rachers blog: bool isRelated = Relation.IsRelated(document.Id, member.Id, RelationType);

     

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Aug 25, 2011 @ 18:43
    Bjarne Fyrstenborg
    0

    Hi Bo

    Yes, I have thought about something like that.. and create a function that should run on page load.

    It has a Helper class that perhaps can be used to get if a member is related or not... I'm not sure how and where to write this..

    Bjarne

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Aug 26, 2011 @ 16:33
    Bjarne Fyrstenborg
    0

    I have tried with this:

    private void LoadStatus(int eventId, int memberId)
            {
                if (!Relation.IsRelated(eventId, memberId))
                {
                    clear.Visible = false;
                    coming.Visible = true;
                }
                else
                {
                    clear.Visible = true;
                    coming.Visible = false;
                }
            }

    and then in pageload:

    protected void Page_Load(object sender, EventArgs e)
            {
                LoadStatus();
            }

    but there in something wrong or missing.. I have tried with LoadStatus(eventId, memberId); and LoadStatus(int eventId, int memberId); as well, but still marks it as an error..

    Bjarne

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Aug 26, 2011 @ 20:46
    Bo Damgaard Mortensen
    0

    Hi Bjarne,

    What does the error tell you? :-) 

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Aug 26, 2011 @ 21:00
    Bjarne Fyrstenborg
    0

    Well, I think it's because the LoadStatus function need eventId and memberId.. but when a use them.. they are not defined in that codebehind.. but in the Helper.cs file..

    LoadStatus()  <--- No overload for method 'LoadStatus' takes 0 arguments
    LoadStatus(eventId, memberId) <--- The 'eventId' does not exist in the current context (the same with memberId)

    In the Helper class is has:

    public static void RelateMemberToEvent(int memberId, int eventId, string comment)
            {
                if (!Relation.IsRelated(eventId, memberId))
                {
                    RelationType rt = RelationType.GetByAlias(_coming);
                    Relation.MakeNew(eventId, memberId, rt, comment);
                }
            }

    Where in relate the member to the event if the member isn't already related.

    Bjarne 

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Sep 27, 2011 @ 10:39
    Bjarne Fyrstenborg
    0

    I have seen some places to check of a member is related, e.g. here: http://blog.hendyracher.co.uk/umbraco-relation-api/

    How can I use this in page load method? so when the page is loaded it has hidden a button if the member in related to the event... if not it shows the button..

    Bjarne

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Oct 09, 2011 @ 14:55
    Bjarne Fyrstenborg
    0

    Anyone who knows how I can use the Relation.IsRelated to check if a event/node and member is related on page load? and the do something if it's related.. e.g. displays a message in a label.

    Bjarne 

Please Sign in or register to post replies

Write your reply to:

Draft