Exemplo n.º 1
0
        public Month GenerateCalendarData(DateTime now)
        {
            ViewBag.CurrentMonth = now.ToString("MMMM");
            ViewBag.CurrentMonthInt = now.ToString("MM");
            ViewBag.CurrentYear = now.ToString("yyyy");

            ViewBag.NextMonth = new DateTime(int.Parse(ViewBag.CurrentYear), int.Parse(ViewBag.CurrentMonthInt), 1).AddMonths(1).Month;
            ViewBag.PrevMonth = new DateTime(int.Parse(ViewBag.CurrentYear), int.Parse(ViewBag.CurrentMonthInt), 1).AddMonths(-1).Month;

            ViewBag.NextYear = new DateTime(int.Parse(ViewBag.CurrentYear), int.Parse(ViewBag.CurrentMonthInt), 1).AddMonths(1).Year;
            ViewBag.PrevYear = new DateTime(int.Parse(ViewBag.CurrentYear), int.Parse(ViewBag.CurrentMonthInt), 1).AddMonths(-1).Year;

            Week week = new Week();
            Month month = new Month(int.Parse(ViewBag.CurrentMonthInt), ViewBag.CurrentMonth, int.Parse(ViewBag.CurrentYear));

            for (int i = 1; i <= DateTime.DaysInMonth(int.Parse(ViewBag.CurrentYear), int.Parse(ViewBag.CurrentMonthInt)); i++)
            {
                DateTime dt = new DateTime(int.Parse(ViewBag.CurrentYear), int.Parse(ViewBag.CurrentMonthInt), i);
                Day day = new Day(dt);
                day.Shifts = shiftService.GetShiftForDay(day).ToList();

                week.Days.Add(day);

                if (dt.DayOfWeek == DayOfWeek.Sunday || i == DateTime.DaysInMonth(int.Parse(ViewBag.CurrentYear), int.Parse(ViewBag.CurrentMonthInt)))
                {
                    month.Weeks.Add(week);
                    week = new Week();
                }
            }

            ViewBag.WeekDayCount = 0;

            return month;
        }
Exemplo n.º 2
0
 public IEnumerable<Shift> GetShiftForMonth(Month month)
 {
     return Mapper.Map<IEnumerable<ShiftHBM>, IEnumerable<Shift>>(shiftRepository.Get().Where(s => s.ShiftDate.Month == month.MonthInt && s.ShiftDate.Year == month.Year.Name));
 }