CineBook Projekt hinzugefügt
This commit is contained in:
79
Views/BookingsView.xaml.cs
Normal file
79
Views/BookingsView.xaml.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using CineBook.Data;
|
||||
using CineBook.Helpers;
|
||||
using CineBook.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CineBook.Views;
|
||||
|
||||
public partial class BookingsView : UserControl
|
||||
{
|
||||
private readonly Repository _repo;
|
||||
private readonly User _currentUser;
|
||||
private Booking? _selected;
|
||||
private List<Booking> _allBookings = new();
|
||||
|
||||
public BookingsView(Repository repo, User user)
|
||||
{
|
||||
InitializeComponent();
|
||||
_repo = repo;
|
||||
_currentUser = user;
|
||||
|
||||
if (!Session.IsAdmin)
|
||||
BtnCancel.Visibility = Visibility.Collapsed;
|
||||
|
||||
StatusFilter.SelectedIndex = 0;
|
||||
LoadBookings();
|
||||
}
|
||||
|
||||
private void LoadBookings()
|
||||
{
|
||||
try
|
||||
{
|
||||
_allBookings = Session.IsAdmin
|
||||
? _repo.GetAllBookings()
|
||||
: _repo.GetBookingsByUser(_currentUser.UserID);
|
||||
ApplyFilter();
|
||||
}
|
||||
catch (System.Exception ex) { StatusText.Text = "⚠ Fehler: " + ex.Message; }
|
||||
}
|
||||
|
||||
private void ApplyFilter()
|
||||
{
|
||||
var filter = (StatusFilter.SelectedItem as ComboBoxItem)?.Content?.ToString() ?? "Alle";
|
||||
var data = filter == "Alle" ? _allBookings : _allBookings.Where(b => b.Status == filter).ToList();
|
||||
BookingsGrid.ItemsSource = data;
|
||||
StatusText.Text = $"● {data.Count} Buchungen angezeigt.";
|
||||
}
|
||||
|
||||
private void FilterChanged(object sender, SelectionChangedEventArgs e) => ApplyFilter();
|
||||
private void RefreshClick(object sender, RoutedEventArgs e) => LoadBookings();
|
||||
|
||||
private void GridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
_selected = BookingsGrid.SelectedItem as Booking;
|
||||
BtnCancel.IsEnabled = _selected != null && _selected.Status == "Confirmed" && Session.IsAdmin;
|
||||
}
|
||||
|
||||
private void CancelBookingClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selected == null) return;
|
||||
var r = MessageBox.Show($"Buchung {_selected.BookingCode} wirklich stornieren?",
|
||||
"Stornierung", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||
if (r == MessageBoxResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
_repo.CancelBooking(_selected.BookingID, _selected.SeatID, _selected.ScreeningID);
|
||||
LoadBookings();
|
||||
MessageBox.Show("Buchung erfolgreich storniert.", "Erfolg", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
MessageBox.Show("DB-Fehler: " + ex.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user