public ActionResult AddMovie(Movie movie)
        {
            string fileName = Path.GetFileName(movie.ImageFile.FileName);

            movie.MovieImage = "~/MovieImages/" + fileName;
            fileName         = Path.Combine(Server.MapPath("~/MovieImages/"), fileName);
            movie.ImageFile.SaveAs(fileName);
            ModelState.Clear();
            if (ModelState.IsValid)
            {
                db.Movies.Add(movie);
                db.SaveChanges();
                return(RedirectToAction("MovieList"));
            }
            return(View(movie));
        }
        public ActionResult SelectSeats(int[] SeatNo)
        {
            if (ModelState.IsValid)
            {
                Booking booking = new Booking();
                booking.UserId  = Convert.ToInt32(Session["UserId"]);
                booking.ShowId  = Convert.ToInt32(Session["ShowId"]);
                booking.MovieId = Convert.ToInt32(Session["MovieId"]);
                db.Bookings.Add(booking);
                db.SaveChanges();
                Booking     book        = db.Bookings.Where(m => m.UserId == booking.UserId && m.ShowId == booking.ShowId && m.MovieId == booking.MovieId).OrderByDescending(m => m.BookingId).FirstOrDefault();
                SeatBooking seatBooking = new SeatBooking();
                for (int i = 0; i < SeatNo.Length; i++)
                {
                    seatBooking.BookingId = book.BookingId;
                    seatBooking.SeatId    = SeatNo[i];
                    db.SeatBookings.Add(seatBooking);
                    db.SaveChanges();
                }
                var message = new MailMessage();
                message.To.Add(new MailAddress(Convert.ToString(Session["UserEmail"])));
                message.From       = new MailAddress("*****@*****.**");
                message.Subject    = "Movie Tickets Booked";
                message.Body       = "Your seats have been booked. Thank you for booking.";
                message.IsBodyHtml = true;

                using (var smtp = new SmtpClient())
                {
                    var credential = new NetworkCredential
                    {
                        UserName = "******",
                        Password = "******"
                    };
                    smtp.Credentials = credential;
                    smtp.Host        = "smtp.gmail.com";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = true;
                    smtp.Send(message);
                }
                return(RedirectToAction("MyBooking"));
            }
            return(View());
        }
Пример #3
0
 public ActionResult Register(User user)
 {
     if (ModelState.IsValid)
     {
         db.Users.Add(user);
         db.SaveChanges();
         return(RedirectToAction("Login", "Auth"));
     }
     return(View(user));
 }