Example #1
0
        public ViewResult ActivityIndex(string searchString)
        {
            var activities = _activityManager.GetAllActivitiesWithSessions();

            if (!string.IsNullOrEmpty(searchString))
            {
                activities = activities.Where(s => s.Name.ToLower().Contains(searchString.ToLower()));
            }

            var result = new IndexActivityViewModel()
            {
                Activities = new List <ActivityWithCountOfSessions>()
            };

            foreach (var activity in activities)
            {
                result.Activities.Add(new ActivityWithCountOfSessions
                {
                    ActivityId   = activity.Id,
                    Name         = activity.Name,
                    SessionCount = activity.Sessions.Count
                });
            }

            return(View(result));
        }