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.
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.
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> } } }
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.
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> } }
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.
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.
Please take a look a it and please help, if you can.
Thank you :-)
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 :)
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 ;-)
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.
Is birthday a property on the member?
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 :)
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.
Thank you for your help so far :-)
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 :)
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) :-)
Hope this helps a bit :-)
Thanks
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 :)
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! ;-)
Sorry we lost the foreach loop
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
}
}
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. :)
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! ;-)
Excuse ME!!!
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 :-)
Thank you a thousand times! You are one of the reasons, the umbraco community is so great! :-D
/Daniel
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 :)
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
For a speedy search, Examine is great! https://our.umbraco.org/documentation/Reference/Searching/Examine/
is working on a reply...