示例#1
0
        public ActionResult Index(User currentUser, int year, int month)
        {
            Require.NotNull(currentUser, "currentUser");
            Require.Ge(year, 2000, "year");
            Require.Ge(month, 1, "month");
            Require.Le(month, 12, "month");

            DateTime firstDayOfMonth = new DateTime(year, month, 1);
            /*Ab Montag der Woche des ersten Tages des Monats.*/
            DateTime from = firstDayOfMonth.GetFirstDayOfWeek();
            /*Bis Sonntag der Woche des letzten Tages Monats*/
            DateTime to = firstDayOfMonth
                          .AddMonths(1)        // 1. des nächsten Monats
                          .AddDays(-1)         // letzter des aktuellen Monats
                          .GetFirstDayOfWeek() // Montag der letzten Woche
                          .AddDays(6);         // Sonntag der letzten Woche

            IPage <PeanutParticipation> peanutParticipations = PeanutService.FindParticipationsOfUser(PageRequest.All, currentUser, from, to);
            IPage <Peanut> attendablePeanuts = PeanutService.FindAttendablePeanutsForUser(PageRequest.All, currentUser, from, to);
            IDictionary <DateTime, IList <PeanutParticipation> > peanutParticipationsByDate =
                peanutParticipations.GroupBy(participation => participation.Peanut.Day)
                .ToDictionary(g => g.Key, g => (IList <PeanutParticipation>)g.ToList());
            IDictionary <DateTime, IList <Peanut> > attendablePeanutsByDate = attendablePeanuts.GroupBy(peanut => peanut.Day)
                                                                              .ToDictionary(g => g.Key, g => (IList <Peanut>)g.ToList());

            return(View("Index", new PeanutsIndexViewModel(year, month, peanutParticipationsByDate, attendablePeanutsByDate)));
        }
示例#2
0
        public ActionResult Day(int year, int month, int day, User currentUser)
        {
            DateTime date = new DateTime(year, month, day);

            IPage <PeanutParticipation> peanutParticipations = PeanutService.FindParticipationsOfUser(PageRequest.All, currentUser, date, date, new [] { PeanutParticipationState.Confirmed });
            IPage <Peanut> attendablePeanuts = PeanutService.FindAttendablePeanutsForUser(PageRequest.All, currentUser, date, date);

            if (peanutParticipations.TotalElements == 1 && attendablePeanuts.TotalElements == 0)
            {
                /*Wenn es an diesem Tag nur diesen einen Peanut gibt, dann diesen anzeigen*/
                return(RedirectToAction("Show", "Peanut", new { peanut = peanutParticipations.Single().Peanut.BusinessId }));
            }
            else
            {
                return(View("List", new PeanutsListViewModel(date, date, peanutParticipations.ToList(), attendablePeanuts.ToList())));
            }
        }