// Run when a tile is pressed on the timetable private void Timetable_TileClicked(TimetableTile Tile) { // If the current user isn't a student and either there's no booking or the teacher owns the booking if (!CurrentUser.IsStudent && (CurrentUser.IsAdmin || Tile.Booking == null || Tile.Booking.Teacher.Id == CurrentUser.Id)) { EditBooking Window = null; // Whether this is a new booking or an edited one bool NewBooking = Tile.Booking == null; if (NewBooking) // New booking { Window = new EditBooking(CurrentUser, true, Tile.Time, Tile.Room); } else // Editing booking { Window = new EditBooking(CurrentUser, false, Tile.Booking); } Window.CurrentDate = CurrentDay; // Display the window, store the result bool?Result = Window.ShowDialog(); // If the window closed successfully if (Result.HasValue && Result.Value) { // Retrieve the new item Booking b = Window.GetItem(); if (b == null) { return; } // Are we deleting? bool Delete = Window.DeleteBooking; b.Id = Tile.Booking == null ? 0 : Tile.Booking.Id; // Add or remove as appropriate using (DataRepository Repo = new DataRepository()) { if (Delete) { Repo.Bookings.Remove(Repo.Bookings.Where(b2 => b2.Id == b.Id).Single()); } else { Repo.Bookings.Add(b); } } } } }
// Run when a tile is pressed on the timetable private void Timetable_TileClicked(TimetableTile Tile) { // If the current user isn't a student and either there's no booking or the teacher owns the booking if (!CurrentUser.IsStudent && (CurrentUser.IsAdmin || Tile.Booking == null || Tile.Booking.Teacher.Id == CurrentUser.Id)) { EditBooking Window = null; // Whether this is a new booking or an edited one bool NewBooking = Tile.Booking == null; if (NewBooking) // New booking Window = new EditBooking(CurrentUser, true, Tile.Time, Tile.Room); else // Editing booking Window = new EditBooking(CurrentUser, false, Tile.Booking); Window.CurrentDate = CurrentDay; // Display the window, store the result bool? Result = Window.ShowDialog(); // If the window closed successfully if (Result.HasValue && Result.Value) { // Retrieve the new item Booking b = Window.GetItem(); if (b == null) return; // Are we deleting? bool Delete = Window.DeleteBooking; b.Id = Tile.Booking == null ? 0 : Tile.Booking.Id; // Add or remove as appropriate using (DataRepository Repo = new DataRepository()) { if (Delete) Repo.Bookings.Remove(Repo.Bookings.Where(b2 => b2.Id == b.Id).Single()); else Repo.Bookings.Add(b); } } } }