Exemple #1
0
        public void OnGet(string date)
        {
            DateTime dt;

            if (date == null ||
                !DateTime.TryParse(date, out dt))
            {
                this.RollCallOptions = this._rollCallService.GetRollCallOptions(
                    DateTime.Now.Date);
            }
            else
            {
                this.RollCallOptions = this._rollCallService.GetRollCallOptions(
                    dt);
            }
        }
        public RollCallOptions GetRollCallOptions(DateTime date)
        {
            var result = new RollCallOptions();

            result.Date = date;

            var people = this._personRepository.GetAll();

            if (people == null)
            {
                throw new Exception("Could not fetch people for roll call");
            }

            var rollCallPeople =
                people.Where(p => p.Presences != null).Select(p =>
                                                              new
            {
                Person        = p,
                PresenceEntry = p.Presences.FirstOrDefault(presence =>
                                                           presence.Called && presence.Date == date &&
                                                           p.PlaceOfConvocation != null)
            })
                .Where(o => o.PresenceEntry != null)
                .ToList();
            var options = rollCallPeople.GroupBy(o => o.Person.PlaceOfConvocation)
                          .Select(g => new RollCallOption
            {
                PlaceOfEntry = g.Key
            }).ToList();

            foreach (var opt in options)
            {
                opt.RollCallLink = "/RollCall?date=" +
                                   result.Date.ToString("yyyy-MM-dd") +
                                   "&placeOfEntry=" + opt.PlaceOfEntry;
            }

            result.Options = options;

            return(result);
        }