Ejemplo n.º 1
0
        public ActionResult Receipt(string card_type, string card_name, string card_number, string security_number, string expiry_date, string customer_id, string first_name, string last_name, char gender, int age, string email, string phone_number, string address, string city, int vehicle_id, string pickupdate, string dropoffdate, string returncity, string pickupcity)
        {
            ViewData["vehicle_id"] = Request.Params["vehicle_id"];
            ViewData["customer_id"] = Request.Params["customer_id"];
            ViewData["first_name"] = Request.Params["first_name"];
            ViewData["last_name"] = Request.Params["last_name"];
            ViewData["age"] = Request.Params["age"];
            ViewData["gender"] = Request.Params["gender"];
            ViewData["email"] = Request.Params["email"];
            ViewData["phone_number"] = Request.Params["phone_number"];
            ViewData["address"] = Request.Params["address"];
            ViewData["city"] = Request.Params["city"];
            ViewData["pickupdate"] = Request.Params["pickupdate"];
            ViewData["dropoffdate"] = Request.Params["dropoffdate"];
            ViewData["pickupcity"] = Request.Params["pickupcity"];
            ViewData["returncity"] = Request.Params["returncity"];

            int cid;
            int.TryParse(customer_id, out cid);
            Customer c = new Customer
            {
                customer_id = cid,
                first_name = first_name,
                last_name = last_name,
                age = age,
                gender = gender,
                email = email,
                phone_number = phone_number,
                address = address,
                city = city
            };            


            int vid = vehicle_id;
            int.TryParse(customer_id, out cid);
            CarRentalApp.Booking b = new CarRentalApp.Booking
            {
                booking_status_code = "1",
                customer_id = cid,
                vehicle_id = vid,
                pickup_city = pickupcity,
                return_city = returncity,
                pickup_date = Convert.ToDateTime(pickupdate),
                return_date = Convert.ToDateTime(dropoffdate)
            };
           

            Models.Payment p = new Models.Payment();
            p.cardtype = card_type; p.cardnumber = card_number; p.cardname = card_name; p.expirydate = expiry_date; p.securitynumber = security_number;
            Models.ParentModel pm = new Models.ParentModel();
            pm.customer = c;
            pm.booking = b;
            DatabaseService s = new DatabaseService();
            pm.reviewmodel = s.getReview(vehicle_id);
            pm.payment = p;

            DateTime end = Convert.ToDateTime(ViewData["dropoffdate"]);
            DateTime start = Convert.ToDateTime(ViewData["pickupdate"]);
            double d = ((end - start).TotalDays + 1) * Convert.ToDouble(pm.reviewmodel.daily_rental_rate);

            ViewData["error"] = "";

            if (s.checkRestriction(pm.customer.customer_id, pm.booking.pickup_date) == false)
            {
                ViewData["error"] = "Unable to complete the booking";
            }
            else
            {
                s.SaveCustomer(c);
                b.booking_id = s.SaveBooking(b);
                CarRentalTestApp.SendEmailService ses = new CarRentalTestApp.SendEmailService();
                String aString = "<br/>Customer ID:" + pm.customer.customer_id + "<br/>Customer First Name:" + pm.customer.first_name + "<br/>Customer Last Name:" + pm.customer.last_name + "<br/>Age:" + pm.customer.age + "<br/>Gender:" + pm.customer.gender + "<br/>Email:" + pm.customer.email + "<br/>Phone Number:" + pm.customer.phone_number + "<br/>Address:" + pm.customer.address + "<br/>City:" + pm.customer.city;
                aString += "<br/>Payment Card Type:" + pm.payment.cardtype + "<br/>Payment Card Number:" + pm.payment.cardnumber + "<br/>Payment Card Name:" + pm.payment.cardname + "<br/>Expiry Date:" + pm.payment.expirydate + "<br/>Security Number:" + pm.payment.securitynumber;
                aString += "<br/>Booking ID:" + pm.booking.booking_id + "<br/>Pickup Date:" + pm.booking.pickup_date + "<br/>Return Date:" + pm.booking.return_date + "<br/>Pickup City:" + pm.booking.pickup_city + "<br/>Drop off city:" + pm.booking.return_city;
                aString += "<br/>Vehicle ID:" + pm.reviewmodel.registration_number + "<br/>Manufacturing Date:" + pm.reviewmodel.manufacturing_date + "<br/>Model:" + pm.reviewmodel.model_code + "<br/>Body style:" + pm.reviewmodel.body_style + "<br/>Passenger Capacity:" + pm.reviewmodel.passenger_capacity + "<br/>Vehicle Category Description:" + pm.reviewmodel.vehicle_category_description + "<br/> Daily Rental:" + pm.reviewmodel.daily_rental_rate + "<br/>Total Cost:" + d.ToString();
                ses.SendEmail(pm.customer.email, aString);
            }           
            return View(pm);
        }