public static ProfileResponseModel Profile(AppUser user, IEnumerable <Entities.Activity> activities) { IEnumerable <SeasonSummaryModel> getSeasons() { var seasons = activities .Where(a => a.StartDateTime > DateTimeOffset.MinValue) .GroupBy(a => Season.FromDate(a.StartDateTime)) .OrderByDescending(s => s.Key) .Select(s => SeasonSummary(s.Key.Year, $"{s.Key.Name} Season", s.ToList())) .ToList(); return(seasons.Count > 1 ? seasons.Append(SeasonSummary(null, "All Time", activities)) : seasons); } return(new ProfileResponseModel { UserId = user.UserId, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Gender = user.Gender, City = user.City, Region = user.Region, Country = user.Country, PhotoUrl = user.PhotoUrl, DefaultActivityType = ((ActivityTypeEnum)(user.DefaultActivityTypeId ?? (byte)ActivityTypeEnum.Ski)).ToString(), Seasons = getSeasons().ToList() }); }