Пример #1
0
        public SelectList GetAllTicketSeats(int SelectedShowing)
        {
            Showing       showing  = db.Showings.Find(SelectedShowing);
            List <Ticket> tickets  = db.Tickets.Where(t => t.Order.Orderstatus == OrderStatus.Completed && t.Showing.ShowingID == showing.ShowingID).ToList();
            SelectList    selSeats = SeatHelper.FindAvailableSeats(tickets);

            return(selSeats);
        }
Пример #2
0
        public ActionResult Create(int ShowingID)
        {
            Showing show = db.Showings.Find(ShowingID);

            Ticket tic = new Ticket();

            tic.Showing = show;

            AppUser user        = db.Users.Find(User.Identity.GetUserId());
            Decimal TicketPrice = Utilities.GenerateTicketPrice.GetTicketPrice(show.StartTime);


            if (show.SpecialEventStatus == SpecialEvent.NotSpecial)
            {
                //sets senior citizen discount
                //TODO: Add logic for only allowing discount for 2 tickets per transaction
                if ((DateTime.Now.Year - user.Birthday.Year) >= 60)
                {
                    TicketPrice           = TicketPrice - 2;
                    ViewBag.SeniorCitizen = "$2 Senior Citizen Discount Applied";
                }
                else
                {
                    ViewBag.SeniorCitizen = "No Discount";
                }

                //vars for determining time between now and showing start time
                TimeSpan TimeBetween = (show.StartTime - DateTime.Now);

                //sets discount if ticket is purchased 48 hours in advance
                if ((TimeBetween.TotalHours >= 48))
                {
                    TicketPrice     = TicketPrice - 1;
                    ViewBag.Advance = "$1 Discount for Purchasing Early";
                }
                else
                {
                    ViewBag.Advance = "No Discount";
                }
            }

            tic.TicketPrice = TicketPrice;

            ViewBag.AllSeats = SeatHelper.FindAvailableSeats(show.Tickets, User.Identity.GetUserId());
            return(View(tic));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "TicketID,Seat,TicketPrice")] Ticket tic, Int32 ShowingID, Int32 SelectedSeat)
        {
            Showing show = db.Showings.Find(ShowingID);

            tic.Showing = show;
            AppUser user = db.Users.Find(User.Identity.GetUserId()); //TODO: make sure this is assigned correctly

            //clear existing errors - we know there is no seat
            ModelState.Clear();

            //Add the logic to see what seat they picked
            List <Seat> AllSeats = SeatHelper.GetAllSeats();
            Seat        seat     = AllSeats.FirstOrDefault(s => s.SeatID == SelectedSeat);

            tic.Seat = seat.SeatName;



            //create logic that will not allow overlapping tickets
            List <Ticket> BoughtTickets = db.Tickets.Where(t => t.Order.AppUser.Id == user.Id).ToList();

            foreach (Ticket t in BoughtTickets)
            {
                if ((!(t.Showing.ShowingID == ShowingID)) && (t.Showing.StartTime.Day == tic.Showing.StartTime.Day))
                {
                    if (t.Showing.StartTime.Add(t.Showing.EndTime - t.Showing.StartTime) > tic.Showing.StartTime && (tic.Showing.EndTime > t.Showing.StartTime))
                    {
                        //ViewBag.OverlappingTicketMessage = "Error: Overlapping Movies. Select another showing.";
                        return(View("Error", new string[] { "Cannot buy overlapping Tickets!!" }));
                    }
                }
            }
            //Order LastOrder = db.Orders.LastOrDefault(o => o.AppUser.Id == UserId);
            TimeSpan eighteenYears = new TimeSpan(24 * 365 * 18, 0, 0);

            if ((DateTime.Now - user.Birthday) < eighteenYears)
            {
                if (tic.Showing.Movie.MPAARating == MPAARating.R || tic.Showing.Movie.MPAARating == MPAARating.NC17)
                {
                    return(View("Error", new string[] { "Need to be 18 years old to see the Movie!!" }));
                }
            }


            /////////////////////////

            //double-check everything is okay now that we've added seat
            ValidateModel(tic);

            //*******  Shouldn't need this section, right? ************
            Decimal TicketPrice = Utilities.GenerateTicketPrice.GetTicketPrice(show.StartTime);

            if (show.SpecialEventStatus == SpecialEvent.NotSpecial)
            {
                //sets senior citizen discount
                //TODO: Add logic for only allowing discount for 2 tickets per transaction
                if ((DateTime.Now.Year - user.Birthday.Year) >= 60)
                {
                    TicketPrice = TicketPrice - 2;
                    tic.SeniorCitizenDiscount = "$2 Senior Citizen Discount Applied";
                }
                else
                {
                    tic.SeniorCitizenDiscount = "No Discount";
                }

                //vars for determining time between now and showing start time
                TimeSpan TimeBetween = (show.StartTime - DateTime.Now);

                //sets discount if ticket is purchased 48 hours in advance
                if ((TimeBetween.TotalHours >= 48))
                {
                    TicketPrice       = TicketPrice - 1;
                    tic.EarlyDiscount = "$1 Discount for Purchasing Early";
                }
                else
                {
                    tic.EarlyDiscount = "No Discount";
                }
            }

            tic.TicketPrice = TicketPrice;

            // ********************************************************

            if (ModelState.IsValid)
            {
                db.Tickets.Add(tic);
                db.SaveChanges();
                String UserId = User.Identity.GetUserId();

                //These six lines replace the next commented out line (Order LastOrder...)
                List <Order> TempOrdersList = db.Orders.Where(o => o.AppUser.Id == UserId).ToList();
                Order        LastOrder;
                if (TempOrdersList.Count() != 0)
                {
                    LastOrder = TempOrdersList.Last();
                }
                else
                {
                    LastOrder = null;
                }



                //Redirects the user to Orders/Create if the order is null or completed
                if (LastOrder == null || LastOrder.Status == OrderStatus.Complete || LastOrder.Status == OrderStatus.Cancelled)
                {
                    return(RedirectToAction("Create", "Orders", new { TicketID = tic.TicketID }));
                }

                //Redirects the user to Orders/Details if the order has not been completed (they are adding more tickets to the order)
                else
                {
                    LastOrder.Tickets.Add(tic);
                    db.SaveChanges();
                    return(RedirectToAction("Details", "Orders", new { OrderID = LastOrder.OrderID }));
                }
            }

            ViewBag.AllSeats = SeatHelper.FindAvailableSeats(tic.Showing.Tickets, User.Identity.GetUserId());
            return(View(tic));
        }