public ActionResult EditSeance(AddSeanceViewModel model)
        {
            var seance = db.Seances.FirstOrDefault(x => x.Id == model.Id);

            if (!ModelState.IsValid)
            {
                model.Auditoriums = db.Auditoriums.Select(x =>
                                                          new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                }).ToList();

                model.Films = db.Films.Select(x =>
                                              new SelectListItem
                {
                    Text  = x.Title,
                    Value = x.Id.ToString()
                }).ToList();

                return(View(model));
            }

            if (db.Seances.Any(x => x.Name == model.Name))
            {
                model.Auditoriums = db.Auditoriums.Select(x =>
                                                          new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                }).ToList();

                model.Films = db.Films.Select(x =>
                                              new SelectListItem
                {
                    Text  = x.Title,
                    Value = x.Id.ToString()
                }).ToList();

                ModelState.AddModelError(String.Empty, "Ten seans jest już używany dla innego filmu.");

                return(View(model));
            }

            seance.Id    = model.Id;
            seance.Name  = model.Name;
            seance.Price = model.Price;
            seance.Date  = model.Date;
            var auditorium = db.Auditoriums.FirstOrDefault(c => c.Id == model.Auditorium);

            seance.Auditorium = auditorium;
            var film = db.Films.FirstOrDefault(c => c.Id == model.Film);

            seance.Film = film;

            db.SaveChanges();

            return(RedirectToAction("SeanceList"));
        }
        public ActionResult EditSeance(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var seance = db.Seances.Find(id);

            if (seance == null)
            {
                return(HttpNotFound());
            }
            else
            {
                var model = new AddSeanceViewModel()
                {
                    Id          = seance.Id,
                    Name        = seance.Name,
                    Price       = seance.Price,
                    Date        = seance.Date,
                    Film        = seance.Film.Id,
                    Auditorium  = seance.Auditorium.Id,
                    Auditoriums = db.Auditoriums.Select(x =>
                                                        new SelectListItem
                    {
                        Text  = x.Name,
                        Value = x.Id.ToString()
                    }).ToList(),

                    Films = db.Films.Select(x =>
                                            new SelectListItem
                    {
                        Text  = x.Title,
                        Value = x.Id.ToString()
                    }).ToList()
                };

                return(View(model));
            }
        }
        //SEANSE

        public ActionResult CreateSeance()
        {
            var model = new AddSeanceViewModel
            {
                Auditoriums = db.Auditoriums.Select(x =>
                                                    new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                }).ToList(),

                Films = db.Films.Select(x =>
                                        new SelectListItem
                {
                    Text  = x.Title,
                    Value = x.Id.ToString()
                }).ToList()
            };

            return(View(model));
        }
        public ActionResult CreateSeance(AddSeanceViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model = new AddSeanceViewModel
                {
                    Auditoriums = db.Auditoriums.Select(x =>
                                                        new SelectListItem
                    {
                        Text  = x.Name,
                        Value = x.Id.ToString()
                    }).ToList(),

                    Films = db.Films.Select(x =>
                                            new SelectListItem
                    {
                        Text  = x.Title,
                        Value = x.Id.ToString()
                    }).ToList()
                };

                return(View(model));
            }

            if (db.Seances.Any(x => x.Name == model.Name))
            {
                model = new AddSeanceViewModel
                {
                    Auditoriums = db.Auditoriums.Select(x =>
                                                        new SelectListItem
                    {
                        Text  = x.Name,
                        Value = x.Id.ToString()
                    }).ToList(),

                    Films = db.Films.Select(x =>
                                            new SelectListItem
                    {
                        Text  = x.Title,
                        Value = x.Id.ToString()
                    }).ToList()
                };

                ModelState.AddModelError(string.Empty, "Ten seans jest już używany dla innego filmu.");

                //komunikat ten tytuł jest zajety
                return(View(model));
            }

            Seance seance = new Seance();

            seance.Name    = model.Name;
            seance.Price   = model.Price;
            seance.Deleted = model.Deleted;
            seance.Date    = model.Date;

            var film = db.Films.FirstOrDefault(c => c.Id == model.Film);

            seance.Film = film;

            var auditorium = db.Auditoriums.FirstOrDefault(c => c.Id == model.Auditorium);

            seance.Auditorium = auditorium;

            db.Seances.Add(seance);
            db.SaveChanges();

            return(RedirectToAction("SeanceList"));
        }