Skip to content

Instantly share code, notes, and snippets.

@alfeg
Created April 23, 2012 15:12
Show Gist options
  • Save alfeg/2471531 to your computer and use it in GitHub Desktop.
Save alfeg/2471531 to your computer and use it in GitHub Desktop.
protected static bool IsListSuitableForSimpleAdmin(IList<Record> records)
{
bool returnValue = false;
if (records != null)
{
int sundayCount = 0;
int mondayCount = 0;
int tuesdayCount = 0;
int wednesdayCount = 0;
int thursdayCount = 0;
int fridayCount = 0;
int saturdayCount = 0;
foreach (Record in records)
{
switch (record.DayOfWeek)
{
case DayOfWeek.Sunday:
sundayCount++;
break;
case DayOfWeek.Monday:
mondayCount++;
break;
case DayOfWeek.Tuesday:
tuesdayCount++;
break;
case DayOfWeek.Wednesday:
wednesdayCount++;
break;
case DayOfWeek.Thursday:
thursdayCount++;
break;
case DayOfWeek.Friday:
fridayCount++;
break;
case DayOfWeek.Saturday:
saturdayCount++;
break;
}
}
returnValue = (sundayCount == 1 &
mondayCount == 1 &
tuesdayCount == 1 &
wednesdayCount == 1 &
thursdayCount == 1 &
fridayCount == 1 &
saturdayCount == 1);
}
return returnValue;
}
protected static bool IsListSuitableForSimpleAdmin(IList<Record> records)
{
var byDayCounts = (records ?? Enumerable.Empty<Record>())
.GroupBy(record => record.DayOfWeek)
.Select(byDays => byDays.Count())
.ToList();
return byDayCounts.All(count => count == 1) && byDayCounts.Count == 7;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment