Beispiel #1
0
        /// <summary>
        ///  Stores the information and proceeds to PayPal payment page.
        /// </summary>
        protected void PayPalBtn_Click(object sender, EventArgs e)
        {
            try
            {
                AddressManager address;
                long           vehicleAvailableID, locationID, customerID;
                DateTime       hireStart, hireEnd;
                NVPAPICaller   payPalCaller = new NVPAPICaller();
                string         retMsg = "";
                string         token = "";
                double         totalDays, totalCost;

                address            = (AddressManager)Session["Address"];
                vehicleAvailableID = (long)Session["VehicleAvailableID"];
                locationID         = (long)Session["LocationID"];
                hireStart          = (DateTime)Session["StartTime"];
                hireEnd            = (DateTime)Session["EndTime"];
                customerID         = (long)Session["CustomerID"];

                VehicleManager vehicle = VehicleManager.GetAvailableVehicles(locationID).Where(x => x.VehicleAvailableID == vehicleAvailableID).SingleOrDefault();

                totalDays = (hireEnd - hireStart).TotalDays;
                totalCost = totalDays * vehicle.BasePrice;
                totalCost = Math.Round(totalCost, 2); //Round to 2 dp

                bool ret = payPalCaller.ShortcutExpressCheckout(totalCost.ToString(), ref token, ref retMsg, vehicle.Manufacturer + " " + vehicle.Model, vehicle.Currency);
                if (ret)
                {
                    Session["token"] = token;
                    Response.Redirect(retMsg, false);
                }

                orderConfirmedLbl.Text = "Order Created";
            }
            catch (Exception ex)
            {
                generalErrorLbl.Text = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }
        /// <summary>
        ///  Loads the information about the order from the session variables which were stored from the review order page.
        /// </summary>
        private void LoadInformation(ref VehicleManager vehicle, ref double totalDays, ref double totalCost, ref DateTime hireStart,
                                     ref DateTime hireEnd, ref AddressManager address, ref CustomerManager customer, ref LocationManager location)
        {
            long vehicleAvailableID, locationID, customerID;
            bool useLocation;

            address            = (AddressManager)Session["Address"];
            vehicleAvailableID = (long)Session["VehicleAvailableID"];
            locationID         = (long)Session["LocationID"];
            hireStart          = (DateTime)Session["StartTime"];
            hireEnd            = (DateTime)Session["EndTime"];
            customerID         = (long)Session["CustomerID"];
            useLocation        = (bool)Session["UseLocation"];

            customer = CustomerManager.GetCustomers().Where(x => x.CustomerID == customerID).SingleOrDefault();
            vehicle  = VehicleManager.GetAvailableVehicles(locationID).Where(x => x.VehicleAvailableID == vehicleAvailableID).SingleOrDefault();
            location = LocationManager.GetLocations().Where(x => x.LocationID == locationID).SingleOrDefault();

            totalDays = (hireEnd - hireStart).TotalDays;
            totalCost = totalDays * vehicle.BasePrice;
            totalCost = Math.Round(totalCost, 2); //Round to 2 dp
        }
        private void LoadAvailableVehicles()
        {
            List <VehicleManager> vehiclesAvailable = new List <VehicleManager>();
            string   manufacturer, model, SIPPCodeStr, currency;
            double   MPG, basePrice;
            long     locationID = 0;
            SIPPCode sizeOfVehicleSIPPCode, noOfDoorsSIPPCode, transmissionAndDriveSIPPCode, fuelAndACSIPPCode;
            Button   bookVehicle;
            TableRow row;

            if (locationDdl.SelectedValue != "")
            {
                locationID = Convert.ToInt32(locationDdl.SelectedValue.Split(',')[0]);

                //Filter by using the ID from the location ddl
                vehiclesAvailable = VehicleManager.GetAvailableVehicles(locationID).Where(x => x.Active == true).ToList();
            }

            foreach (VehicleManager vehicle in vehiclesAvailable)
            {
                row = new TableRow();
                Image vehicleImg = new Image();

                TableCell cell = new TableCell();

                vehicleImg.ImageUrl      = vehicle.ImageLoc;
                vehicleImg.AlternateText = vehicle.Manufacturer + " " + vehicle.Model;

                //make standard size of car images 270x150
                vehicleImg.Width  = Variables.STANDARDWIDTH;
                vehicleImg.Height = Variables.STANDARDHEIGHT;

                cell.Controls.Add(vehicleImg);

                row.Cells.Add(cell);
                vehiclesAvailableTbl.Rows.Add(row);

                manufacturer = vehicle.Manufacturer;
                model        = vehicle.Model;
                MPG          = vehicle.MPG;
                SIPPCodeStr  = vehicle.SIPPCode;
                currency     = vehicle.Currency;
                AddCell(row, manufacturer + " " + model + "<br />MPG: " + MPG.ToString() + "<br />SIPP: " + SIPPCodeStr);

                //Gets SIPP Code descriptions for all letters of SIPP code for this car
                sizeOfVehicleSIPPCode        = SIPPCode.GetSIPPCodeDesc(Variables.SIZEOFVEHICLE, vehicle.SIPPCode[0].ToString());
                noOfDoorsSIPPCode            = SIPPCode.GetSIPPCodeDesc(Variables.NOOFDOORS, vehicle.SIPPCode[1].ToString());
                transmissionAndDriveSIPPCode = SIPPCode.GetSIPPCodeDesc(Variables.TRANSMISSIONANDDRIVE, vehicle.SIPPCode[2].ToString());
                fuelAndACSIPPCode            = SIPPCode.GetSIPPCodeDesc(Variables.FUELANDAC, vehicle.SIPPCode[3].ToString());

                cell = new TableCell();
                Label label = new Label();
                label.Text = sizeOfVehicleSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = noOfDoorsSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = transmissionAndDriveSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = fuelAndACSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                row.Cells.Add(cell);

                basePrice = vehicle.BasePrice;
                AddCell(row, currency + ": " + basePrice.ToString());

                //Book button to book selected car
                bookVehicle          = new Button();
                bookVehicle.ID       = locationID + "_" + vehicle.VehicleAvailableID + "_BookBtn";
                bookVehicle.Text     = "Book";
                bookVehicle.CssClass = "btn btn-primary";
                bookVehicle.Click   += new EventHandler(BookVehicleBtn_Click);
                if (Session["LoggedInType"] != null)
                {
                    if (Session["LoggedInType"].ToString() == "")
                    {
                        bookVehicle.OnClientClick = "return alert('Please login to continue');";
                    }
                }
                else
                {
                    bookVehicle.OnClientClick = "return alert('Please login to continue');";
                }
                cell = new TableCell();
                cell.Controls.Add(bookVehicle);
                row.Cells.Add(cell);

                vehiclesAvailableTbl.Rows.Add(row);
            }
        }
        /// <summary>
        ///  Adds a new vehicle to be listed against this location as available to book.
        /// </summary>
        protected void AddAvailableVehiclesBtn_Click(object sender, EventArgs e)
        {
            try
            {
                List <VehicleManager> vehiclesAvailable = new List <VehicleManager>();
                bool   validEntries  = true;
                long   vehicleID     = 0;
                long   locationID    = 0;
                int    totalVehicles = 0;
                int    userID        = 0;
                double basePrice     = 0;
                string currency;

                #region checkValidity
                if (locationDdl.SelectedValue != "")
                {
                    locationID        = Convert.ToInt32(locationDdl.SelectedValue.Split(',')[0]);
                    vehiclesAvailable = VehicleManager.GetAvailableVehicles(locationID);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please select a location. <br />";
                }
                if (vehicleDdl.SelectedValue != "")
                {
                    vehicleID = Convert.ToInt32(vehicleDdl.SelectedValue.Split(',')[0]);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please select a vehicle. <br />";
                }

                if (Regex.IsMatch(totalVehiclesTxt.Text, @"^[0-9]*$"))
                {
                    totalVehicles = Convert.ToInt32(totalVehiclesTxt.Text);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please enter a whole number for total vehicles. <br />";
                }

                if (currencyDdl.SelectedValue != "")
                {
                    currency = currencyDdl.SelectedValue;
                }
                else
                {
                    currency           = "";
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please enter a currency. <br />";
                }
                if (Variables.CheckDecimal(basePriceTxt.Text))
                {
                    basePrice = Convert.ToDouble(basePriceTxt.Text);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please enter a base price in currency format. <br />";
                }

                foreach (VehicleManager vehicle in vehiclesAvailable)
                {
                    if (vehicle.VehicleID == vehicleID)
                    {
                        validEntries       = false;
                        inputErrorLbl.Text = inputErrorLbl.Text + "This vehicle is already assigned to this location. Please select another. <br />";
                    }
                }

                if (Response.Cookies["UserID"].Value != null)
                {
                    userID = Convert.ToInt32(Response.Cookies["UserID"].Value);
                }
                else if (Session["UserID"] != null)
                {
                    userID = Convert.ToInt32(Session["UserID"]);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = "Not logged in. Please login to continue";
                }
                #endregion

                if (validEntries == true)
                {
                    VehicleManager.InsertNewAvailableVehicle(vehicleID, locationID, totalVehicles, currency, basePrice, userID, (int)UserAccess.UserType.company);
                    vehicleAddedLbl.Text = "New available vehicle added.";
                }
            }
            catch (Exception ex)
            {
                generalErrorLbl.Text = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }