HELLLP!!...Display Values from Child Pages by Week and Year
Hi Guys,
Looking for some guru level help here.
I have a friends fishing website which has a list of child pages with some data I wish to loop through and display in a table. I wish to show the total number of fish caught by Week Number and Year. I have attached an image below to show what I'm trying to acheive.
Each child page has a date the catch was posted and a textbox with the total number of fish caught.
Here is the code I have written so far which I think I can get the current weeks total but not all the weeks from the total child pages, I appreciate this is probably wrong but any help or pointers in the right direction would be good.
var latestCatches = Umbraco.Content(1157);
var currentYear = DateTime.Now.Year;
var culture = CultureInfo.GetCultureInfo("en-GB");
var dateTimeInfo = DateTimeFormatInfo.GetInstance(culture);
var dateTime = DateTime.Today;
int weekNumber = culture.Calendar.GetWeekOfYear(dateTime, dateTimeInfo.CalendarWeekRule, dateTimeInfo.FirstDayOfWeek);
int WeeklyCatchTotal = 0;
DateTime startOfWeek = DateTime.Today;
int delta = DayOfWeek.Monday - startOfWeek.DayOfWeek;
startOfWeek = startOfWeek.AddDays(delta);
DateTime endOfWeek = startOfWeek.AddDays(5);
foreach (var latestCatch in latestCatches.Children.Where("catchDate >= @0", startOfWeek))
{
if (latestCatches.catchDate >= startOfWeek || latestCatches.catchDate <= endOfWeek)
{
int total = latestCatch.totalFish;
WeeklyCatchTotal = WeeklyCatchTotal + total;
}
}
<td>Week @weekNumber</td><td>@WeeklyCatchTotal</td>
Still looking for some help here, I think I need some help in how I can get the data I require to be displayed. Like I mentioned above I have a list of child pages with 2 values on each page I need to work with. One is the totalcatches value which is an Int and the other value is the date the catch was reported.
So there is a catch report for every day Monday to Saturday. So what Im trying to do is loop through all the child pages and total each catch report report by week so there is 6 reports per week.
What I want to do then is display each week number and the total catches for that week by year.
Could anyone give me a code example I could work with.
Thanks for your input. So when I use your code I only get the current week which is 38. What do I need to do to my code so it calculates all totalFish for each week i.e 1-37 and for each year.?
I have attached a screenshot below of what I want to acheive but im not sure if its possible.
When I fetch the var latestCatches = Umbraco.TypedContent(1157) it returns the 203 childpages. But how do I loop through all and add each child pages totalfish to the week it was caught.
Again I really appreciate you responding with any help you can offer.
Did you manage to get a look at my issue above when running your code? Your code works perfect but only returns the current week. Can you take a look at my last post as I try and explain what I need in more detail.
Finally managed to sort this out. Went down the route of using a Dictionary a key value pairs. Here's the code below in case anyone else needs to do something similar.
HELLLP!!...Display Values from Child Pages by Week and Year
Hi Guys,
Looking for some guru level help here.
I have a friends fishing website which has a list of child pages with some data I wish to loop through and display in a table. I wish to show the total number of fish caught by Week Number and Year. I have attached an image below to show what I'm trying to acheive.
Each child page has a date the catch was posted and a textbox with the total number of fish caught.
Here is the code I have written so far which I think I can get the current weeks total but not all the weeks from the total child pages, I appreciate this is probably wrong but any help or pointers in the right direction would be good.
}
Hi Guys,
Still looking for some help here, I think I need some help in how I can get the data I require to be displayed. Like I mentioned above I have a list of child pages with 2 values on each page I need to work with. One is the totalcatches value which is an Int and the other value is the date the catch was reported.
So there is a catch report for every day Monday to Saturday. So what Im trying to do is loop through all the child pages and total each catch report report by week so there is 6 reports per week.
What I want to do then is display each week number and the total catches for that week by year.
Could anyone give me a code example I could work with.
Kind Regards Eric
Hi Eric
I changed your code little bit, made it strongly typed, try this code:
Thanks,
Alex
Hi Alex,
Thanks for your input. So when I use your code I only get the current week which is 38. What do I need to do to my code so it calculates all totalFish for each week i.e 1-37 and for each year.?
I have attached a screenshot below of what I want to acheive but im not sure if its possible.
When I fetch the var latestCatches = Umbraco.TypedContent(1157) it returns the 203 childpages. But how do I loop through all and add each child pages totalfish to the week it was caught.
Again I really appreciate you responding with any help you can offer.
Eric
Hi Alex,
Did you manage to get a look at my issue above when running your code? Your code works perfect but only returns the current week. Can you take a look at my last post as I try and explain what I need in more detail.
Kind Regards Eric
Hi Guys,
Can anyone else help me here? Really struggling with this, just want to know if it can be done and if so a code example?
Kind Regards Eric
Hi Guys,
Finally managed to sort this out. Went down the route of using a Dictionary a key value pairs. Here's the code below in case anyone else needs to do something similar.
@using System.Globalization; @inherits umbraco.MacroEngines.DynamicNodeContext @inherits Umbraco.Web.Macros.PartialViewMacroPage
@ var latestCatches = Umbraco.Content(1157); //var currentYear = DateTime.Now.Year; var culture = CultureInfo.GetCultureInfo("en-GB"); var dateTimeInfo = DateTimeFormatInfo.GetInstance(culture); var dateTime = DateTime.Today; int weekNumber = 0; Dictionary
}
Cumbernauld Web Design
Hi Eric
Thank you for sharing with the community, nice solution!
Thanks,
Alex
is working on a reply...