public ActionResult ChangePrice() { MovieViewModel mvm = new MovieViewModel(); mvm.Movie = new Movie(); MovieDal dal = new MovieDal(); string nameValue = Request.Form["txtMovieName"]; int price = 0; if (Request.Form["MoviePrice"] != null) { price = int.Parse(Request.Form["MoviePrice"]); } if (MovieExist(nameValue)) { Movie addMovie = dal.Movies.First(a => a.mName == nameValue); addMovie.Price = price; dal.SaveChanges(); mvm.Movies = dal.Movies.ToList <Movie>(); return(View(mvm)); } mvm.Movies = dal.Movies.ToList <Movie>(); return(View(mvm)); }
public ActionResult EditMoviePage(Movie m1) {//take us to the edit movie page view - in the edit action we need to chack only if ModelState.IsValid if (ModelState.IsValid) { //connect to db MovieDal dal = new MovieDal(); //get the max value of OrderNum Movie m2 = (from m in dal.movies where m.MovieName == m1.MovieName select m).FirstOrDefault(); //edit movie in db m2.MovieName = m1.MovieName; m2.Type = m1.Type; m2.Description = m1.Description; m2.Link = m1.Link; m2.ImageLink = m1.ImageLink; dal.SaveChanges(); return(RedirectToAction("MovieListPage")); } return(View(m1)); }
public ActionResult Submit() { MovieViewModel mvm = new MovieViewModel(); Movie MyMovie = new Movie() { ID = int.Parse(Request.Form["Movie.ID"]).ToString(), mName = Request.Form["Movie.mName"], mDate = //DateTime.ParseExact(Request.Form["Movie.mDate"], @"MM/dd/yyyy hh:mm:ss", CultureInfo.InvariantCulture), DateTime.Parse(Request.Form["Movie.mDate"]), Price = int.Parse(Request.Form["Movie.Price"]), HallName = Request.Form["Movie.HallName"], Age = int.Parse(Request.Form["Movie.Age"]), Category = Request.Form["Movie.Category"], }; MovieDal dal = new MovieDal(); if (ModelState.IsValid) { dal.Movies.Add(MyMovie); dal.SaveChanges(); mvm.Movie = new Movie(); } else { mvm.Movie = MyMovie; } mvm.Movies = dal.Movies.ToList <Movie>(); return(View("EnterMovie", mvm)); }
public ActionResult SubRemoveMovie(Movie obj) { MovieDal dal = new MovieDal(); TicketDal tdal = new TicketDal(); string name = obj.MovieName.ToString(); string date = obj.date.ToString(); string time = obj.time.ToString(); List <Movie> exist = (from x in dal.Movies where x.MovieName.Equals(name) && x.date.Equals(date) && x.time.Equals(time) select x).ToList <Movie>(); if (exist.Count == 0) { TempData["msg"] = "Movie doesn't exist !!!"; TempData["color"] = "red"; return(View("RemoveMovie", obj)); } string hid = exist[0].HallId; List <Ticket> Texist = (from x in tdal.Tickets where x.MovieName.Equals(name) && x.date.Equals(date) && x.time.Equals(time) && x.HallId.Equals(hid) select x).ToList <Ticket>(); if (Texist.Count != 0) { TempData["msg"] = "You can't remove this movie , someone buy it!!!"; TempData["color"] = "red"; return(View("RemoveMovie", obj)); } dal.Movies.Remove(exist[0]); dal.SaveChanges(); TempData["msg"] = "Movie Removed Successfully !!!"; TempData["color"] = "blue"; return(View("RemoveMovie")); }
public ActionResult UploadFiles(Movie MyMovie, HttpPostedFileBase moviePicture) { if (ModelState.IsValid) { if (ModelState.IsValid) { MovieDal dal = new MovieDal(); MyMovie.moviePicture = moviePicture.FileName; dal.MOVIES.Add(MyMovie); dal.SaveChanges(); } try { //Method 2 Get file details from HttpPostedFileBase class if (moviePicture != null) { string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(moviePicture.FileName)); moviePicture.SaveAs(path); } ViewBag.FileStatus = "File uploaded successfully."; } catch (Exception) { ViewBag.FileStatus = "Error while file uploading.";; } } return(RedirectToAction("NewMovie")); }
public ActionResult DeleteMovie(string id) { using (MovieDal dc = new MovieDal()) { var v = dc.MOVIES.Where(a => a.ID == id).FirstOrDefault(); if (v != null) { dc.MOVIES.Remove(v); dc.SaveChanges(); return(View("ManageMovie")); } } return(View("ManageMovie")); }
public ActionResult RemoveMovie(string MovieName) {//remove the movie with the same name in the db and return us to Movie List Page //connect to db MovieDal dal = new MovieDal(); //get the movie from db Movie m1 = (from m in dal.movies where m.MovieName == MovieName select m).FirstOrDefault(); //remove the movie from db dal.movies.Remove(m1); dal.SaveChanges(); return(RedirectToAction("MovieListPage")); }
public ActionResult Edit(int id, Movie c) { try { using (MovieDal mdb = new MovieDal()) { c.Picture = "~/UploadedFiles/" + c.Picture.ToString(); mdb.Entry(c).State = EntityState.Modified; mdb.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, Movie c) { try { using (MovieDal mdb = new MovieDal()) { Movie m = mdb.Movies.Where(x => x.mid == id).FirstOrDefault(); mdb.Movies.Remove(m); mdb.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View()); } }
public ActionResult PutOnSale(int id, int sale) { try { using (MovieDal mdb = new MovieDal()) { Movie c = mdb.Movies.Where(x => x.mid == id).FirstOrDefault(); c.Sale = sale; mdb.Entry(c).State = EntityState.Modified; mdb.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(Movie c) { c.Picture = "~/UploadedFiles/" + c.Picture.ToString(); using (MovieDal mdb = new MovieDal()) { foreach (Movie movie in mdb.Movies.ToList <Movie>()) { if (movie.Hall == c.Hall && DateTime.Compare(movie.Date, c.Date) == 0) { ViewBag.x = "This DateTime and Hall is choosen allready !"; return(View()); } } } try { using (MovieDal mdb = new MovieDal()) { mdb.Movies.Add(c); mdb.SaveChanges(); using (MostDal modb = new MostDal()) { if (modb.Mosts.ToList <Most>().Where(x => x.Title == c.Title).Count() == 0) { Most m = new Most(); m.Title = c.Title; modb.Mosts.Add(m); modb.SaveChanges(); } } } ViewBag.x = " Movie has been added Succecfully!"; return(RedirectToAction("Index", "User")); } catch { ViewBag.x = "Wrong input!"; return(View()); } }
public ActionResult AddMoviePage(Movie m1) {//take us to the add movie page view bool NameCheck = checkMovieName(m1.MovieName); if (ModelState.IsValid && !NameCheck) { //save date of creating the movie in ouer db m1.Date = DateTime.Now; //connect to db MovieDal dal = new MovieDal(); dal.movies.Add(m1); dal.SaveChanges(); return(RedirectToAction("MovieListPage")); } else if (NameCheck) { ViewBag.message1 = "That movie name already exist"; } return(View(m1)); }
public ActionResult SubAddMovie(Movie obj, MovieImage temp) { MovieDal dal = new MovieDal(); string Hallid = obj.HallId.ToString(); string date = obj.date.ToString(); string time = obj.time.ToString(); List <Movie> exist = (from x in dal.Movies where x.HallId.Equals(Hallid) && x.date.Equals(date) && x.time.Equals(time) select x).ToList <Movie>(); if (exist.Count != 0) { TempData["msg"] = "There is a movie at the same time and the same hall !!!"; TempData["color"] = "red"; return(View("AddMovie", obj)); } HallDal halls = new HallDal(); List <Hall> HallExist = (from x in halls.Halls where x.HallId.Equals(obj.HallId) select x).ToList <Hall>(); if (HallExist.Count == 0) { TempData["msg"] = "Hall not exist !!!"; TempData["color"] = "red"; return(View("AddMovie", obj)); } string filename = Path.GetFileNameWithoutExtension(temp.ImageBytes.FileName); string extension = Path.GetExtension(temp.ImageBytes.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; obj.poster = "~/Images/" + filename; filename = Path.Combine(Server.MapPath("~/Images/"), filename); temp.ImageBytes.SaveAs(filename); dal.Movies.Add(obj); dal.SaveChanges(); TempData["msg"] = "Movie Added Successfully !!!"; TempData["color"] = "blue"; return(View("AddMovie")); }
// GET: Home public ActionResult Index() { //removing ended movies and tickets using (MovieDal mdb = new MovieDal()) { foreach (Movie movie in mdb.Movies.ToList <Movie>()) { int res = DateTime.Compare(movie.Date, DateTime.Now); if (res < 0) { mdb.Movies.Remove(movie); mdb.SaveChanges(); TicketDal tdb = new TicketDal(); foreach (Ticket t in tdb.Tickets.ToList <Ticket>()) { if (t.Movietitle == movie.Title && t.Hall == movie.Hall && DateTime.Compare(movie.Date, t.Date) == 0) { tdb.Tickets.Remove(t); tdb.SaveChanges(); } } } } } //creating id for user if (Session["idUser"] == null) { Random rnd = new Random(); int id = rnd.Next(1000); Session["idUser"] = id; } using (MovieDal mdb = new MovieDal()) { return(View("Home", mdb.Movies.ToList <Movie>().Where(x => x.Sale == null))); } }
public ActionResult SubMangingPrices(Movie obj) { MovieDal dal = new MovieDal(); string name = obj.MovieName.ToString(); string date = obj.date.ToString(); string time = obj.time.ToString(); List <Movie> exist = (from x in dal.Movies where x.MovieName.Equals(name) && x.date.Equals(date) && x.time.Equals(time) select x).ToList <Movie>(); if (exist.Count == 0) { TempData["msg"] = "Movie doesn't exist !!!"; TempData["color"] = "red"; return(View("ManagingPrices", obj)); } string price = exist[0].price; exist[0].price = obj.price; exist[0].preprice = price; dal.SaveChanges(); TempData["msg"] = "Movie price updated successfully !!!"; TempData["color"] = "blue"; return(View("RemoveMovie")); }
public ActionResult DeleteMovie() { MovieViewModel mvm = new MovieViewModel(); mvm.Movie = new Movie(); MovieDal dal = new MovieDal(); string nameValue = Request.Form["txtMovieName"]; if (MovieExist(nameValue)) { Movie delMovie = new Movie { mName = nameValue }; dal.Movies.Attach(delMovie); dal.Movies.Remove(delMovie); dal.SaveChanges(); mvm.Movies = dal.Movies.ToList <Movie>(); return(View(mvm)); } mvm.Movies = dal.Movies.ToList <Movie>(); return(View(mvm)); }
public ActionResult Save(Movie emp) { bool status = false; if (ModelState.IsValid) { using (MovieDal dc = new MovieDal()) { if (emp.ID != null) { //Edit var v = dc.MOVIES.Where(a => a.ID == emp.ID).FirstOrDefault(); if (v != null) { v.moviePicture = emp.moviePicture; v.name = emp.name; v.price = emp.price; v.SALLE = emp.SALLE; v.showtime = emp.showtime; v.ageLimitation = emp.ageLimitation; } } else { //Save dc.MOVIES.Add(emp); } dc.SaveChanges(); status = true; return(View("ManageMovie")); } } return(new JsonResult { Data = new { status = status } }); }
public ActionResult SubManagingHalls(Movie obj) { TicketDal dal = new TicketDal(); MovieDal Mdal = new MovieDal(); string name = obj.MovieName.ToString(); string date = obj.date.ToString(); string time = obj.time.ToString(); string New_hall = obj.HallId.ToString(); List <Movie> Mexist = (from x in Mdal.Movies where x.MovieName.Equals(name) && x.date.Equals(date) && x.time.Equals(time) select x).ToList <Movie>(); if (Mexist.Count == 0) { TempData["msg"] = "Movie doesn't exist !!!"; TempData["color"] = "red"; return(View("ManagingHalls", obj)); } string Old_hall = Mexist[0].HallId; List <Ticket> exist = (from x in dal.Tickets where x.MovieName.Equals(name) && x.date.Equals(date) && x.time.Equals(time) && x.HallId.Equals(Old_hall) select x).ToList <Ticket>(); if (exist.Count != 0) { TempData["msg"] = "You cant change movie hall , Someone buy ticket for this movie !!!"; TempData["color"] = "red"; return(View("ManagingHalls", obj)); } HallDal halls = new HallDal(); List <Hall> HallExist = (from x in halls.Halls where x.HallId.Equals(New_hall) select x).ToList <Hall>(); if (HallExist.Count == 0) { TempData["msg"] = "Hall not exist !!!"; TempData["color"] = "red"; return(View("ManagingHalls", obj)); } List <Movie> NewExist = (from x in Mdal.Movies where x.date.Equals(date) && x.time.Equals(time) && x.HallId.Equals(New_hall) select x).ToList <Movie>(); if (NewExist.Count != 0) { TempData["msg"] = "There is a movie at the same time and the same hall !!!"; TempData["color"] = "red"; return(View("ManagingHalls", obj)); } Mdal.Movies.Remove(Mexist[0]); obj.poster = Mexist[0].poster; obj.age = Mexist[0].age; obj.price = Mexist[0].price; obj.preprice = Mexist[0].preprice; obj.category = Mexist[0].category; Mdal.Movies.Add(obj); Mdal.SaveChanges(); List <Movie> ms = (from x in Mdal.Movies where x.MovieName.Equals(name) && x.date.Equals(date) && x.time.Equals(time) && x.HallId.Equals(New_hall) select x).ToList <Movie>(); foreach (Ticket t in exist) { t.MovieId = ms[0].id; } dal.SaveChanges(); TempData["msg"] = "Movie hall updated successfully !!!"; TempData["color"] = "blue"; return(View("ManagingHalls")); }