Ejemplo n.º 1
0
        public ActionResult DeleteTicket(int?pid, int tid)
        {
            if (pid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PassengerTicketView PTV = new PassengerTicketView
            {
                Passenger = db.Passengers.Include(c => c.ApplicationUser).Include(c => c.Tickets).SingleOrDefault(c => c.Id == pid),
                Ticket    = db.Tickets.Include(c => c.Payment).Include(c => c.Trip).Include(c => c.Trip.Bus).Include(c => c.Trip.Line).SingleOrDefault(c => c.Id == tid),
                Seats     = db.Seats.Include(c => c.Passenger).Where(c => c.PassengerId == pid)
            };

            if (PTV == null)
            {
                return(HttpNotFound());
            }

            foreach (var Seat in PTV.Seats)
            {
                db.Seats.Remove(Seat);
            }

            db.Tickets.Remove(PTV.Ticket);

            db.SaveChanges();

            //Here We should write Mail Notification Function contain the State of the ticket

            return(RedirectToAction("ViewPassenger", new { pid = pid }));
        }
Ejemplo n.º 2
0
        public IHttpActionResult BlockTicket(int?pid, int tid)
        {
            if (pid == null)
            {
                return(NotFound());
            }
            PassengerTicketView PTV = new PassengerTicketView
            {
                Passenger = db.Passengers.Include(c => c.ApplicationUser).Include(c => c.Tickets).SingleOrDefault(c => c.Id == pid),
                Ticket    = db.Tickets.Include(c => c.Payment).Include(c => c.Trip).Include(c => c.Trip.Bus).Include(c => c.Trip.Line).SingleOrDefault(c => c.Id == tid)
            };

            if (PTV == null)
            {
                return(NotFound());
            }
            if (PTV.Ticket.IsBlocked)
            {
                PTV.Ticket.IsBlocked = false;
                IEnumerable <Seat> Seats = db.Seats.Where(c => c.PassengerId == pid);
                foreach (var Seat in Seats)
                {
                    Seat.IsAvailable = false;
                }
            }
            else
            {
                PTV.Ticket.IsBlocked = true;
                IEnumerable <Seat> Seats = db.Seats.Where(c => c.PassengerId == pid);
                foreach (var Seat in Seats)
                {
                    Seat.IsAvailable = true;
                }
            }
            db.SaveChanges();


            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(User.Identity.GetUserName());
                mail.Subject = "Block Booking Test";

                SmtpServer.Port = 587;
                SmtpServer.UseDefaultCredentials = true;
                SmtpServer.Credentials           = new System.Net.NetworkCredential("", "");
                SmtpServer.EnableSsl             = true;
                SmtpServer.Send(mail);
            }
            catch
            {
                return(Ok());
            }


            //Here We should write Mail Notification Function contain the State of the ticket
            return(Ok());
        }
