Created
April 23, 2012 15:12
-
-
Save alfeg/2471531 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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