private void PopulateMonthVM(MonthVM monthVM, int month, int year, Int64? shiftId, string name, out int totalCovers, out int totalParty) { totalCovers = 0; totalParty = 0; monthVM.Week1 = new List<wDay>(); monthVM.Week2 = new List<wDay>(); monthVM.Week3 = new List<wDay>(); monthVM.Week4 = new List<wDay>(); monthVM.Week5 = new List<wDay>(); monthVM.Week6 = new List<wDay>(); List<DateTime> dt = new List<DateTime>(); dt = GetDates(year, month); foreach (DateTime d in dt) { var resForDay = db.GetReservationByDate(d); var wday = new wDay() { day = d, Reservations = new List<Reservation>() }; if (shiftId.HasValue && shiftId.Value > 0) resForDay = resForDay.Where(r => r.FoodMenuShiftId == shiftId).ToList(); if (!string.IsNullOrEmpty(name)) { name = name.Trim().ToLower(); long pnum = 0; if (long.TryParse(name, out pnum)) { resForDay = resForDay.Where(r => r.Customers.PhoneNumbers.Any(pn => pn.PhoneNumbers.ToLower().Contains(name))).ToList(); } else { resForDay = resForDay.Where(r => r.Customers.FirstName.ToLower().Contains(name) || r.Customers.LastName.ToLower().Contains(name)).ToList(); } } resForDay = resForDay.OrderBy(r => r.TimeForm).ToList(); wday.Reservations.AddRange(resForDay ?? new List<Reservation>()); totalCovers = totalCovers + wday.Reservations.Sum(r => r.Covers); totalParty = totalParty + wday.Reservations.Count(); switch (GetWeekOfMonth(d)) { case 1: monthVM.Week1.Add(wday); break; case 2: monthVM.Week2.Add(wday); break; case 3: monthVM.Week3.Add(wday); break; case 4: monthVM.Week4.Add(wday); break; case 5: monthVM.Week5.Add(wday); break; case 6: monthVM.Week6.Add(wday); break; }; } while (monthVM.Week1.Count < 7) // not starting from sunday { wDay dy = null; monthVM.Week1.Insert(0, dy); } if (month == 12) { monthVM.nextMonth = (01).ToString() + "/" + (year + 1).ToString(); monthVM.prevMonth = (month - 1).ToString() + "/" + (year).ToString(); } else if (month == 1) { monthVM.nextMonth = (month + 1).ToString() + "/" + (year).ToString(); monthVM.prevMonth = (12).ToString() + "/" + (year - 1).ToString(); } else { monthVM.nextMonth = (month + 1).ToString() + "/" + (year).ToString(); monthVM.prevMonth = (month - 1).ToString() + "/" + (year).ToString(); } }
public ActionResult MonthList(int month, int year, Int64? shiftId, string name) { ViewBag.shiftId = shiftId; ViewBag.searchText = name ?? string.Empty; var monthData = new MonthVM(); int totalCovers; int totalParties; this.PopulateMonthVM(monthData, month, year, shiftId, name, out totalCovers, out totalParties); this.PopulateMonthCalenderTopOption(month, year); ViewBag.TotalCovers = totalCovers; ViewBag.TotalParties = totalParties; ViewBag.date = DateTime.UtcNow.ToDefaultTimeZone(User.Identity.GetDatabaseName()).Date; return PartialView(monthData); }