Ejemplo n.º 3
0
        public ActionResult ViewTicket(int?pid, int tid)
        {
            if (pid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PassengerTicketView PTV = new PassengerTicketView
            {
                Passenger = db.Passengers.Include(c => c.ApplicationUser).Include(c => c.Tickets).SingleOrDefault(c => c.Id == pid),
                Ticket    = db.Tickets.Include(c => c.Payment).Include(c => c.Trip).Include(c => c.Trip.Bus).Include(c => c.Trip.Line).SingleOrDefault(c => c.Id == tid),
                Seats     = db.Seats.Include(c => c.Passenger).Where(c => c.PassengerId == pid)
            };

            if (PTV == null)
            {
                return(HttpNotFound());
            }
            return(View(PTV));
        }
Ejemplo n.º 4
0
        public ActionResult CancelBooking(int pid, int tid)
        {
            if (pid == 0 || tid == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            PassengerTicketView PTV = new PassengerTicketView
            {
                Passenger = db.Passengers.Include(c => c.ApplicationUser).Include(c => c.Tickets).SingleOrDefault(c => c.Id == pid),
                Ticket    = db.Tickets.Include(c => c.Payment).Include(c => c.Trip).Include(c => c.Trip.Line).Include(c => c.Trip.Bus).Include(c => c.Trip.Bus.BookedSeats).Single(c => c.Id == tid),
                Seats     = db.Seats.Include(c => c.Passenger).Where(c => c.PassengerId == pid)
            };

            if (PTV.Passenger == null || PTV.Ticket == null || PTV.Seats == null)
            {
                return(HttpNotFound());
            }
            //Delete All Seats Before Ticket
            foreach (var Seat in PTV.Seats)
            {
                if (PTV.Ticket.Trip.Bus.BookedSeats.Contains(Seat))
                {
                    db.Seats.Remove(Seat);
                }
            }

            if (PTV.Passenger.Tickets.Count == 1)
            {
                //34an lw mfe4 8er el ticket de w at3mlha Delete yrg3 tany User Not Passenger
                db.Tickets.Remove(PTV.Ticket);
                db.Passengers.Remove(PTV.Passenger);
            }
            else
            {
                db.Tickets.Remove(PTV.Ticket);
            }

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public ActionResult BlockTicket(int?pid, int tid)
        {
            if (pid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PassengerTicketView PTV = new PassengerTicketView
            {
                Passenger = db.Passengers.Include(c => c.ApplicationUser).Include(c => c.Tickets).SingleOrDefault(c => c.Id == pid),
                Ticket    = db.Tickets.Include(c => c.Payment).Include(c => c.Trip).Include(c => c.Trip.Bus).Include(c => c.Trip.Line).SingleOrDefault(c => c.Id == tid)
            };

            if (PTV == null)
            {
                return(HttpNotFound());
            }
            if (PTV.Ticket.IsBlocked)
            {
                PTV.Ticket.IsBlocked = false;
                IEnumerable <Seat> Seats = db.Seats.Where(c => c.PassengerId == pid);
                foreach (var Seat in Seats)
                {
                    Seat.IsAvailable = false;
                }
            }
            else
            {
                PTV.Ticket.IsBlocked = true;
                IEnumerable <Seat> Seats = db.Seats.Where(c => c.PassengerId == pid);
                foreach (var Seat in Seats)
                {
                    Seat.IsAvailable = true;
                }
            }
            db.SaveChanges();

            //Here We should write Mail Notification Function contain the State of the ticket

            return(RedirectToAction("ViewTicket", new { pid = pid, tid = tid }));
        }
Ejemplo n.º 6
0
        public ActionResult Ticket(int pid, int tid, int trip)
        {
            //W ynf3 y3dl el feedback aw y3mlo Delete
            //Hyb2a Fe 3 Bottuns Add/Edit/Delete FeedBack, Add Seat and Delete if it not expired
            //Hyb2a Fe 3 Bottuns Add/Edit/Delete FeedBack if it expired
            if (pid == 0 || tid == 0 || trip == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PassengerTicketView PUTV = new PassengerTicketView
            {
                Passenger = db.Passengers.Include(c => c.ApplicationUser).Include(c => c.Tickets).SingleOrDefault(c => c.Id == pid),
                Ticket    = db.Tickets.Include(c => c.Payment).Include(c => c.Trip).Include(c => c.Trip.Bus).Include(c => c.Trip.Bus.Driver).Include(c => c.Trip.Line).SingleOrDefault(c => c.Id == tid),
                Seats     = db.Seats.Include(cc => cc.Passenger).Where(cc => cc.PassengerId == pid),
                Feedbacks = db.Feedbacks.Include(c => c.PassengerId).Include(c => c.TripId).Where(c => c.PassengerId.Id == pid && c.TripId.Id == trip)
            };

            if (PUTV.Passenger == null || PUTV.Ticket == null)
            {
                return(HttpNotFound());
            }

            return(View(PUTV));
        }
        public IHttpActionResult CancelBooking(int pid, int tid)
        {
            if (pid == 0 || tid == 0)
            {
                return(BadRequest());
            }

            PassengerTicketView PTV = new PassengerTicketView
            {
                Passenger = db.Passengers.Include(c => c.ApplicationUser).Include(c => c.Tickets).SingleOrDefault(c => c.Id == pid),
                Ticket    = db.Tickets.Include(c => c.Payment).Include(c => c.Trip).Include(c => c.Trip.Line).Include(c => c.Trip.Bus).Include(c => c.Trip.Bus.BookedSeats).Single(c => c.Id == tid),
                Seats     = db.Seats.Include(c => c.Passenger).Where(c => c.PassengerId == pid)
            };

            if (PTV.Passenger == null || PTV.Ticket == null || PTV.Seats == null)
            {
                return(NotFound());
            }
            //Delete All Seats Before Ticket
            foreach (var Seat in PTV.Seats)
            {
                if (PTV.Ticket.Trip.Bus.BookedSeats.Contains(Seat))
                {
                    db.Seats.Remove(Seat);
                }
            }

            if (PTV.Passenger.Tickets.Count == 1)
            {
                //34an lw mfe4 8er el ticket de w at3mlha Delete yrg3 tany User Not Passenger
                db.Tickets.Remove(PTV.Ticket);
                db.Passengers.Remove(PTV.Passenger);
            }
            else
            {
                db.Tickets.Remove(PTV.Ticket);
            }

            db.SaveChanges();


            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(User.Identity.GetUserName());
                mail.Subject = "Cancel Booking Test";

                SmtpServer.Port = 587;
                SmtpServer.UseDefaultCredentials = true;
                SmtpServer.Credentials           = new System.Net.NetworkCredential("Email", "Pass");
                SmtpServer.EnableSsl             = true;
                SmtpServer.Send(mail);
            }
            catch
            {
                return(Ok());
            }

            return(Ok());
        }