Esempio n. 1
0
        public void TestMethod3()
        {
            int expected = 280;
            List <ProductToBuy> listProduct          = new List <ProductToBuy>();
            PriceCalculation    priceCalculation     = new PriceCalculation();
            ProductToBuy        productToBuy         = new ProductToBuy();
            JSONParser          parser               = new JSONParser();
            dynamic             promotionEngineModel = parser.ParseJSON();

            priceCalculation.UnitPrice        = promotionEngineModel.UnitPrice;
            priceCalculation.ActivePromotions = promotionEngineModel.ActivePromotions;


            productToBuy.ProuductName    = "A";
            productToBuy.ProductQuantity = 3;
            listProduct.Add(productToBuy);

            productToBuy = new ProductToBuy();
            productToBuy.ProuductName    = "B";
            productToBuy.ProductQuantity = 5;
            listProduct.Add(productToBuy);

            productToBuy = new ProductToBuy();
            productToBuy.ProuductName    = "C";
            productToBuy.ProductQuantity = 1;
            listProduct.Add(productToBuy);

            productToBuy = new ProductToBuy();
            productToBuy.ProuductName    = "D";
            productToBuy.ProductQuantity = 1;
            listProduct.Add(productToBuy);

            int actual = priceCalculation.GetTotalPrice(listProduct);

            Assert.AreEqual(expected, actual, "Test Method 3 failed");
        }
Esempio n. 2
0
        public ActionResult FlightBooking(FlightBookingViewModel model, string[] Name, string[] Gender, string[] Nationality, string[] DOB, string btnProceed, string btnSubmit)
        {
            string seats = Request.Form["SeatsSelected"];

            string[] seat = seats.Split(new char[] { ',' });

            if (!String.IsNullOrEmpty(btnProceed))
            {
                string bookedSeats = String.Join(",", (from b in db.Booking_Detail
                                                       join s in db.Seat_Detail on b.BookingID equals s.BookingID
                                                       where b.FlightID == model.flightID
                                                       select s.SeatID).ToArray());
                ViewBag.BookedSeats   = bookedSeats;
                ViewBag.SelectedSeats = seats;

                var flightDetail = (from f in db.Flight_Detail where f.FlightID == model.flightID select f).FirstOrDefault();
                var priceList    = (from p in db.Pricings where p.FlightID == model.flightID select p).ToList();

                var firstClassPriceList    = (from pl in priceList where pl.ClassCategory == "First" select pl).OrderBy(x => x.Price).ToList();
                var businessClassPriceList = (from pl in priceList where pl.ClassCategory == "Business" select pl).OrderBy(x => x.Price).ToList();
                var economyClassPriceList  = (from pl in priceList where pl.ClassCategory == "Economy" select pl).OrderBy(x => x.Price).ToList();

                model.numberOfSelectedSeats  = seat.Length;
                model.bookedSeats            = seat;
                model.flightDetail           = flightDetail;
                model.firstClassPriceList    = firstClassPriceList;
                model.businessClassPriceList = businessClassPriceList;
                model.economyClassPriceList  = economyClassPriceList;
                ViewBag.Disable = "disable";
            }

            if (!String.IsNullOrEmpty(btnSubmit))
            {
                Guid sessionUserID = new Guid(User.Identity.Name.Split('|')[1].ToString());

                PriceCalculation priceCalculation = new PriceCalculation();

                Booking_Detail bookingDetail = new Booking_Detail()
                {
                    BookingID          = Guid.NewGuid(),
                    FlightID           = model.flightID,
                    BookedByCustomerID = sessionUserID,
                    Amount             = priceCalculation.GetTotalPrice(DOB, seat, model.flightID),
                    BookingDateTime    = DateTime.Now
                };
                db.Booking_Detail.Add(bookingDetail);
                db.SaveChanges();

                for (int i = 0; i < seat.Length; i++)
                {
                    Seat_Detail seatDetail = new Seat_Detail()
                    {
                        TicketID  = Guid.NewGuid(),
                        BookingID = bookingDetail.BookingID,
                        SeatID    = Convert.ToInt16(seat[i])
                    };
                    db.Seat_Detail.Add(seatDetail);
                    db.SaveChanges();

                    Passenger passenger = new Passenger()
                    {
                        PassengerID = Guid.NewGuid(),
                        Name        = Name[i],
                        Gender      = Gender[i],
                        DOB         = Convert.ToDateTime(DOB[i]),
                        Nationality = Nationality[i],
                        TicketID    = seatDetail.TicketID
                    };
                    db.Passengers.Add(passenger);
                    db.SaveChanges();
                }
                return(RedirectToAction("Home", "Customer"));
            }
            return(View(model));
        }