Copied to clipboard

Flag this post as spam?

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


  • Daniel Larsen 116 posts 381 karma points
    May 08, 2013 @ 20:13
    Daniel Larsen
    0

    Member birthday

    Hi, I am trying to make a birthday module, where you can see, if it is any of the members birthday today. I am trying to do something like this, but it is not working. It should not show anything, if there is no birthday.

    @{
    var today = DateTime.Now.ToString("d. MMMM yyyy");
    var members = Member.GetAll.Where("Birthday == today");  

    foreach (var item in members) { <li>
    <p>Wohoo! There is a birthday today. Who can it be?</p>
    </li>
    }
    }

    Please take a look a it and please help, if you can.

    Thank you :-)

  • Charles Afford 1163 posts 1709 karma points
    May 09, 2013 @ 21:19
    Charles Afford
    0

    What version of umbraco are you using?  The Umbraco now uses ASP.Membership provider.  This will point you in the right direction :). http://charlesafford.com/post/2012/10/15/Umbraco-members-and-ASPnet-membership-provider

    If you need any other help, just ask.  Charlie :)

  • Daniel Larsen 116 posts 381 karma points
    May 13, 2013 @ 11:05
    Daniel Larsen
    0

    It really did not help me much, but thank you :-)

    I know how to get the different properties, with help from this post: http://our.umbraco.org/forum/developers/razor/31571-Display-Member-Name

    I was wondering, if I could make a where sort, where it only showes the members, who has a birthday today?

    This is part of a school project, where we are making an intranet, so bear with me. I am not that skilled ;-)

  • Charles Afford 1163 posts 1709 karma points
    May 14, 2013 @ 21:08
    Charles Afford
    0

    Hi, if you could tell me what version are umbraco you are using that would help.  That post will work but is now done diffrently in version 4 (which is why i pointed you to my post).  What code are you using? c#? razor?  Are you using webforms or mvc?  

    Sure its possible.  If you could let me see some code then i can help :).  Charlie.

  • Charles Afford 1163 posts 1709 karma points
    May 14, 2013 @ 21:16
    Charles Afford
    0

    Is birthday a property on the member?

  • Charles Afford 1163 posts 1709 karma points
    May 14, 2013 @ 21:18
    Charles Afford
    0

    It will be something like this:

     foreach (umbraco.cms.businesslogic.member.Member Member in umbraco.cms.businesslogic.member.Member.GetAllAsList())

                    {

                        DateTime birthday = (DateTime)Member.getProperty("birthday").Value;

                        if (birthday == DateTime.Today)

                        {

                            "YOU HAVE A BIRTHDAY";

                        }

                    }

    You will have to make sure that the property is returning a DateTime :)

  • Daniel Larsen 116 posts 381 karma points
    May 15, 2013 @ 14:06
    Daniel Larsen
    0

    I am using v4.11.4 and using Razor, hence the Razor forum ;-)

    It didn't like your code, so i modified it a bit. Now umbraco is not complaining, but looking at the site, i get the error: Error loading MacroEngine script...
    The empBirth is the birthday property and it is a date picker for the member. 

     

    @{
    foreach (umbraco.cms.businesslogic.member.Member Member in umbraco.cms.businesslogic.member.Member.GetAllAsList())
    {
    DateTime birthday = (DateTime)Member.getProperty("empBirth").Value;
    if (birthday == DateTime.Today)
    {
       <p>There is a birthday!</p>
    }
    }
    }

    Thank you for your help so far :-)

     

  • Charles Afford 1163 posts 1709 karma points
    May 15, 2013 @ 15:43
    Charles Afford
    0

    Hi,

    Can you debug?  Have you go a member and can you access the properties on the member.  I dont think you can access custom proprties (which is why i reffered you to my post)

    Nothing code wise looks wrong.

    You want to do a null check on the member and check that its not you casting the object to a datetime causing the issue.

    Charlie :)

  • Daniel Larsen 116 posts 381 karma points
    May 16, 2013 @ 13:27
    Daniel Larsen
    0

    How should I debug it? Yes, I have multiple members and i can access all of their custom properties. I have made a members list too, so no problem there. See the sample of my code here, where I get and format the birthday (empBirth) :-)

     

    @using umbraco.cms.businesslogic.member
    @{
    var members = Member.GetAll;  
    foreach (var item in members) {
    @*Get and format birth date*@
    var birth = item.getProperty("empBirth").Value;
    birth = string.Format("{0:d. MMMM yyyy}", @birth); 
    <p>@birth</p>
    }
    }

    Hope this helps a bit :-)

    Thanks

     

  • Charles Afford 1163 posts 1709 karma points
    May 16, 2013 @ 14:25
    Charles Afford
    1

    Hi it does.  Right have tried this on my local machine.

      IEnumerable<umbraco.cms.businesslogic.member.Member> member = umbraco.cms.businesslogic.member.Member.GetAllAsList(); // Get an Ienum

      {

    string birthday = umbraco.library.FormatDateTime(currentmembers.getProperty("empBirth").Value.ToString(), "M/d/yyyy");  //Get short date string

             string datetoday = DateTime.Today.ToShortDateString();  // these date formats are now the same and can match 5/6/2013 ect

                        if (DateTime.Today.ToShortDateString() == birthday) // if there is a match then

                        {

                        <p>Birthday: @birthday</p> // do something

                        }

                    }

     

    Hope this helps :)

  • Daniel Larsen 116 posts 381 karma points
    May 16, 2013 @ 16:28
    Daniel Larsen
    0

    I think you almost made it! It is complaining about this: The name 'currentmembers' does not exist in the current context

    Is some of your code missing? :-)

    Thank you for you excelent guidance good sir! ;-)

  • Charles Afford 1163 posts 1709 karma points
    May 16, 2013 @ 16:33
    Charles Afford
    0

    Sorry we lost the foreach loop

  • Charles Afford 1163 posts 1709 karma points
    May 16, 2013 @ 16:36
    Charles Afford
    100

     IEnumerable<umbraco.cms.businesslogic.member.Member> members = umbraco.cms.businesslogic.member.Member.GetAllAsList();  // Get an Ienum

    foreach (umbraco.cms.businesslogic.member.Member currentmembers in members) {

      {

    string birthday = umbraco.library.FormatDateTime(currentmembers.getProperty("empBirth").Value.ToString(), "M/d/yyyy");  //Get short date string

             string datetoday = DateTime.Today.ToShortDateString();  // these date formats are now the same and can match 5/6/2013 ect

                        if (DateTime.Today.ToShortDateString() == birthday) // if there is a match then

                        {

                       

    Birthday: @birthday

    // do something

                        }

                    }


     

  • Charles Afford 1163 posts 1709 karma points
    May 16, 2013 @ 16:41
    Charles Afford
    0

    All that is happening is you are:

    getting all members in a list

    Moving through the list

    getting the members date of birth property and coverting it to a string in a date format

    getting the current date in the same format

    comparing the dates

    rendering the result

    Hope that helped 

    Charlie. :)

  • Daniel Larsen 116 posts 381 karma points
    May 16, 2013 @ 16:47
    Daniel Larsen
    0

    Haha it works now, with one exception! It will only show the birthday of a new born baby xD

    Do you have a quick fix for that? :-)

    But thank you for the help. Much appreciated! ;-)

  • Charles Afford 1163 posts 1709 karma points
    May 16, 2013 @ 16:49
    Charles Afford
    0

    Excuse ME!!!

  • Daniel Larsen 116 posts 381 karma points
    May 16, 2013 @ 17:10
    Daniel Larsen
    0

    Sorry. If I offended you in any way, I am sorry. That was not my intention at all. :-/

    I am very glad for your help and you have helpede much further, than I would ever have on my own. You (razor) rock! :-D

    I fixed the little glitch here :-)

    @{
    IEnumerable<umbraco.cms.businesslogic.member.Member> members = umbraco.cms.businesslogic.member.Member.GetAllAsList();
    {
    foreach (umbraco.cms.businesslogic.member.Member currentmembers in members) 
    {
    string birthday = umbraco.library.FormatDateTime(currentmembers.getProperty("empBirth").Value.ToString(), "d/M");
    @*string datetoday = DateTime.Today.ToString("d/M");*@

    if (DateTime.Today.ToString("d/M") == birthday)
    {
    <p>Birthday: @birthday</p>
    }
    }
    }
    }

    Thank you a thousand times! You are one of the reasons, the umbraco community is so great! :-D

    /Daniel

  • Charles Afford 1163 posts 1709 karma points
    May 16, 2013 @ 17:22
    Charles Afford
    1

    No problem :) Glad you got it fixed.  Yea you will need to do some modfication but really glad you got i fixed.  Any time :).  Charlie :)

  • aaeda 117 posts 150 karma points
    Feb 04, 2016 @ 14:12
    aaeda
    0

    Hello

    I am also trying yo do the same thing, that is display birthday. But the main issue that I am having is that the page is taking ages to load. The way I am doing it is looping through all members (I have around 2000), then comparing the dates and displaying.

    Any idea how it can be done to load more quickly?

    Thanks Regards Aaeda

  • Daniel 60 posts 174 karma points
    Feb 05, 2016 @ 00:23
Please Sign in or register to post replies

Write your reply to:

Draft