Esempio n. 1
0
        public ActionResult History()
        {
            var db = new HockeySignupsDb(Properties.Settings.Default.ConStr);
            IEnumerable <Event> events = db.GetEvents();
            //longer approach
            HistoryViewModel vm = new HistoryViewModel();

            //List<EventWithCount> eventsWithCounts = new List<EventWithCount>();
            //foreach (Event e in events)
            //{
            //    EventWithCount eventWithCount = new EventWithCount();
            //    eventWithCount.Event = e;
            //    eventWithCount.SignupCount = db.GetSignupCountForEvent(e.Id);
            //    eventsWithCounts.Add(eventWithCount);
            //}

            //vm.Events = eventsWithCounts;

            //shorter approach
            vm.Events = events.Select(e => new EventWithCount
            {
                Event       = e,
                SignupCount = db.GetSignupCountForEvent(e.Id)
            });


            return(View(vm));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            HockeySignupsDb db = new HockeySignupsDb(Settings1.Default.ConStr);

            //var e = new Event {Date = DateTime.Today.AddDays(3), MaxPeople = 20};
            //db.AddEvent(e);
            //Console.WriteLine(e.Id);
            db.GetEvents().ToList().ForEach(e =>
            {
                Console.WriteLine(e.Date + " " + e.MaxPeople + " " + e.Id);
            });
            Console.ReadKey(true);
        }