Files
CineBook/Views/MovieEditDialog.xaml.cs

77 lines
2.3 KiB
C#

using CineBook.Models;
using System.Windows;
using System.Windows.Controls;
namespace CineBook.Views;
public partial class MovieEditDialog : Window
{
public Movie? Result { get; private set; }
private readonly Movie? _editing;
public MovieEditDialog(Movie? movie)
{
InitializeComponent();
_editing = movie;
if (movie != null)
{
DialogTitle.Text = "🎥 FILM BEARBEITEN";
TitleBox.Text = movie.Title;
// Set genre combobox
foreach (ComboBoxItem item in GenreBox.Items)
if (item.Content?.ToString() == movie.Genre)
GenreBox.SelectedItem = item;
DurationBox.Text = movie.DurationMinutes.ToString();
RatingBox.Text = movie.Rating.ToString("F1");
ActiveCheck.IsChecked = movie.IsActive;
DescBox.Text = movie.Description;
}
else
{
DialogTitle.Text = "🎥 FILM HINZUFÜGEN";
RatingBox.Text = "7.0";
ActiveCheck.IsChecked = true;
}
}
private void SaveClick(object sender, RoutedEventArgs e)
{
// Validierung
if (string.IsNullOrWhiteSpace(TitleBox.Text))
{
ErrorText.Text = "⚠ Titel ist Pflichtfeld!"; return;
}
if (!int.TryParse(DurationBox.Text, out var dur) || dur <= 0)
{
ErrorText.Text = "⚠ Ungültige Dauer!"; return;
}
if (!decimal.TryParse(RatingBox.Text.Replace(',', '.'),
System.Globalization.NumberStyles.Any,
System.Globalization.CultureInfo.InvariantCulture, out var rating)
|| rating < 0 || rating > 10)
{
ErrorText.Text = "⚠ Bewertung muss zwischen 0-10 liegen!"; return;
}
Result = new Movie
{
MovieID = _editing?.MovieID ?? 0,
Title = TitleBox.Text.Trim(),
Genre = (GenreBox.SelectedItem as ComboBoxItem)?.Content?.ToString() ?? "",
DurationMinutes = dur,
Rating = rating,
IsActive = ActiveCheck.IsChecked == true,
Description = DescBox.Text.Trim()
};
DialogResult = true;
Close();
}
private void CancelClick(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
}