public WTRViewModel(WTRViewModel wtrPerson, int weekNum, int year) : this() { ID = wtrPerson.ID; FirstName = wtrPerson.FirstName; LastName = wtrPerson.LastName; FactorDetails = new List <FactorData>(); foreach (var fData in wtrPerson.FactorDetails) { if (fData.WeekNumber == weekNum && fData.From.Year == year) { FactorData data = new FactorData(); data.Factor = fData.Factor; data.From = fData.From; data.To = fData.To; data.Hours = 0; data.WeekNumber = fData.WeekNumber; data.Location = fData.Location; FactorDetails.Add(data); } } SortFactorDataByStartDate(); }
public WTRViewModel(Employee employee, DateTime from, DateTime to) : this() { ID = employee.EID; FirstName = employee.FirstName; LastName = employee.LastName; FactorDetails = new List <FactorData>(); if (employee.DateDismissed != null) { DateDismissed = employee.DateDismissed.Value.ToShortDateString(); } Dictionary <int, StartEndDatePair> timeSpanDatePairDict = GetWeeksInTimeSpan(from, to); Dictionary <int, StartEndDatePair> calendarItemDatePairDict = new Dictionary <int, StartEndDatePair>(); Dictionary <int, StartEndDatePair> resultDatePairDict = new Dictionary <int, StartEndDatePair>(); foreach (var calendarItems in employee.CalendarItems.Where((f => (f.From <= from && f.To >= from) || (f.From >= from && f.From <= to)))) { calendarItemDatePairDict = GetWeeksInTimeSpan(calendarItems.From, calendarItems.To); resultDatePairDict = IntersectDatePairDicts(timeSpanDatePairDict, calendarItemDatePairDict); foreach (int week in resultDatePairDict.Keys) { FactorData data = new FactorData(); data.Factor = calendarItems.Type; data.Location = calendarItems.Location; data.From = resultDatePairDict[week].startDate; data.To = resultDatePairDict[week].endDate; data.Hours = 0; data.WeekNumber = week; FactorDetails.Add(data); } } SortFactorDataByStartDate(); }