using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace KinoPoisk
{
    /// <summary>
    /// Логика взаимодействия для AddSeans.xaml
    /// </summary>
    public partial class AddSeans : Window
    {
        public AddSeans()
        {
            InitializeComponent();
            KinoPoiskContext context = new KinoPoiskContext();
            var films = context.Films;
            foreach (var item in films)
            {
                Namefilm.Items.Add(item.NameFilm);
            }
        }

        private void CreateAcc_Click(object sender, RoutedEventArgs e)
        {
            KinoPoiskContext context = new KinoPoiskContext();
            var sessions = context.MovieSessions;
            var idFilm = context.Films.SingleOrDefault(x => x.NameFilm == Namefilm.Text);

            MovieSession movieSession = new MovieSession()
            {
                IdFilm = idFilm.Id,
                Seats = Convert.ToInt32(CollMest.Text),
                DatePremiers = Convert.ToDateTime(DateProv.Text),
                Price = Convert.ToDecimal(Price.Text),
            };

            sessions.Add(movieSession);
            context.SaveChanges();

            MainMenu mainmenu = new MainMenu();
            this.Hide();
            mainmenu.Show();
        }

        private void Cansel_Click(object sender, RoutedEventArgs e)
        {
            MainMenu mainmenu = new MainMenu();
            this.Hide();
            mainmenu.Show();
        }
    }
}
