I work with a nurse calendar, which consists of Shifts:
public interface IShift { ShiftType ShiftType { get; } //enum {Day, Early, Late, Night} DateTime Day { get; } bool IsNightShift(); bool IsWeekendShift(); }
Nursing Calendar IEnumerable<IShift> . From this, I select my own shifts ( IEnumerable<IShift> selectedShifts ) for a shorter period of time to check for some limitations.
I am trying to calculate several conditions, for example, Night Shifts on Friday:
var countFridayNight = selectedShifts.Count(s => s.IsNightShift() && s.Day.DayOfWeek == DayOfWeek.Friday);
What I'm struggling with is counting a few things a few days. For example, late shift on Friday and early shift next Monday. I tried this, but VS doesn't look like syntax:
var countFridayLateAndMondayEarly = selectedShifts.Count( (r, s) => s.ShiftType == ShiftType.Late && s.Day.DayOfWeek == DayOfWeek.Friday && r.Day.DayOfWeek == DayOfWeek.Monday && r.Day.AddDays(-2).DayOfYear == s.Day.DayOfYear && r.ShiftType == ShiftType.Early );
Edit: Removed curly braces in the last lambda expression.
Edit2: There were two comments saying that a graph cannot accept more than one variable inside a lambda expression. How else can I do what I need to use LINQ?
Edit3: Clarification of the problem - I need to count the shifts, which are late shifts on Friday, and at the same time there is another shift, which is at the beginning of next Monday.
c # lambda linq
Dracke
source share