/// <summary>
        ///     Action for completing the reservation.
        /// </summary>
        public ActionResult CompleteReservation()
        {
            List<string> randomCodes = new List<string>();
            string randomCode;

            var of = new PLSQLDatabaseHandler();

            if (this.Session["reservation"] == null)
            {
                return this.RedirectToAction("Index");
            }

            // Write reservation to the database and get an id
            var reservations = new RESERVATION();
            reservations.PAYED = 0;

            // Get reservation id
            int reservation_id = of.CallWriteReservation(0);

            var reservation = new CUSTOMERS_PAYING();
            reservation = (CUSTOMERS_PAYING)this.Session["reservation"];

            // Write rfid and get an id back
            var rfid = new RFID();

            // Generate random.
            randomCode = this.GetRandomCode(12, true);
            while (randomCodes.Count(x => x == randomCode) > 0 || this.Db.RFIDS.Count(x => x.KEY == randomCode) > 0)
            {
                randomCode = this.GetRandomCode(12, true);
            }
            randomCodes.Add(randomCode);

            rfid.KEY = randomCode;
            rfid.USERNAME = @"ICT4EVENTS\" + reservation.NAME.Replace(" ", string.Empty);

            // get rfid id
            int rfid_id = of.CallWriteRFID(rfid.KEY, rfid.USERNAME);

            // Write user to the database
            var user = new USER();
            user.RFIDS_ID = rfid_id;

            // Get user id from insert
            int user_id = of.CallWriteUser(rfid_id);

            reservation.RESERVATIONS_ID = reservation_id;
            reservation.USERS_ID = user_id;

            of.CallWriteCustomerPaying(
                user_id,
                reservation_id,
                reservation.NAME,
                reservation.STREET,
                reservation.POSTALCODE,
                reservation.CITY,
                reservation.PHONE,
                reservation.EMAIL);

            string ExtraHtml = string.Empty;

            // CO-CUSTOMERS
            for (int i = 1; i < (int)this.Session["numpersons"]; i++)
            {
                // Write rfid to the database and get the inserted id back
                var newRfid = new RFID();

                randomCode = this.GetRandomCode(12, true);
                while (randomCodes.Count(x => x == randomCode) > 0 || this.Db.RFIDS.Count(x => x.KEY == randomCode) > 0)
                {
                    randomCode = this.GetRandomCode(12, true);
                }
                randomCodes.Add(randomCode);

                newRfid.KEY = randomCode;
                newRfid.USERNAME = @"ICT4EVENTS\" + this.Session["coBoekerName" + i];
                newRfid.USERNAME = newRfid.USERNAME.Replace(" ", string.Empty);

                // Get id
                int newRfid_Id = of.CallWriteRFID(newRfid.KEY, newRfid.USERNAME);

                var newUser = new USER();
                newUser.RFIDS_ID = newRfid_Id;
                newUser.TYPE = "Guest";
                int newUser_Id = of.CallWriteUser(newRfid_Id);

                var newCustomers = new CUSTOMER();
                newCustomers.RESERVATIONS_ID = reservation_id;
                newCustomers.USERS_ID = newUser_Id;
                of.CallWriteCustomer(newUser_Id, reservation_id);

                //Add extra HTML to the mail
                ExtraHtml += "<br /><br /><p>Gebruiker gegevens voor gebruiker: " + this.Session["coBoekerName" + i]
                             + "<p><p>Inlognaam: '" + newRfid.USERNAME + "'</p><br /><p>Barcode voor gebruiker: '"
                             + this.Session["coBoekerName" + i]
                             + "'</p><div style='width: 400px; height: 150px; overflow: hidden'><img src='http://www.bcgen.com/demo/linear-dbgs.aspx?S=13&D="
                             + newRfid.KEY
                             + "&CC=T&CT=T&ST=T&X=0.03&O=0&BBV=0&BBH=0&CG=0&BH=1&LM=0.2&EM=0&CS=0&PT=T&TA=F&CA=&CB=' style='width: 400px;'/></div>";
            }

            //Send emial to the users given emailaddress
            this.SendReservationEmail(reservation.EMAIL, reservation.NAME, rfid.KEY, rfid.USERNAME, ExtraHtml);

            //Return to index
            return this.RedirectToAction("Index");
        }
        /// <summary>
        /// The step 2.
        /// </summary>
        public ActionResult Step2()
        {
            int numpersons = 0;
            List<string> errors = new List<string>();

            try
            {
                numpersons = Convert.ToInt16(this.Request.Form["NUMPERSONS"].Trim());
            }
            catch (Exception e)
            {
                errors.Add("Aantal personen is niet een correct nummmer.");

                // return RedirectToAction("Step1");
            }

            var reservation = new CUSTOMERS_PAYING();
            if (this.Session["reservation"] == null)
            {

                //Check if fields are empty
                if (this.Request.Form["FIRSTNAME"].Trim() == string.Empty || this.Request.Form["LASTNAME"].Trim() == string.Empty)
                {
                    errors.Add("Naam is niet ingevuld.");
                }

                if (this.Request.Form["ADDRESS"].Trim() == string.Empty)
                {
                    errors.Add("Adres is niet ingevuld.");
                }

                if (this.Request.Form["PLACE"].Trim() == string.Empty)
                {
                    errors.Add("Plaats is niet ingevuld.");
                }

                if (this.Request.Form["POSTALCODE"].Trim() == string.Empty)
                {
                    errors.Add("Postcode is niet ingevuld.");
                }

                if (this.Request.Form["PHONENUMBER"].Trim() == string.Empty)
                {
                    errors.Add("Telefoonnummer is niet ingevuld.");
                }

                if (this.Request.Form["EMAIL"].Trim() == string.Empty)
                {
                    errors.Add("Email is niet ingevuld.");
                }

                //add fields to reservation
                reservation.NAME = this.Request.Form["FIRSTNAME"].Trim() + " " + this.Request.Form["LASTNAME"].Trim();

                reservation.STREET = this.Request.Form["ADDRESS"].Trim();
                reservation.CITY = this.Request.Form["PLACE"].Trim();
                reservation.POSTALCODE = this.Request.Form["POSTALCODE"].Trim();
                reservation.PHONE = this.Request.Form["PHONENUMBER"].Trim();
                reservation.EMAIL = this.Request.Form["EMAIL"].Trim();

                this.Session["reservation"] = reservation;
                this.Session["numpersons"] = numpersons;

            }

            //Show flags if errors are found
            if (errors.Count > 0)
            {
                this.SetFlash(
                    "De volgende fouten zijn opgetreden: <ul>"
                    + string.Join(string.Empty, errors.ConvertAll(x => "<li>" + x + "</li>")) + "</ul>",
                    FlashType.Danger);
            }

            this.ViewBag.numpersons = numpersons;

            if (numpersons > 1 && errors.Count == 0)
            {
                return this.View();
            }

            if (numpersons == 1 && errors.Count == 0)
            {
                return this.RedirectToAction("Step3");
            }

            return this.RedirectToAction("Step1");
        }