// ----------------------------- this view is only for static run (TEMP VIEW)
        public ActionResult HotelCheckout()
        {
            List <RoomVM> rooms = new List <RoomVM>();
            RoomVM        room1 = new RoomVM()
            {
                roomPrice       = 250.22,
                roomDescription = "bla bla bla blabla bla bla bla",
                roomComposition = "Single"
            };
            RoomVM room2 = new RoomVM()
            {
                roomPrice       = 581.85,
                roomDescription = "bla bla bla bla",
                roomComposition = "Adult + 2 Children"
            };

            rooms.Add(room1);
            rooms.Add(room2);
            rooms.Add(new RoomVM()); // always pass 3 rooms

            HotelCheckoutVM hotelCheckoutVM = new HotelCheckoutVM()
            {
                hotelName     = "Globales Acis Y Galatea",
                numberOfRooms = 2,
                room          = rooms,
                startDate     = "15.06.2018",
                endDate       = "18.06.2018",
                hotelAddress  = "Galatea 6 Madrid"
            };

            return(View(hotelCheckoutVM));
        }
        public ActionResult SubmitRoomComposition(HotelOrderDetailsVM rc)
        {
            List <RoomVM> rooms = new List <RoomVM>();
            RoomVM        room1 = new RoomVM()
            {
                roomPrice       = rc.roomPrice1,
                roomDescription = rc.roomType1,
                roomComposition = rc.roomComposition1
            };
            RoomVM room2 = new RoomVM()
            {
                roomPrice       = rc.roomPrice2,
                roomDescription = rc.roomType2,
                roomComposition = rc.roomComposition2
            };
            RoomVM room3 = new RoomVM()
            {
                roomPrice       = rc.roomPrice3,
                roomDescription = rc.roomType3,
                roomComposition = rc.roomComposition3
            };

            rooms.Add(room1);
            rooms.Add(room2);
            rooms.Add(room3); // always pass 3 rooms

            HotelCheckoutVM hotelCheckoutVM = new HotelCheckoutVM()
            {
                hotelName     = rc.hotelName,
                numberOfRooms = rc.numberOfRooms,
                room          = rooms,
                startDate     = rc.startDate,
                endDate       = rc.endDate,
                hotelAddress  = rc.address
            };

            return(View("HotelCheckout", hotelCheckoutVM));
        }
        public ActionResult SubmitOrder(HotelCheckoutVM hc)
        {
            DataLayer dl = new DataLayer();

            DateTime today        = DateTime.Today;
            string   date         = today.ToString("dd/MM/yyyy").Replace("/", ".");
            double   totalFee     = Convert.ToDouble(hc.totalFee.ToString().Substring(1, hc.totalFee.Length - 1));
            bool     sameCustomer = false;
            List <HotelOrderDetails> hotelOrderDetailsList = new List <HotelOrderDetails>();

            // first check if customer already exists in table
            List <Customer> customerFromDB = (from u in dl.customers
                                              where u.Email.ToLower() == hc.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 != hc.customerName || customerFromDB[0].ID != hc.id)
                {
                    TempData["error"] = "This email address already exist in our records with different name and/or different id!";
                    return(View("HotelCheckout", hc));
                }
                else if (customerFromDB[0].Location != hc.address || customerFromDB[0].PhoneNumber != hc.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;
                }
            }

            string[] destination = hc.destination.Split(',');
            string   destCountry = destination[1];

            if (destination[1][0] == ' ')
            {
                destCountry = destination[1].Substring(1, destination[1].Length - 1);
            }

            Order order = new Order()
            {
                CreditCard       = hc.creditCard,
                CustomerEmail    = hc.email,
                OrderDate        = date,
                Status           = 0,
                TotalPayment     = totalFee,
                Type             = "Hotel",
                OrderDestination = destCountry,
            };

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

            HotelOrder hotelOrder = new HotelOrder()
            {
                InvoiceID  = INVOICE,
                StartDate  = hc.startDate,
                EndDate    = hc.endDate,
                HotelName  = hc.hotelName,
                NumOfRooms = hc.numberOfRooms,
                Reviewed   = 0,
            };

            dl.hotelOrders.Add(hotelOrder); // adding in memory and not to DB //

            for (int i = 0; i < hc.numberOfRooms; ++i)
            {
                HotelOrderDetails hotelOrderDetails = new HotelOrderDetails()
                {
                    RoomType        = hc.room[i].roomDescription,
                    PaymentForRoom  = hc.room[i].roomPrice,
                    RoomComposition = hc.room[i].roomComposition,
                    Invoice         = INVOICE
                };
                //hotelOrderDetailsList.Add(hotelOrderDetails);
                dl.hotelOrderDetails.Add(hotelOrderDetails); // adding in memory and not to DB //
            }

            if (!sameCustomer)
            {
                Customer customer = new Customer()
                {
                    Email       = hc.email,
                    FullName    = hc.customerName,
                    Location    = hc.location,
                    ID          = hc.id,
                    PhoneNumber = hc.phone
                };

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

            dl.SaveChanges();

            // create object to sent to recipt view

            return(RedirectToAction("ViewOrderReceipt", "Support", new { invoice = INVOICE }));
        }