Esempio n. 1
0
        private void BuildEvents()
        {
            var currentDate = new DateTime(2016, 05, 06);
            var endDate = new DateTime(2016, 09, 09);
            var index = 0;
            while (currentDate < endDate)
            {
                var ev = new Event
                {
                    Date = currentDate,
                    EventNumber = index,
                    NextEvent = index == 0,
                    WasCanceled = false,
                };

                _session.Add(ev);
                _session.Commit();

                currentDate = currentDate.AddDays(7);
                index++;
            }
        }
Esempio n. 2
0
        private StatsViewModel GetStats(Event data)
        {
            var catAvail = _session.Set<Year>()
                .Where(x => x.Current)
                .SelectMany(x => x.PlayableCategories)
                .ToList();

            var categories = new List<CatStatsViewModel>();
            foreach (var category in catAvail)
            {
                var count = data.Attendees.Count(x => x.Categories.Select(y => y.Id).Contains(category.Id));
                var catdata = new CatStatsViewModel
                {
                    name = category.Name,
                    count = count,
                    percentage = ((int)count / data.Attendees.Count) * 100
                };

                categories.Add(catdata);
            }

            var model = new StatsViewModel
            {
                eventNumber = data.EventNumber,
                attendees = data.Attendees.Count,
                ageAvg = data.Attendees
                    .Where(x => x.Player.DateOfBirth.HasValue)
                    .Select(x => x.Player.DateOfBirth.Value.AsAge())
                    .Average(),

                categories = categories,
            };

            return model;
        }