MONI.Data.WorkYear.GetPositionHitlistAsync C# (CSharp) Method

GetPositionHitlistAsync() private static method

private static GetPositionHitlistAsync ( IEnumerable months, int lookBackInWeeks, PositionSearchViewModel posSearchViewModel ) : Task>
months IEnumerable
lookBackInWeeks int
posSearchViewModel MONI.ViewModels.PositionSearchViewModel
return Task>
        private static async Task<IEnumerable<HitlistInfo>> GetPositionHitlistAsync(IEnumerable<WorkMonth> months, int lookBackInWeeks, PositionSearchViewModel posSearchViewModel)
        {
            return await Task.Factory.StartNew(() => {
                if (posSearchViewModel != null)
                {
                    var allDays = months.SelectMany(m => m.Days);
                    var daysFromLookback = lookBackInWeeks > 0 ? allDays.Where(m => m.DateTime > DateTime.Now.AddDays(lookBackInWeeks * -7)) : allDays;
                    var hitlistInfos = daysFromLookback
                        .SelectMany(d => d.Items)
                        .GroupBy(p => p.Position)
                        .Select(g =>
                            new HitlistInfo(
                                g.Key,
                                g.Count(),
                                g.Sum(wi => wi.HoursDuration),
                                posSearchViewModel.GetDescriptionForPositionNumber(g.Key))
                        );
                    return hitlistInfos.OrderByDescending(g => g.HoursUsed);
                }
                else
                {
                    return Enumerable.Empty<HitlistInfo>();
                }
            });
        }