コード例 #1
0
        public ActionResult ConfirmReservation(int movieID, int saloonID, int sessionID, int genreID, string ticketPrice, string seats)
        {
            decimal toBeConverted = Convert.ToDecimal(ticketPrice);

            var query = _saleRep.FirstOrDefault(x => x.MovieID == movieID && x.SessionID == sessionID && x.GenreID == genreID && x.TicketPrice == toBeConverted);

            ViewBag.Seats = seats;
            if (query == null)
            {
                int userID = 0;

                if (Session["member"] != null)
                {
                    userID = (Session["member"] as AppUser).ID;
                }
                else if (Session["vip"] != null)
                {
                    userID = (Session["vip"] as AppUser).ID;
                }

                Sale toBeAdded = new Sale()
                {
                    AppUserID   = userID,
                    MovieID     = movieID,
                    SessionID   = sessionID,
                    GenreID     = genreID,
                    Type        = ENTITIES.Enums.PaymentType.JustReservation,
                    SaleType    = ENTITIES.Enums.SaleType.Reservation,
                    TicketPrice = Convert.ToDecimal(ticketPrice)
                };
                _saleRep.Add(toBeAdded);

                string[] selectedSeats = seats.Trim().Split(':');

                List <SeatListVM> characterNumber = new List <SeatListVM>();

                for (int i = 0; i < selectedSeats.Length; i++)
                {
                    string[] seat = selectedSeats[i].Split('-');
                    characterNumber.Add(new SeatListVM {
                        Character = seat[0], Number = Convert.ToInt32(seat[1])
                    });
                }

                foreach (SeatListVM item in characterNumber)
                {
                    Seat result = _sRep.FirstOrDefault(x => x.SaloonID == saloonID && x.SessionID == sessionID && x.Character == item.Character && x.Number == item.Number);
                    result.SeatActive = true;
                    _saleSeatRep.Add(new SaleSeat {
                        SaleID = toBeAdded.ID, SeatID = result.ID
                    });
                    _sRep.Update(result);
                }


                SaleResvervationTicketVM srtvm = new SaleResvervationTicketVM()
                {
                    MovieName   = toBeAdded.Movie.MovieName,
                    TicketPrice = Convert.ToDecimal(ticketPrice),
                    SalonID     = saloonID,
                    SaleNo      = toBeAdded.SaleNo,
                    TicketDate  = (_sesRep.FirstOrDefault(x => x.ID == sessionID)).Time
                };


                return(View(srtvm));
            }
            else
            {
                SaleResvervationTicketVM svtvm = new SaleResvervationTicketVM()
                {
                    MovieName   = query.Movie.MovieName,
                    TicketPrice = Convert.ToDecimal(ticketPrice),
                    SalonID     = saloonID,
                    SaleNo      = query.SaleNo,
                    TicketDate  = (_sesRep.FirstOrDefault(x => x.ID == sessionID)).Time
                };


                return(View(svtvm));
            }
        }