I have the below DTO object/class. I have a list of dates I am cycling through for the current week. Is there a way I can cyle through this DTO?
Example. Say the date is 2/24/2013 - I would need to add the data to the list for SundayList. If the date is 2/27/2013, I would need to add the data to the list for WednesdayList. I am just not sure how to do it, since it's not an actual list. Hope my issue
make sense.
public class SearchWeekDTO
{
public List<SearchLinkDTO> SundayList { get; set; }
public List<SearchLinkDTO> MondayList { get; set; }
public List<SearchLinkDTO> TuesdayList { get; set; }
public List<SearchLinkDTO> WednesdayList { get; set; }
public List<SearchLinkDTO> ThursdayList { get; set; }
public List<SearchLinkDTO> FridayList { get; set; }
public List<SearchLinkDTO> SaturdayList { get; set; }
public int HighestCount { get; set; }
public SearchWeekDTO()
{
SundayList = new List<SearchLinkDTO>();
MondayList = new List<SearchLinkDTO>();
TuesdayList = new List<SearchLinkDTO>();
WednesdayList = new List<SearchLinkDTO>();
ThursdayList = new List<SearchLinkDTO>();
FridayList = new List<SearchLinkDTO>();
SaturdayList = new List<SearchLinkDTO>();
}
}
yes you can do that....create an instance of SearchWeekDTO, then iterate all your dates, find the day, lets say you have a sunday then instance.SundayList.Add(new SearchLinkDTO() {...properties...});
I assume the following kind of thing you want to achieve -
public void AddData(DateTime date, SearchLinkDTO dto)
{
switch (date.Day)
{
case DayOfWeek.Sunday:
AddData(SundayList, dto);
break;
case DayOfWeek.Monday:
AddData(MondayList, dto);
break;
/// So on for rest of the week days;
}
}
public void AddData(List<SearchLinkDTO> dtoList, SearchLinkDTO dto)
{
dtoList.Add(dto);
}
Correct me if i am wrong.
Please “Mark as Answer” on the reply that helps you. This will help others jump directly to a solution having similar problem.
Marked as answer by tvb2727 on Feb 25, 2013 09:41 AM
Just create a function to process all your SearchLinkDTO as below,
public void ProcessDate(List<SearchLinkDTO> list)
{
foreach (List<SearchLinkDTO> d in list) {
switch (Strings.Format(d.date, "dddd").ToLower) {
case "sunday":
SundayList.Add(d);
break;
case "monday":
MondayList.Add(d);
break;
case "tuesday":
TuesdayList.Add(d);
break;
case "wednesday":
WednesdayList.Add(d);
break;
case "thursday":
ThursdayList.Add(d);
break;
case "friday":
FridayList.Add(d);
break;
case "saturday"
SaturdayList.Add(d);
break;
}
}
}
Marked as answer by tvb2727 on Feb 25, 2013 09:41 AM
tvb2727
Participant
919 Points
1269 Posts
C# Class Object Understanding
Feb 24, 2013 08:39 PM|LINK
I have the below DTO object/class. I have a list of dates I am cycling through for the current week. Is there a way I can cyle through this DTO?
Example. Say the date is 2/24/2013 - I would need to add the data to the list for SundayList. If the date is 2/27/2013, I would need to add the data to the list for WednesdayList. I am just not sure how to do it, since it's not an actual list. Hope my issue make sense.
public class SearchWeekDTO { public List<SearchLinkDTO> SundayList { get; set; } public List<SearchLinkDTO> MondayList { get; set; } public List<SearchLinkDTO> TuesdayList { get; set; } public List<SearchLinkDTO> WednesdayList { get; set; } public List<SearchLinkDTO> ThursdayList { get; set; } public List<SearchLinkDTO> FridayList { get; set; } public List<SearchLinkDTO> SaturdayList { get; set; } public int HighestCount { get; set; } public SearchWeekDTO() { SundayList = new List<SearchLinkDTO>(); MondayList = new List<SearchLinkDTO>(); TuesdayList = new List<SearchLinkDTO>(); WednesdayList = new List<SearchLinkDTO>(); ThursdayList = new List<SearchLinkDTO>(); FridayList = new List<SearchLinkDTO>(); SaturdayList = new List<SearchLinkDTO>(); } }ramiramilu
All-Star
95295 Points
14072 Posts
Re: C# Class Object Understanding
Feb 25, 2013 08:09 AM|LINK
yes you can do that....create an instance of SearchWeekDTO, then iterate all your dates, find the day, lets say you have a sunday then instance.SundayList.Add(new SearchLinkDTO() {...properties...});
thanks,
JumpStart
Pankaj.Sharm...
Contributor
2350 Points
387 Posts
Re: C# Class Object Understanding
Feb 25, 2013 08:16 AM|LINK
I assume the following kind of thing you want to achieve -
public void AddData(DateTime date, SearchLinkDTO dto) { switch (date.Day) { case DayOfWeek.Sunday: AddData(SundayList, dto); break; case DayOfWeek.Monday: AddData(MondayList, dto); break; /// So on for rest of the week days; } } public void AddData(List<SearchLinkDTO> dtoList, SearchLinkDTO dto) { dtoList.Add(dto); }Correct me if i am wrong.
prabu.raveen...
Contributor
5020 Points
955 Posts
Re: C# Class Object Understanding
Feb 25, 2013 08:21 AM|LINK
Just create a function to process all your SearchLinkDTO as below,
public void ProcessDate(List<SearchLinkDTO> list)
{
foreach (List<SearchLinkDTO> d in list) {
switch (Strings.Format(d.date, "dddd").ToLower) {
case "sunday":
SundayList.Add(d);
break;
case "monday":
MondayList.Add(d);
break;
case "tuesday":
TuesdayList.Add(d);
break;
case "wednesday":
WednesdayList.Add(d);
break;
case "thursday":
ThursdayList.Add(d);
break;
case "friday":
FridayList.Add(d);
break;
case "saturday"
SaturdayList.Add(d);
break;
}
}
}