Exemplo n.º 1
0
 public bool InsertReservationAccount(ReservationAccount reservation)
 {
     return _context.InsertReservationAccount(reservation);
 }
Exemplo n.º 2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!IsValid)
            {
                feedbackPanel.Visible = true;
                lblError.Text = "Invalide registratie!";
                lblError.CssClass = "text-danger";
                return;
            }

            if (StartDate.SelectedDate == DateTime.Parse("1-1-0001") ||
                EndDate.SelectedDate == DateTime.Parse("1-1-0001"))
            {
                feedbackPanel.Visible = true;
                lblError.Text = "Invalide datas.";
                return;
            }

            if (drpListOfPlaces.SelectedValue == "Selecteer een plek")
            {
                feedbackPanel.Visible = true;
                lblError.Text = "Selecteer eerst een plek om een reservering te plaatsen.";
                return;
            }

            // variables
            Count = 0;

            // Counting field of reservations
            Count = CheckEmptyEmailCount(Email1, Count);
            Count = CheckEmptyEmailCount(Email2, Count);
            Count = CheckEmptyEmailCount(Email3, Count);
            Count = CheckEmptyEmailCount(Email4, Count);
            Count = CheckEmptyEmailCount(Email5, Count);

            // Leader information
            var lFirstname = leader_first_name.Text;
            var lSurname = leader_last_name.Text;
            var lAddress = leader_address.Text;
            var lCity = leader_city.Text;
            var lUsername = leader_Username.Text;
            var lIban = leader_iban.Text;
            var lEmail = leader_Email.Text;
            var lPass = leader_Password.Text;

            PlaceId = Convert.ToInt32(drpListOfPlaces.SelectedValue);
            var reservationOnPlace = LogicCollection.ReservationLogic.GetCountReservationOfPlace(PlaceId);

            if ((Count + 1 + reservationOnPlace) > LogicCollection.PlaceLogic.GetPlaceByID(PlaceId).Capacity)
            {
                feedbackPanel.Visible = true;
                lblError.Text = "Teveel mensen willen op de plek ingeschreven worden.";
                return; // Too much people on that place
            }

            // Making person of leader
            var person = new Person(0, lFirstname, lSurname, lAddress, lCity, lIban); // local person
            if (!LogicCollection.PersonLogic.Insert(person)) {return;} // insert person
            person = LogicCollection.PersonLogic.GetLastAdded(); // get person out of database

            // Register leader
            var lhash = Membership.GeneratePassword(8, 2);
            var leaderUser = new User(0, lUsername, lEmail, lhash, false, lPass);
            if (!LogicCollection.UserLogic.RegisterUser(leaderUser)) {return;}
            leaderUser = LogicCollection.UserLogic.GetLastAdded();

            // Making reservation
            var reservation = new Reservation(0, person.ID, StartDate.SelectedDate, EndDate.SelectedDate, false); // local reservation
            if (!LogicCollection.ReservationLogic.Insert(reservation)){return;} // insert reservation
            reservation = LogicCollection.ReservationLogic.GetLastAdded(); // get reservation out of database

            // Reservation Wristband leader
            var resvationWristband = new ReservationWristband(0, reservation.ID, leaderUser.ID);
            if (!LogicCollection.ReservationWristbandLogic.Insert(resvationWristband)){return;} // insert reservation
            resvationWristband = LogicCollection.ReservationWristbandLogic.GetLastAdded();

            // sending reservation mail to leader
            try
            {
                LogicCollection.ReservationLogic.ReservationMail(leaderUser, CurEvent,
                LogicCollection.PlaceLogic.GetPlaceByID(PlaceId), reservation.DateStart, reservation.DateEnd);
            }
            catch (Exception)
            {
                return;
            }

            // Making reservation_account
            var reservationAccount = new ReservationAccount(0, reservation.ID, PlaceId);
            if (!LogicCollection.ReservationLogic.InsertReservationAccount(reservationAccount)) { return; }
            

            #region checking reservations emailadresses & Reservations of users
            
            // Listof Textboxes 
            var listOfEmailReservation = new List<TextBox>()
            {
                Email1, Email2, Email3, Email4, Email5
            };

            var reservationsOfNewUser = new List<User>();
            // Checking Emailadres if not empty 
            foreach (var email in listOfEmailReservation.Where(email => CheckEmptyEmailStatus(email)))
            {
                if (!LogicCollection.UserLogic.IsValidEmail(email.Text) || email == leader_Email)
                {
                    feedbackPanel.Visible = true;
                    lblError.Text = "Invalide emailadressen.";
                    return;
                }

                var result = Regex.Match(email.Text, @"^.*?(?=@)").Value;

                var hash = Membership.GeneratePassword(8 , 0);
                reservationsOfNewUser.Add(new User(0, result, email.Text, hash, false, null));
            }

            // Adding user to database and make reservation 
            foreach (var user in reservationsOfNewUser)
            {
                // checking if users is not null send email and insert into database
                if (user == null) continue;

                //send email and insert into database and make reservationAccount
                var password = Membership.GeneratePassword(10, 0);
                var register = LogicCollection.UserLogic.RegisterUser(user, true, password);
                var userLast = LogicCollection.UserLogic.GetLastAdded();

                if (!register) continue;
                //var res = new ReservationAccount(0, reservation.ID, PlaceId);
                //if (!LogicCollection.ReservationLogic.InsertReservationAccount(res)) { return; }

                var resvationWristGuest = new ReservationWristband(0, reservation.ID, userLast.ID);
                if (!LogicCollection.ReservationWristbandLogic.Insert(resvationWristGuest)) { return; } // insert reservationWristband

                //sending reservation mail to newUser
                try
                {
                    LogicCollection.ReservationLogic.ReservationMail(userLast, CurEvent,
                        LogicCollection.PlaceLogic.GetPlaceByID(PlaceId), reservation.DateStart, reservation.DateEnd);
                }
                catch (Exception)
                {
                    return;
                }
            }
            #endregion

            // Feedbackpanels
            feedbackPanel.Visible = false;
            feedbackPanelSucces.Visible = true;
            fromRegister.Visible = false;

            lblSucces.Visible = true;
            lblSucces.Text =
                (IsValid ? "Succesvol geregisteerd! Login om je reservering te betalen." : "Invalide gegevens") +
                "<br />Voornaam: " + lFirstname +
                "<br />Achternaam: " + lSurname +
                "<br />Adres: " + lAddress +
                "<br />Woonplaats: " + lCity +
                "<br />IBAN: " + lIban +
                "<br />Email: " + lEmail +
                "<br />Meerdere reserveerders: " + Count +
                "<br />PlaceID: " + PlaceId +
                "<br />Startdatum: " + StartDate.SelectedDate.ToShortDateString() +
                "<br />Einddatum: " + EndDate.SelectedDate.ToShortDateString() +
                "<br /><a href='/Views/AccountSystem/Login.aspx'>Nu inloggen</a>";
        }