Exemplo n.º 1
0
 public static MvcHtmlString CondensedView(CourtScheduleViewModel cs)
 {
     string res = "<table>";
     foreach (BookingsForADay bfad in cs.bookings)
     {
         res += "<tr style='line-height:6px'>";
         foreach (BookingData bd in bfad.bookings)
         {
             if (bd.id == -1)
                 res += "<td style='background-color:lightgreen'>";
             else
                 res += "<td style='background-color:orange'>";
             res += "&nbsp;</td>";
         }
         res += "</tr>";
     }
     res += "</table>";
     return new MvcHtmlString(res);
 }
Exemplo n.º 2
0
        private const int operationEnd = 22;// opening hours = 7h00-22h00

        // GET: CourtSchedule
        public ActionResult Index(int courtid)
        {
            courts theCourt = db.courts.Find(courtid);
            
            CourtScheduleViewModel vm = new CourtScheduleViewModel();
            vm.courtName = theCourt.name;

            // Create headers
            vm.colHeaders.Add("Date");
            for (int h = operationStart; h <= operationEnd; h++) 
                vm.colHeaders.Add(string.Format("{0}:00", h));

            // Fill structure with empty bookings
            DateTime dateStart = DateTime.Now;
            for (int day = 0; day < 7; day++) // Add 7 days
            {
                BookingsForADay oneday = new BookingsForADay();
                oneday.rowHeader = string.Format("{0:dd MMM}", dateStart.AddDays(day));
                for (int h = operationStart; h <= operationEnd; h++) 
                    oneday.bookings.Add(new BookingData(-1, ""));
                vm.bookings.Add(oneday);
            }

            // place real bookings
            foreach (reservations r in theCourt.reservations)
            {
                int col = r.date.Hour - operationStart; // Column of the array
                int row = (int)(r.date - dateStart).TotalDays; // Row of the array
                if ((row >= 0) && (row < vm.bookings.Count) && (col >= 0) && (col < vm.colHeaders.Count-1)) // Just to be safe... -1 because of the row header
                {
                    vm.bookings.ElementAt(row).bookings.ElementAt(col).id = r.users.idUsers;
                    vm.bookings.ElementAt(row).bookings.ElementAt(col).booker = r.users.lastname;
                }
            }
            return View(vm);
        }