예제 #1
0
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  EVENT HANDLERS  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

        protected void AddDestinationBtn_Click(object sender, EventArgs e, Location location)
        {
            TravellerController travellerController = new TravellerController();
            List <Favorite>     TravellerFavorites  = GetFavoriteList();

            try
            {
                bool contains = TravellerFavorites.Any(f => f.LocationID == location.ID);
                if (contains != true)
                {
                    bool favCreated = travellerController.CreateNewFavorite((int)Session[AppData.USERID], location.ID);
                    // Check if it is false
                }
                else
                {
                    string msg   = "This location is already in your destinations!";
                    string alert = "alert(" + msg + ");";
                    Response.Write("<script>alert('" + msg + "');</script>");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                string msg   = "There was an error. The location could not be added to your Destinations.";
                string alert = "alert(" + msg + ");";
                Response.Write("<script>alert('" + msg + "');</script>");
            }
            finally
            {
                travellerController.Dispose();
                TravellerFavorites.Clear();
                LoadLocations(location);
                LoadLocationModals(location);
            }
        }
예제 #2
0
        private void DeleteDestinationBtn_Click(object sender, EventArgs e, Location location)
        {
            TravellerController travellerController = new TravellerController();
            List <Favorite>     TravellerFavorites  = GetFavoriteList();

            try
            {
                bool contains = TravellerFavorites.Any(f => f.LocationID == location.ID);
                if (contains == true)
                {
                    bool deleted = travellerController.DeleteFavorite((int)Session[AppData.USERID], location.ID);
                    // Check if it is false
                }
                else
                {
                    string msg   = "This location does not exist in your Destinations!";
                    string alert = "alert(" + msg + ");";
                    Response.Write("<script>alert('" + msg + "');</script>");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                var msg = AppData.CreateAlert("There was an error. The location could not be removed from your Destinations.", "danger");
                err_Placeholder.Controls.Add(msg);
                System.Threading.Thread.Sleep(2000);
            }
            finally
            {
                travellerController.Dispose();
                TravellerFavorites.Clear();
                Response.Redirect(Request.RawUrl);
            }
        }
예제 #3
0
        /// <summary>
        /// Handles the click event of btnUpdatePW to update user password
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdatePW_Click(object sender, EventArgs e)
        {
            Validate("ValidateNewPW");
            if (!Page.IsValid)
            {
                return;
            }

            TravellerController travellerController = new TravellerController();

            try
            {
                string userName = (string)Session[AppData.USERNAME];
                string oldPW    = txtOldPW.Text;
                int    id       = (int)Session[AppData.USERID];
                string newPW    = txtNewPW.Text;

                bool oldPW_Verified = travellerController.VerifyCredentials(userName, oldPW);

                if (oldPW_Verified == false)
                {
                    var msg = AppData.CreateAlert("Incorrect current password, please try again", "danger");
                    updatePW_ErrPlaceholder.Controls.Add(msg);
                    return;
                }
                else if (newPW == oldPW)
                {
                    var msg = AppData.CreateAlert("New password cannot be same as current password, please choose something else", "danger");
                    updatePW_ErrPlaceholder.Controls.Add(msg);
                    return;
                }

                bool pwUpdated = travellerController.UpdateTravellerPassword(id, newPW);

                if (pwUpdated == true)
                {
                    var msg = AppData.CreateAlert("Password updated successfully", "success");
                    updatePW_ErrPlaceholder.Controls.Add(msg);
                }
                else
                {
                    var msg = AppData.CreateAlert("Password was not updated.", "danger");
                    updatePW_ErrPlaceholder.Controls.Add(msg);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);

                var errMsg = AppData.CreateAlert("There was an error while updating your password. Please try again.", "danger");
                updatePW_ErrPlaceholder.Controls.Add(errMsg);
            }
            finally
            {
                travellerController.Dispose();
            }
        }
예제 #4
0
        protected void Login_Click(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(2000);

            TravellerController travellerController = new TravellerController();

            try
            {
                string userName = txtUsername.Text;
                string password = txtPassword.Text;

                bool verified = travellerController.VerifyCredentials(userName, password);

                if (verified == true)
                {
                    Traveller user = travellerController.GetTravellerByUserName(userName);
                    user.UserName = userName;

                    if (user != null)
                    {
                        Session[AppData.USERID]       = user.TravellerID;
                        Session[AppData.USERNAME]     = user.UserName;
                        Session[AppData.FIRSTNAME]    = user.FirstName;
                        Session[AppData.LASTNAME]     = user.LastName;
                        Session[AppData.COUNTRY]      = user.Country;
                        Session[AppData.EMAIL]        = user.Email;
                        Session[AppData.LOGGEDIN]     = true;
                        Session[AppData.LOGGEDINTIME] = DateTime.UtcNow;

                        Response.Redirect("default.aspx?", false);
                        Context.ApplicationInstance.CompleteRequest();
                    }
                    else
                    {
                        var msg = AppData.CreateAlert("There was an error while logging you in.", "danger");
                        loginErrPlaceholder.Controls.Add(msg);

                        string logMessage = "Error: User tried to login with verified credentials, but no user was created.";
                        logger.Error(logMessage);
                    }
                }
                else
                {
                    var msg = AppData.CreateAlert("Invalid username and/or password", "danger");
                    loginErrPlaceholder.Controls.Add(msg);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            finally
            {
                travellerController.Dispose();
            }
        }
예제 #5
0
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  EVENT HANDLERS  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

        /// <summary>
        /// Handles the click event of btnUpdatePI to update personal information
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdatePI_Click(object sender, EventArgs e)
        {
            int    id      = (int)Session[AppData.USERID];
            string fn      = txtFirstName.Text;
            string ln      = txtLastName.Text;
            string country = CountryListBox.Text;

            TravellerController travellerController = new TravellerController();

            try
            {
                bool piUpdated = travellerController.UpdateTravellerInfo(id, fn, ln, country);

                if (piUpdated == true)
                {
                    Traveller user = travellerController.GetTravellerByUserName((string)Session[AppData.USERNAME]);
                    Session[AppData.FIRSTNAME] = user.FirstName;
                    Session[AppData.LASTNAME]  = user.LastName;
                    Session[AppData.COUNTRY]   = user.Country;

                    // Refresh data on page
                    txtFirstName.Text = (string)Session[AppData.FIRSTNAME];
                    txtLastName.Text  = (string)Session[AppData.LASTNAME];
                    lblCountry.Text   = "Country: <strong>" + (string)Session[AppData.COUNTRY] + "</strong>";

                    var msg = AppData.CreateAlert("Personal information updated successfully", "success");
                    updatePI_ErrPlaceholder.Controls.Add(msg);
                }
                else
                {
                    var msg = AppData.CreateAlert("Personal information could not be updated.", "danger");
                    updatePI_ErrPlaceholder.Controls.Add(msg);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                var msg = AppData.CreateAlert("There was an error while updating your information. Please try again.", "danger");
                updatePI_ErrPlaceholder.Controls.Add(msg);
            }
            finally
            {
                travellerController.Dispose();
            }
        }
예제 #6
0
        protected void AddCommentBtn_Click(object sender, EventArgs e, Location location, Comment comment)
        {
            TravellerController travellerController = new TravellerController();

            try
            {
                bool commentCreated = travellerController.CreateNewComment((int)Session[AppData.USERID], comment.LocationID, comment.CommentDate, comment.UserComment);
                // Check if it is false
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                string msg   = "There was an error. Your comment could not be added.";
                string alert = "alert(" + msg + ");";
                Response.Write("<script>alert('" + msg + "');</script>");
            }
            finally
            {
                travellerController.Dispose();
                LoadLocationModals(location);
            }
        }
예제 #7
0
        public List <Favorite> GetFavoriteList()
        {
            TravellerController tc        = new TravellerController();
            List <Favorite>     Favorites = new List <Favorite>();

            try
            {
                Favorites = tc.GetTravellerFavoritesByTravellerID((int)Session[AppData.USERID]);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                var msg = AppData.CreateAlert("Your saved destinations could not be loaded at this time. Please refresh the page or try logging out and logging back in", "warning");
                err_Placeholder.Controls.Add(msg);
            }
            finally
            {
                tc.Dispose();
            }

            return(Favorites);
        }
예제 #8
0
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  EVENT HANDLERS  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

        protected void Register_Click(object sender, EventArgs e)
        {
            Validate();
            if (!Page.IsValid)
            {
                return;
            }

            System.Threading.Thread.Sleep(2000);

            string firstName = txtFirstName.Text;
            string lastName  = txtLastName.Text;
            string country   = CountryListBox.Text;
            string email     = txtEmail.Text;
            string userName  = txtUsername.Text;
            string password  = txtPassword.Text;

            TravellerController travellerController = new TravellerController();

            try
            {
                bool userExists = travellerController.CheckIfUsernameExists(userName);
                if (userExists == true)
                {
                    HtmlGenericControl messageDiv = new HtmlGenericControl("div")
                    {
                        ID = "message"
                    };
                    messageDiv.Attributes["class"] = "alert alert-danger";
                    messageDiv.InnerText           = "That username already exists. Please choose another.";

                    registerErrPlaceholder.Controls.Add(messageDiv);
                }
                else
                {
                    bool registered = travellerController.CreateNewTraveller(firstName, lastName, country, userName, email, password);

                    if (registered == true)
                    {
                        Response.Redirect("login.aspx?justregistered=true", false);
                        Context.ApplicationInstance.CompleteRequest();
                    }
                    else
                    {
                        HtmlGenericControl messageDiv = new HtmlGenericControl("div")
                        {
                            ID = "message"
                        };
                        messageDiv.Attributes["class"] = "alert alert-danger";
                        messageDiv.Attributes["role"]  = "alert";
                        messageDiv.InnerText           = "There was an error while created your account.";

                        messagePlaceholder.Controls.Add(messageDiv);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            finally
            {
                travellerController.Dispose();
            }
        }