Exemple #1
0
        private void DeleteOrder(object sender, RoutedEventArgs e)
        {
            Booking selectedbooking = (Booking)bookingsGrid.SelectedItem;

            using (KinoContext db = new KinoContext())
            {
                var film = db.Films.First(x => x.Name == selectedbooking.Film);
                db.ReservationPlaces.RemoveRange(db.ReservationPlaces.Where(x => x.CodeId == selectedbooking.Code));
                db.ReservationCodes.Remove(db.ReservationCodes.First(x => x.Code == selectedbooking.Code));
                db.Notifications.Add(new Notification {
                    Message = $"Привет, {user.FirstName}!\nВы отменили бронирование №{selectedbooking.Code} на сумму {selectedbooking.TotalCost} грн.\n\nФильм: {film.Name}\nДата: {selectedbooking.Date}\nСеанс:  {selectedbooking.Time}", Time = $"{DateTime.Now.Day.ToString("00")}.{DateTime.Now.Month.ToString("00")}\n{DateTime.Now.Hour.ToString("00")}:{DateTime.Now.Minute.ToString("00")}", UserId = user.Id
                });

                db.SaveChanges();
                MessageBox.Show("Бронирование успешно удалено.");
            }

            try
            {
                bookingsGrid.SelectedItem = bookings.ElementAt(0);
            }
            catch { }

            BookingsGridRefresh();
        }
Exemple #2
0
 private void Clear(object sender, RoutedEventArgs e)
 {
     using (KinoContext db = new KinoContext())
     {
         db.Notifications.RemoveRange(db.Notifications.Where(x => x.UserId == main.user.Id));
         db.SaveChanges();
         UpdateList();
     }
 }
Exemple #3
0
 private void ChangeLastName(object sender, RoutedEventArgs e)
 {
     using (KinoContext db = new KinoContext())
     {
         db.Users.First(x => x.Id == user.Id).LastName = lastname.Text;
         db.SaveChanges();
         MessageBox.Show("Фамилия успешно изменена.");
     }
 }
Exemple #4
0
 private void ChangeLogin(object sender, RoutedEventArgs e)
 {
     using (KinoContext db = new KinoContext())
     {
         db.Users.First(x => x.Id == user.Id).Login = login.Text;
         db.SaveChanges();
         MessageBox.Show("Логин успешно изменен.");
     }
 }
 public void DeleteOrder(Booking booking)
 {
     using (KinoContext db = new KinoContext())
     {
         var reserv = db.ReservationCodes.First(x => x.Code == booking.Code);
         db.ReservationPlaces.RemoveRange(db.ReservationPlaces.Where(x => x.CodeId == booking.Code));
         db.ReservationCodes.Remove(db.ReservationCodes.Find(reserv.Id));
         db.SaveChanges();
     }
     main.RefreshBookings();
     BookingsGridRefresh();
 }
        public void Update(object ob)
        {
            Film film = (Film)ob;

            using (KinoContext db = new KinoContext())
            {
                db.Notifications.Add(new Notification {
                    Message = $"Привет, {this.FirstName}!\nФильм {film.Name} уже в прокате, проверьте вкладку \"Сеансы\".\nУспейте забронировать билет!", Time = $"{DateTime.Now.Day.ToString("00")}.{DateTime.Now.Month.ToString("00")}\n{DateTime.Now.Hour.ToString("00")}:{DateTime.Now.Minute.ToString("00")}", UserId = this.Id
                });
                db.SaveChanges();
            }
        }
Exemple #7
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            using (KinoContext db = new KinoContext())
            {
                db.Films.First(x => x.Id == selectedfilm.Id).IsPremiere = false;
                db.SaveChanges();
                selectedfilm.ChangeState();
            }

            main.GridPrincipal.Children.Clear();
            main.GridPrincipal.Children.Add(new NewFilmControl(main, new Seancess(main), selectedfilm, true));
            main.title.Text = "Добавление фильма в сеансы";
        }
Exemple #8
0
 private void code_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (code.Text == randcode.ToString())
     {
         using (KinoContext db = new KinoContext())
         {
             db.Users.First(x => x.Id == user.Id).Email = email.Text;
             db.SaveChanges();
         }
         MessageBox.Show("E-mail успешно изменен.");
         code.Visibility   = Visibility.Collapsed;
         submit.Visibility = Visibility.Collapsed;
     }
 }
