public async Task <IActionResult> Create([Bind("Id,Title")] Film film)
        {
            if (ModelState.IsValid)
            {
                _context.Add(film);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(film));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Nr,Rows,Columns")] Hall hall)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hall);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hall));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,Genre,Price,ShowDate")] Show show, string filmTitle, int hallNr)
        {
            if (show == null)
            {
                return(NotFound());
            }

            var film = _context.Films.FirstOrDefault(x => x.Title == filmTitle);
            var hall = _context.Halls.FirstOrDefault(q => q.Nr == hallNr);

            if (film == null)
            {
                //jesli nie ma takiego filmu, to zaznacz okienko na czerwono
                ModelState.AddModelError(string.Empty, "Film o podanym tytule nie istnieje w bazie");
            }
            else
            {
                show.Film = film;
            }

            if (hall == null)
            {
                ModelState.AddModelError(string.Empty, "Sala o podanym numerze nie istnieje w bazie");
                //return View();
            }
            else
            {
                show.Hall = hall;
            }


            if (ModelState.IsValid)
            {
                _context.Add(show);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(show));
        }