Copied to clipboard

Flag this post as spam?

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


  • Kasper 14 posts 49 karma points
    Apr 11, 2013 @ 10:06
    Kasper
    0

    Is it possible to somehow check if Member.AfterSave and Member.BeforeSave is triggered from back office?

    Hi All

    I am trying to send an email to a member if a true/false property is checked and saved.
    But the Member.AfterSave and Member.BeforeSave events is also triggered on the frontend of the site, when a member is registered.

    My question is, can i somehow do a check in the event, to se if the event is called in the back office or not?
    Or is there anotther way to only bind som code to the save member event in the back office.

    Hope you guys can help me with this, before i go totally crazy :)

    Best regards
    Kasper

    Code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.web;
    using umbraco.cms.businesslogic.property;
    using umbraco.cms.businesslogic.member;

    namespace umbracoExtensions.classes
    {
    public class AppBase : umbraco.BusinessLogic.ApplicationBase
    {
    public bool member_isApprovedBeforeValue = false;
    public AppBase()
    {
    Member.AfterSave += new Member.SaveEventHandler(Member_AfterSave);
    Member.BeforeSave += new Member.SaveEventHandler(Member_BeforeSave);
    }

    void Member_BeforeSave(Member sender, SaveEventArgs e)
    {
    if (Convert.ToBoolean(sender.getProperty("member_isApproved").Value))
    {
    member_isApprovedBeforeValue = true;
    }
    }

    void Member_AfterSave(Member sender, SaveEventArgs e)
    {
    bool member_isApproved = Convert.ToBoolean(sender.getProperty("member_isApproved").Value);
    SendMail mail = new SendMail();
    if (member_isApproved == true && member_isApprovedBeforeValue == false)
    {
    // User activated - Send mail
    mail.sendmailToUser(1183, sender);
    }

    if (member_isApproved == false && member_isApprovedBeforeValue == true)
    {
    // User deactivated - Send mail
    mail.sendmailToUser(1184, sender);
    }


    }

    }


    }

  • Kasper 14 posts 49 karma points
    Apr 11, 2013 @ 13:31
    Kasper
    0

    Made a work around, not pretty but i works for me.. Anyone ho has a better solution is very welcome to post it :)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.web;
    using umbraco.cms.businesslogic.property;
    using umbraco.cms.businesslogic.member;
    using umbraco.NodeFactory;

    namespace Janoos_umbracoExtensions.classes
    {
    public class AppBase : umbraco.BusinessLogic.ApplicationBase
    {
    public static bool member_isApprovedBeforeValue = false;
    public AppBase()
    {
    Member.AfterSave += new Member.SaveEventHandler(Member_AfterSave);
    }

    void Member_AfterSave(Member sender, SaveEventArgs e)
    {

    string currentUrl = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;

    Uri uri = new Uri(currentUrl);
    string filename = System.IO.Path.GetFileName(uri.LocalPath);

    if (filename=="editMember.aspx")
    {

    //Filename of the edit page in umbraco backoffice #DO NOT USE THE SAME PAGE NAME TO EDIT A MEMBER IN FRONTEND#

    }



    }

    }


    }

  • keilo 568 posts 1023 karma points
    Oct 05, 2015 @ 06:07
    keilo
    0

    I know this is dated but curious what did you end up using with the AfterSave event handler to send member confirm. email?

Please Sign in or register to post replies

Write your reply to:

Draft