public ActionResult Create(MovieShovingViewModel model) { ViewBag.Movies = new SelectList(_context.Movies, "MovieId", "NameOfMovie"); ViewBag.Cinemas = new SelectList(_context.Cinemas, "Id", "CinemaName"); /*ApplicationDbContext myEntity = new ApplicationDbContext(); * var getCinemalist = myEntity.Cinemas.ToList(); * SelectList cinemaList = new SelectList(getCinemalist, "Id", "CinemaName"); * ViewBag.cinemalistname = cinemaList; * * ApplicationDbContext myEntity2 = new ApplicationDbContext(); * var getMovieList = myEntity2.Movies.ToList(); * SelectList movieList = new SelectList(getMovieList, "MovieId", "NameOfMovie"); * ViewBag.movielistname = movieList;*/ var movieShoving = new MovieShoving(); if (model == null) { return(View()); } if (ModelState.IsValid) { movieShoving.Id = model.Id; movieShoving.CinemaId = model.CinemaId; movieShoving.MovieId = model.MovieId; movieShoving.FromDate = model.FromDate; movieShoving.ToDate = model.ToDate; _context.MovieShovings.Add(movieShoving); _context.Entry(movieShoving).State = EntityState.Added; _context.SaveChanges(); ModelState.Clear(); var rows = _context.RowSeats.ToList(); foreach (var row in rows) { var entity = new MovieSeats { RowSeatId = row.Id, RefSeatStatusId = _context.RefSeatStatuses.FirstOrDefault(x => x.SeatStatus.Equals(false)).Id, MovieId = model.MovieId, DateMovie = model.FromDate }; _context.MovieSeatses.Add(entity); _context.SaveChanges(); } } return(View()); }
public ActionResult Delete(int id, MovieShoving movie1) { try { MovieShoving movie = _context.MovieShovings.Where(m => m.Id == id).FirstOrDefault(); _context.Entry(movie).State = EntityState.Deleted; _context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View(movie1)); } }
public ActionResult Delete(int id) { var model = new MovieShoving(); var result = _context.MovieShovings.FirstOrDefault(x => x.Id.Equals(id)); if (result == null) { return(HttpNotFound()); } model.Id = result.Id; model.MovieId = result.MovieId; model.CinemaId = result.CinemaId; model.FromDate = result.FromDate; model.ToDate = result.ToDate; return(View(model)); }