Exemple #9
0
        private void DeleteFilm(object sender, RoutedEventArgs e)
        {
            using (KinoContext db = new KinoContext())
            {
                db.Subscriptions.RemoveRange(db.Subscriptions.Where(x => x.FilmId == selectedfilm.Id));
                db.FilmsGenres.RemoveRange(db.FilmsGenres.Where(x => x.FilmId == selectedfilm.Id));
                db.Films.Remove(db.Films.First(x => x.Id == selectedfilm.Id));
                db.SaveChanges();
                films        = db.Films.Where(x => x.IsPremiere == true).ToList();
                selectedfilm = db.Films.First(x => x.IsPremiere == true);
            }

            FilmRefresh();
        }
 public bool FinalRegistration(int number)
 {
     if (this.number == number)
     {
         using (KinoContext db = new KinoContext())
         {
             db.Users.Add(user);
             db.SaveChanges();
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
Exemple #11
0
 private void ChangePassword(object sender, RoutedEventArgs e)
 {
     using (KinoContext db = new KinoContext())
     {
         if (db.Users.First(x => x.Id == user.Id).Password == oldpass.Password && newpass.Password == newpass2.Password)
         {
             db.Users.First(x => x.Id == user.Id).Password = newpass.Password;
             db.SaveChanges();
             MessageBox.Show("Пароль успешно изменен.");
         }
         else
         {
             MessageBox.Show("Что-то пошло не так.");
         }
     }
 }
Exemple #12
0
        private void ChangePath(object sender, RoutedEventArgs e)
        {
            OpenFileDialog folderBrowser = new OpenFileDialog();

            folderBrowser.ValidateNames   = false;
            folderBrowser.CheckFileExists = false;
            folderBrowser.CheckPathExists = true;
            folderBrowser.FileName        = "Folder Selection.";

            if (folderBrowser.ShowDialog() == true)
            {
                string folderPath = System.IO.Path.GetDirectoryName(folderBrowser.FileName);
                path.Text = folderPath;

                using (KinoContext db = new KinoContext())
                {
                    db.Users.First(x => x.Id == user.Id).PathForTickets = path.Text;
                    db.SaveChanges();
                }
            }
        }
        private void TicketsSold(object sender, RoutedEventArgs e)
        {
            Booking booking = (Booking)bookingsGrid.SelectedItem;

            using (KinoContext db = new KinoContext())
            {
                var reserv = db.ReservationCodes.First(x => x.Code == booking.Code);

                var places = db.ReservationPlaces.Where(x => x.CodeId == reserv.Id);
                
                foreach (var x in places.ToList())
                {
                    db.SoldPlaces.Add(new SoldPlace { FilmDateSeanceId = booking.FDS, Place = x.Place, Range = x.Range });
                    db.SaveChanges();
                }

                DeleteOrder(booking);
            }
            main.RefreshBookings();
            BookingsGridRefresh();

            MessageBox.Show("Бронь успешно подтверждена.");
        }
        private void SaveFilm()
        {
            if (filmtitle.Text == "" || filmcountry.Text == "" || filmdescription.Text == "")
            {
                MessageBox.Show("Заполните все поля");
            }
            else
            {
                if (edit == true)
                {
                    using (KinoContext db = new KinoContext())
                    {
                        db.Films.First(x => x.Id == film.Id).Name            = filmtitle.Text;
                        db.Films.First(x => x.Id == film.Id).PosterByte      = ImageToByte((BitmapImage)filmposter.Source);
                        db.Films.First(x => x.Id == film.Id).RatingIMDb      = float.Parse(filmIMDb.Text);
                        db.Films.First(x => x.Id == film.Id).RatingKinopoisk = float.Parse(filmKinopoisk.Text);
                        db.Films.First(x => x.Id == film.Id).Slogan          = filmslogan.Text;
                        db.Films.First(x => x.Id == film.Id).Trailer         = trailer.Text;
                        db.Films.First(x => x.Id == film.Id).Country         = filmcountry.Text;
                        db.Films.First(x => x.Id == film.Id).Description     = filmdescription.Text;

                        if (filmpremier.Visibility == Visibility.Visible)
                        {
                            db.Films.First(x => x.Id == film.Id).PremierDate = DateTime.Parse(filmpremier.Text);
                            db.SaveChanges();
                        }
                        db.SaveChanges();

                        db.FilmsGenres.RemoveRange(db.FilmsGenres.Where(x => x.FilmId == film.Id));
                        db.SaveChanges();

                        foreach (var y in genres)
                        {
                            if (db.Genres.Where(x => x.Name == y.Name).Count() == 0)
                            {
                                db.Genres.Add(y);
                                db.SaveChanges();
                            }

                            var genresid = db.Genres.First(x => x.Name == y.Name).Id;

                            db.FilmsGenres.Add(new FilmsGenres {
                                FilmId = film.Id, GenreId = genresid
                            });
                            db.SaveChanges();
                        }

                        main.GridPrincipal.Children.Clear();
                        try
                        {
                            main.GridPrincipal.Children.Add(seancess);
                        }
                        catch { premiers.FilmRefresh(); main.GridPrincipal.Children.Add(premiers); }
                    }
                }

                else
                {
                    using (KinoContext db = new KinoContext())
                    {
                        film = new Film();

                        film.Name       = filmtitle.Text;
                        film.Slogan     = filmslogan.Text;
                        film.PosterByte = poster;
                        try
                        {
                            film.RatingIMDb      = float.Parse(filmIMDb.Text);
                            film.RatingKinopoisk = float.Parse(filmKinopoisk.Text);
                        }
                        catch { }
                        film.Description = filmdescription.Text;
                        film.Country     = filmcountry.Text;
                        film.Trailer     = trailer.Text;

                        try
                        {
                            film.PremierDate = DateTime.Parse(filmpremier.Text);
                        }
                        catch { film.PremierDate = DateTime.Now; }

                        if (isPremier)
                        {
                            film.IsPremiere = true;
                        }

                        db.Films.Add(film);
                        db.SaveChanges();
                        var filmid = db.Films.First(x => x.Name == film.Name).Id;

                        foreach (Genre x in genres.ToArray())
                        {
                            if (db.Genres.Where(g => g.Name == x.Name).Count() == 0)
                            {
                                db.Genres.Add(x);
                                db.SaveChanges();
                            }

                            var genreid = db.Genres.First(g => g.Name == x.Name).Id;

                            db.FilmsGenres.Add(new FilmsGenres {
                                FilmId = filmid, GenreId = genreid
                            });
                            db.SaveChanges();
                        }

                        main.GridPrincipal.Children.Clear();
                        try
                        {
                            main.GridPrincipal.Children.Add(seancess);
                        }
                        catch { premiers.FilmRefresh(); main.GridPrincipal.Children.Add(premiers); }
                    }
                }
                MessageBox.Show("Фильм успешно сохранен.");
            }
        }
Exemple #15
0
        private void Book(object sender, RoutedEventArgs e)
        {
            var      num  = 1;
            var      date = seancess.seance.Title.ToString("t").Split(':');
            var      time = seancess.date.Title.ToString("d").Split('.');
            DateTime a    = DateTime.Now;
            DateTime b    = new DateTime(int.Parse(time[2]), int.Parse(time[1]), int.Parse(time[0]), int.Parse(date[0]), int.Parse(date[1]), 0);
            var      diff = b.Subtract(a).TotalMinutes;

            if (seancess.main.user == null)
            {
                using (KinoContext db = new KinoContext())
                {
                    for (int i = 0; i < panels.Count(); i++)
                    {
                        var grids = panels.ElementAt(i).Children.OfType <Grid>();

                        foreach (var y in grids)
                        {
                            var buttons = y.Children.OfType <Button>();

                            foreach (var z in buttons)
                            {
                                if (z.Style == (Style)FindResource("RoundCornerSold"))
                                {
                                    db.SoldPlaces.Add(new SoldPlace {
                                        Range = i + 1, Place = int.Parse(z.Content.ToString()), FilmDateSeanceId = seancess.filmdateseance.Id
                                    });
                                    db.SaveChanges();
                                }
                            }
                        }
                    }

                    db.Prices.First(x => x.Range == 1).Cost = int.Parse(firstf.Text);
                    db.Prices.First(x => x.Range == 2).Cost = int.Parse(secondf.Text);
                    db.Prices.First(x => x.Range == 3).Cost = int.Parse(thirdf.Text);
                    db.Prices.First(x => x.Range == 4).Cost = int.Parse(fourthf.Text);
                    db.Prices.First(x => x.Range == 5).Cost = int.Parse(fifthf.Text);
                    db.Prices.First(x => x.Range == 6).Cost = int.Parse(sixf.Text);
                    db.Prices.First(x => x.Range == 7).Cost = int.Parse(seventhf.Text);
                    db.Prices.First(x => x.Range == 8).Cost = int.Parse(eighthf.Text);
                    db.SaveChanges();
                }
            }



            else if (diff > 15)
            {
                var dir = "KINOAFISHA " + DateTime.Now.ToString("dd-mm-yy hh-mm");
                using (KinoContext db = new KinoContext())
                {
                    MessageBox.Show(user.Id.ToString());
                    if (db.Users.First(x => x.Id == user.Id).PathForTickets == null)
                    {
                        folder = SetPath();
                        MessageBox.Show(db.Users.First(x => x.Id == user.Id).PathForTickets);
                        db.Users.First(x => x.Id == user.Id).PathForTickets = folder;
                        db.SaveChanges();
                        MessageBox.Show(db.Users.First(x => x.Id == user.Id).PathForTickets);
                    }
                    else
                    {
                        folder = db.Users.First(x => x.Id == user.Id).PathForTickets;
                    }
                }

                using (KinoContext db = new KinoContext())
                {
                    Directory.CreateDirectory(db.Users.First(x => x.Id == user.Id).PathForTickets + "\\" + dir);

                    var number = 0;

                    if (db.ReservationCodes.Where(x => x.UserId == user.Id && x.FilmDateSeanceId == seancess.filmdateseance.Id).Count() == 0)
                    {
                        Random rnd = new Random();
                        number = rnd.Next(100000, 999999);
                        ReservationCode code = new ReservationCode {
                            Code = number, UserId = user.Id, FilmDateSeanceId = seancess.filmdateseance.Id
                        };
                        db.ReservationCodes.Add(code);
                        db.SaveChanges();
                    }
                    else
                    {
                        number = db.ReservationCodes.First(x => x.UserId == user.Id && x.FilmDateSeanceId == seancess.filmdateseance.Id).Code;
                    }

                    var codeid = db.ReservationCodes.First(x => x.UserId == user.Id && x.FilmDateSeanceId == seancess.filmdateseance.Id).Id;

                    List <Order> orders = new List <Order>();
                    for (int i = 0; i < panels.Count(); i++)
                    {
                        var grids = panels.ElementAt(i).Children.OfType <Grid>();

                        foreach (var y in grids)
                        {
                            var buttons = y.Children.OfType <Button>();

                            foreach (var z in buttons)
                            {
                                if (z.Style == (Style)FindResource("RoundCornerChosed"))
                                {
                                    int price = 0;
                                    switch (i)
                                    {
                                    case 0: price = int.Parse(firstf.Text); break;

                                    case 1: price = int.Parse(secondf.Text); break;

                                    case 2: price = int.Parse(thirdf.Text); break;

                                    case 3: price = int.Parse(fourthf.Text); break;

                                    case 4: price = int.Parse(fifthf.Text); break;

                                    case 5: price = int.Parse(sixf.Text); break;

                                    case 6: price = int.Parse(seventhf.Text); break;

                                    case 7: price = int.Parse(eighthf.Text); break;
                                    }

                                    if (student.IsChecked == true)
                                    {
                                        orders.Add(new StudentOrder(i + 1, int.Parse(z.Content.ToString()), codeid, price));
                                    }

                                    else if (retiree.IsChecked == true)
                                    {
                                        orders.Add(new RetireeOrder(i + 1, int.Parse(z.Content.ToString()), codeid, price));
                                    }

                                    else
                                    {
                                        orders.Add(new SimpleOrder(i + 1, int.Parse(z.Content.ToString()), codeid, price));
                                    }
                                    num++;
                                }
                            }
                        }
                    }

                    if (orders.Count() >= 5)
                    {
                        if (orders.Count() >= 10)
                        {
                            for (int i = 0; i < orders.Count(); i++)
                            {
                                orders[i] = new MoreThan10Decorator(orders[i]);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < orders.Count(); i++)
                            {
                                orders[i] = new MoreThan5Decorator(orders[i]);
                            }
                        }
                    }

                    num = 1;
                    var totalprice = db.ReservationCodes.First(r => r.Id == codeid).TotalPrice;
                    foreach (var x in orders)
                    {
                        db.ReservationPlaces.Add(new ReservationPlace {
                            CodeId = x.Code, Place = x.Place, Range = x.Range, Price = x.Price, Retiree = x.Retiree, Student = x.Student
                        });
                        db.SaveChanges();

                        Ticket t = new Ticket(user);
                        t.path            = folder;
                        t.filmname.Text   = seancess.film.Name;
                        t.filmcode.Text   = db.ReservationCodes.First(r => r.UserId == user.Id && r.FilmDateSeanceId == seancess.filmdateseance.Id).Code.ToString();
                        t.filmdate.Text   = seancess.date.Title.ToString("d");
                        t.filmplace.Text  = x.Place.ToString();
                        t.filmrange.Text  = x.Range.ToString();
                        t.filmseance.Text = seancess.seance.Title.ToString("t");
                        t.filmprice.Text  = x.GetCost().ToString();
                        t.dir             = dir;
                        t.number          = num.ToString();
                        t.Show();
                        num++;
                        totalprice += x.Price;
                    }
                    db.ReservationCodes.First(r => r.Id == codeid).TotalPrice = totalprice;

                    Auth_Reg auth = new Auth_Reg();
                    auth.SendMail($"Привет, {user.FirstName}! Ваше бронирование №{db.ReservationCodes.First(r => r.Id == codeid).Code} на сумму {totalprice} было успешно оформлено. Основная информация про заказ: фильм - \"{seancess.film.Name}\", дата - {seancess.date.Title.ToString("d")}, сеанс - {seancess.seance.Title.ToString("t")}. Для более детальной информации просмотрите вкладку \"Профиль\" в нашем приложении KINOAFISHA. Спасибо за бронирование!", user.Email);
                    MessageBox.Show($"Письмо о бронировании было отправлено на Вашу электронную почту, в папке {folder} были сохранены электронные билеты. Спасибо за бронирование!");

                    db.Notifications.Add(new Notification {
                        Message = $"Привет, {user.FirstName}!\nВы успешно совершили бронирование №{db.ReservationCodes.First(r => r.Id == codeid).Code} на сумму {totalprice} грн.\n\nФильм: \"{seancess.film.Name}\"\nДата: {seancess.date.Title.ToString("d")}\nСеанс:  {seancess.seance.Title.ToString("t")}", Time = $"{DateTime.Now.Day.ToString("00")}.{DateTime.Now.Month.ToString("00")}\n{DateTime.Now.Hour.ToString("00")}:{DateTime.Now.Minute.ToString("00")}", UserId = user.Id
                    });

                    db.SaveChanges();
                }
            }
            else
            {
                MessageBox.Show("Бронировать билеты можно не позже, чем за 15 минут до начала сеанса.");
            }
        }
        private void DeleteFilm(object sender, RoutedEventArgs e)
        {
            bool delete       = true;
            Film selectedfilm = (Film)filmsGrid.SelectedItem;

            using (KinoContext db = new KinoContext())
            {
                List <SeanceFDS> seanceFDs = new List <SeanceFDS>();
                var selectedfilmdate       = db.FilmsDates.Where(x => x.FilmId == selectedfilm.Id);

                foreach (var x in selectedfilmdate.ToList())
                {
                    var selecteddate = db.Dates.First(d => d.Id == x.DateId);

                    List <FilmsDatesSeances> filmdateseances = new List <FilmsDatesSeances>();
                    filmdateseances = db.FilmsDatesSeances.Where(fds => fds.FilmsDatesId == x.Id).ToList();

                    foreach (var fds in filmdateseances.ToList())
                    {
                        var selectedseance = db.Seances.First(s => s.Id == fds.SeanceId);
                        seanceFDs.Add(new SeanceFDS {
                            date = selecteddate.Title, time = selectedseance.Title
                        });
                    }
                }

                foreach (var x in seanceFDs.ToList())
                {
                    var      date = x.time.ToString("t").Split(':');
                    var      time = x.date.ToString("d").Split('.');
                    DateTime a    = DateTime.Now;
                    DateTime b    = new DateTime(int.Parse(time[2]), int.Parse(time[1]), int.Parse(time[0]), int.Parse(date[0]), int.Parse(date[1]), 0);
                    var      diff = b.Subtract(a).TotalMinutes;

                    if (diff > 0)
                    {
                        delete = false;
                        break;
                    }
                }

                if (delete)
                {
                    var selectedfilmdateids = new List <int>();
                    foreach (var x in selectedfilmdate.ToList())
                    {
                        List <FilmsDatesSeances> filmdateseances = new List <FilmsDatesSeances>();
                        filmdateseances = db.FilmsDatesSeances.Where(fds => fds.FilmsDatesId == x.Id).ToList();

                        foreach (var fds in filmdateseances)
                        {
                            var reservations = db.ReservationCodes.Where(r => r.FilmDateSeanceId == fds.Id);
                            var reservcodes  = new List <int>();
                            foreach (var r in reservations)
                            {
                                reservcodes.Add(r.Id);
                            }

                            foreach (var rc in reservcodes)
                            {
                                db.ReservationPlaces.RemoveRange(db.ReservationPlaces.Where(rp => rp.CodeId == rc));
                                db.SaveChanges();
                            }
                            db.ReservationCodes.RemoveRange(db.ReservationCodes.Where(rc => rc.FilmDateSeanceId == fds.Id));
                            db.SaveChanges();

                            db.SoldPlaces.RemoveRange(db.SoldPlaces.Where(s => s.FilmDateSeanceId == fds.Id));
                        }

                        db.FilmsDatesSeances.RemoveRange(filmdateseances);
                    }
                    db.FilmsDates.RemoveRange(selectedfilmdate);
                    db.FilmsGenres.RemoveRange(db.FilmsGenres.Where(g => g.FilmId == selectedfilm.Id));
                    db.Films.Remove(db.Films.First(g => g.Id == selectedfilm.Id));
                    db.Subscriptions.RemoveRange(db.Subscriptions.Where(x => x.FilmId == selectedfilm.Id));
                    db.SaveChanges();
                    filmsGridRefresh();
                }
                else
                {
                    MessageBox.Show("Нельзя удалить выбранный фильм, так как сеансы еще не прошли.");
                }
            }
        }
        private void Save(object sender, RoutedEventArgs e)
        {
            using (KinoContext db = new KinoContext())
            {
                try
                {
                    var filmdate            = db.FilmsDates.Where(x => x.FilmId == film.Id);
                    var selectedfilmdate    = db.FilmsDates.Where(x => x.FilmId == film.Id);
                    var selectedfilmdateids = new List <int>();
                    foreach (var x in filmdate)
                    {
                        selectedfilmdateids.Add(x.Id);
                    }

                    var selectedfilmdateseance = db.FilmsDatesSeances.Where(x => selectedfilmdateids.Contains((int)x.FilmsDatesId));

                    db.FilmsDatesSeances.RemoveRange(selectedfilmdateseance);
                    db.FilmsDates.RemoveRange(selectedfilmdate);

                    db.SaveChanges();



                    foreach (var x in datesname)
                    {
                        if (db.Dates.Where(d => d.Title == x.InFormat).Count() == 0)
                        {
                            db.Dates.Add(new Date {
                                Title = x.InFormat
                            });
                            db.SaveChanges();
                        }

                        var dateid = db.Dates.First(d => d.Title == x.InFormat).Id;

                        if (db.FilmsDates.Where(fd => fd.DateId == dateid && fd.FilmId == film.Id).Count() == 0)
                        {
                            db.FilmsDates.Add(new FilmsDates {
                                DateId = dateid, FilmId = film.Id
                            });
                            db.SaveChanges();
                        }

                        foreach (var y in seancesname)
                        {
                            int seanceid  = -1;
                            var dub       = false;
                            var seancesdb = db.Seances;
                            if (y.InFormat == x.InFormat)
                            {
                                foreach (var ss in seancesdb)
                                {
                                    if (ss.Title.ToString().Contains(y.Title))
                                    {
                                        dub      = true;
                                        seanceid = ss.Id;
                                        break;
                                    }
                                }
                                if (!dub)
                                {
                                    db.Seances.Add(new Seance {
                                        Title = y.SeanceInFormat
                                    });
                                    db.SaveChanges();
                                }

                                var filmdateid = db.FilmsDates.First(fd => fd.FilmId == film.Id && fd.DateId == dateid).Id;

                                if (seanceid == -1)
                                {
                                    seanceid = db.Seances.First(s => s.Title == y.SeanceInFormat).Id;
                                }

                                if (db.FilmsDatesSeances.Where(fds => fds.FilmsDatesId == filmdateid && fds.SeanceId == seanceid).Count() == 0)
                                {
                                    db.FilmsDatesSeances.Add(new FilmsDatesSeances {
                                        FilmsDatesId = filmdateid, SeanceId = seanceid
                                    });
                                    db.SaveChanges();
                                }
                            }
                        }

                        MessageBox.Show("Внесенные изменения были успешно сохранены.");
                    }
                }
                catch { }


                main.GridPrincipal.Children.Clear();
                main.GridPrincipal.Children.Add(seancess);
            }
        }