Ejemplo n.º 1
0
        // ----------------------------- this view is only for static run (TEMP VIEW)
        public ActionResult FlightCheckout()
        {
            FlightCheckoutVM objToPass = new FlightCheckoutVM()
            {
                departureFlightNumber = "150",
                returnFlightNumber    = "151",
                departureDate         = "15.06.2018",
                returnDate            = "25.06.2018",
                departureLocation     = "Tel Aviv",
                returnLocation        = "London",
                numberOfTickets       = 5,
                babies           = 1,
                children         = 1,
                youngsters       = 1,
                adults           = 2,
                pensioners       = 0,
                price_babies     = "40.00",
                price_children   = "60.00",
                price_youngsters = "120.00",
                price_adults     = "100.00",
                price_pensioners = "90.00",
                airline          = "LY",
                totalFee         = "420.00",
            };

            return(View(objToPass));
        }
Ejemplo n.º 2
0
        public ActionResult SubmitFlightComposition(FlightInfoVM obj)
        {
            string[] temp_composition = obj.composition.Split(',');
            int      size             = temp_composition.Length;

            int[]    composition       = new int[size];
            string[] composition_price = new string[size];
            for (int i = 0; i < size; ++i)
            {
                composition[i] = int.Parse(temp_composition[i]);
            }

            composition_price[0] = (Math.Round(double.Parse(obj.price) * 0.4, 2)).ToString();
            composition_price[1] = (Math.Round(double.Parse(obj.price) * 0.6, 2)).ToString();
            composition_price[2] = (Math.Round(double.Parse(obj.price) * 1.2, 2)).ToString();
            composition_price[3] = (Math.Round(double.Parse(obj.price) * 1, 2)).ToString();
            composition_price[4] = (Math.Round(double.Parse(obj.price) * 0.8, 2)).ToString();

            FlightCheckoutVM objToPass = new FlightCheckoutVM()
            {
                destCountry           = obj.destinationCountry,
                departureFlightNumber = obj.outbound.FlightNumber,
                returnFlightNumber    = obj.inbound.FlightNumber,
                departureDate         = obj.departureDate,
                returnDate            = obj.returnDate,
                departureLocation     = obj.originCity,
                returnLocation        = obj.destinationCity,
                numberOfTickets       = composition[0] + composition[1] + composition[2] + composition[3] + composition[4],
                babies           = composition[0],
                children         = composition[1],
                youngsters       = composition[2],
                adults           = composition[3],
                pensioners       = composition[4],
                price_babies     = composition_price[0],
                price_children   = composition_price[1],
                price_youngsters = composition_price[2],
                price_adults     = composition_price[3],
                price_pensioners = composition_price[4],
                airline          = obj.airline,
                totalFee         = obj.totalPrice,
            };

            return(View("FlightCheckout", objToPass));
        }
Ejemplo n.º 3
0
        public ActionResult SubmitOrder(FlightCheckoutVM obj)
        {
            DataLayer dl = new DataLayer();

            DateTime today        = DateTime.Today;
            string   date         = today.ToString("dd/MM/yyyy").Replace("/", ".");
            double   totalFee     = Convert.ToDouble(obj.totalFee.Replace("$", ""));
            bool     sameCustomer = false;

            // first check if customer already exists in table
            List <Customer> customerFromDB = (from u in dl.customers
                                              where u.Email.ToLower() == obj.email.ToLower()
                                              select u).ToList <Customer>();

            if (customerFromDB.Count != 0) // if customer already exists
            {
                // check if the input is the same as the customer data
                if (customerFromDB[0].FullName != obj.customerName || customerFromDB[0].ID != obj.id)
                {
                    TempData["error"] = "This email address already exist in our records with different name and/or different id!";
                    return(View("FlightCheckout", obj));
                }
                else if (customerFromDB[0].Location != obj.address || customerFromDB[0].PhoneNumber != obj.phone)
                {
                    // update: delete this row and later add new customer row
                    dl.customers.Remove(customerFromDB[0]);
                    dl.SaveChanges();
                }
                // else: same row - no need to update
                else
                {
                    sameCustomer = true;
                }
            }

            // --------------------- create object and save to table 1: Order
            Order order = new Order()
            {
                CreditCard       = obj.creditCard,
                CustomerEmail    = obj.email,
                OrderDate        = date,
                Status           = 0,
                TotalPayment     = totalFee,
                Type             = "Flight",
                OrderDestination = obj.destCountry,
            };

            dl.orders.Add(order); // adding in memory and not to DB //
            dl.SaveChanges();
            int INVOICE = order.InvoiceNumber;

            // --------------------- create object and save to table 2: FlightOrder
            FlightOrder flightOrder = new FlightOrder()
            {
                InvoiceID             = INVOICE,
                DepartureLocation     = obj.departureLocation,
                ArrivalLocation       = obj.returnLocation,
                DepartureDate         = obj.departureDate,
                ReturnDate            = obj.returnDate,
                Outbound_FlightNumber = int.Parse(obj.departureFlightNumber),
                Inbound_FlightNumber  = int.Parse(obj.returnFlightNumber),
                Airline            = obj.airline,
                NumberOfBabies     = obj.babies,
                NumberOfChildren   = obj.children,
                NumberOfYoungsters = obj.youngsters,
                NumberOfAdults     = obj.adults,
                NumberOfPensioners = obj.pensioners,
                PricePerBaby       = double.Parse(obj.price_babies),
                PricePerChild      = double.Parse(obj.price_children),
                PricePerYoungster  = double.Parse(obj.price_youngsters),
                PricePerAdult      = double.Parse(obj.price_adults),
                PricePerPensioner  = double.Parse(obj.price_pensioners),
            };

            dl.flightOrders.Add(flightOrder); // adding in memory and not to DB //

            // --------------------- create object and save to table 3: Customer
            if (!sameCustomer)
            {
                Customer customer = new Customer()
                {
                    Email       = obj.email,
                    FullName    = obj.customerName,
                    Location    = obj.location,
                    ID          = obj.id,
                    PhoneNumber = obj.phone
                };

                dl.customers.Add(customer); // adding in memory and not to DB //
            }

            dl.SaveChanges();

            // go to recipt
            return(RedirectToAction("ViewOrderReceipt", "Support", new { invoice = INVOICE }));
        }