Ejemplo n.º 1
0
    /*
     * CREATED:     H. Conant		MAR 17 2018
     *
     * ProcessRequestButton_Click()
     * This method processes a contact request and displays the new status to the user
     *
     * PARAMETERS:
     * object sender - object on the page that is being targeted
     * EventArgs e - event that has triggered the method
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * SurveyController.ProcessContactRequest()
     * MessageUserControl.ShowErrorMessage()
     * MessageUserControl.ShowSuccessMessage()
     */
    protected void ProcessRequestButton_Click(object sender, EventArgs e)
    {
        try
        {
            surveyController.ProcessContactRequest(int.Parse(SurveyIDLabel.Text));
            ProcessedStatus.Text = "Processed";
        }
        catch (Exception ex)
        {
            MessageUserControl.ShowErrorMessage("Could not process contact request. Please try again. If error persists, please contact your administrator.", ex);
        }


        if (ProcessedStatus.Text == "Processed")
        {
            ProcessedStatus.ForeColor    = System.Drawing.Color.Green;
            ProcessRequestButton.Enabled = false;
            ProcessRequestButton.Visible = false;
            MessageUserControl.ShowSuccessMessage("Contact Request was processed. This change may not be reflected on other pages until page results are refreshed.");
        }
        else
        {
            MessageUserControl.ShowErrorMessage("Could not process contact request. Please try again. If error persists, please contact your administrator.");
        }
    }
Ejemplo n.º 2
0
    /*
     * CREATED:    C. Stanhope     MAR 13 2018
     * MODIFIED:   C. Stanhope     MAR 21 2018
     *  - added ResetSearchFilters() method call
     *  - added validation
     * MODIFIED:   C. Stanhope     APR 5 2018
     *  - new word trims whitespace
     * MODIFIED:   C. Stanhope     APR 6 2018
     *  - added try-catch for database access
     *
     * AddAccessCodeButton_Click()
     * Triggered when "AddAccessCodeButton" is clicked and is used to add an access code to the database.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * ValidateAccessCodeWord()
     * AccessCodeController.AddAccessCode()
     * MessageUserControl.ShowSuccessMessage()
     * ClearPage()
     * ResetSearchFilters()
     * MessageUserControl.ShowInfoMessage()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void AddAccessCodeButton_Click(object sender, EventArgs e)
    {
        string newWord = AddAccessCodeTB.Text.ToLower().Trim();

        if (newWord.Length > 0)
        {
            if (ValidateAccessCodeWord(newWord))
            {
                AccessCodeDTO newAccessCode = new AccessCodeDTO();
                newAccessCode.accesscodeword = newWord;
                newAccessCode.activeyn       = true; // defaults to active

                try
                {
                    accessCodeController.AddAccessCode(newAccessCode);

                    MessageUserControl.ShowSuccessMessage("New access code '" + newWord + "' added");
                    ClearPage();
                    ResetSearchFilters();
                }
                catch (Exception ex)
                {
                    MessageUserControl.ShowErrorMessage("Adding access code failed. Please try again. If error persists, please contact your administrator.", ex);
                }
            }
            else // invalid code word
            {
                MessageUserControl.ShowInfoMessage("The access code '" + newWord + "' is not valid. Please ensure the access code is between 6 and 8 letters (no numbers or symbols are permitted).");
            }
        }
        else // no word entered
        {
            MessageUserControl.ShowInfoMessage("No access code word was entered. Please enter a word between 6 and 8 letters (no numbers or symbols are permitted).");
        }
    }
Ejemplo n.º 3
0
 /*
  * CREATED:     A. Valberg		MAR 3 2018
  * MODIFIED:    H. Conant		MAR 5 2018
  * - Updated method signature
  * - Updated method body code
  *
  * DeactivateUnitButton_Click()
  * This method allows the user to deactivate a specified unit in the database.
  *
  * PARAMETERS:
  * object sender - object on the page that is being targeted
  * EventArgs e - event that has triggered the method
  *
  * RETURNS:
  * void
  *
  * ODEV METHOD CALLS:
  * MessageUserControl.ShowInfoMessage()
  * UnitController.DeactivateUnit()
  * MessageUserControl.ShowSuccessMessage()
  * MessageUserControl.ShowErrorMessage()
  * ClearPage()
  */
 protected void DeactivateUnitButton_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(DeactivateUnitNameLabel.Text))
     {
         MessageUserControl.ShowInfoMessage("Please select a care site and unit.");
     }
     else
     {
         int tempUnitId;
         int.TryParse(UnitDDL.SelectedValue, out tempUnitId);
         if (tempUnitId == 0)
         {
             MessageUserControl.ShowInfoMessage("Please select a care site and unit.");
         }
         else
         {
             UnitDTO tempUnit = new UnitDTO();
             tempUnit.unitid = tempUnitId;
             try
             {
                 unitController.DeactivateUnit(tempUnit);
                 MessageUserControl.ShowSuccessMessage("Unit " + UnitDDL.SelectedItem.Text + " has been deactivated for the " + CareSiteDDL.SelectedItem.Text + " care site.");
                 ClearPage();
             }
             catch (Exception ex)
             {
                 MessageUserControl.ShowErrorMessage("Deactivating unit failed. Please try again. If error persists, please contact your administrator.", ex);
             }
         }
     }
 }
Ejemplo n.º 4
0
    /*
     * CREATED:      C. Stanhope         MAR 13 2018
     *
     * AddAccessCodeButton_Click()
     * Triggered when "AddAccessCodeButton" is clicked and is used to add an access code to the database.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * METHOD CALLS:
     * AccessCodeController.AddAccessCode()
     * MessageUserControl.ShowSuccessMessage()
     */
    protected void AddAccessCodeButton_Click(object sender, EventArgs e)
    {
        AccessCodeDTO newAccessCode = new AccessCodeDTO();

        newAccessCode.accesscodeword = AddAccessCodeTB.Text;
        newAccessCode.activeyn       = true; // defaults to active

        accessCodeController.AddAccessCode(newAccessCode);

        MessageUserControl.ShowSuccessMessage("New access code added!");
        ClearPage();
    }
Ejemplo n.º 5
0
    /*
     * CREATED:     C. Stanhope		MAR 23 2018
     * MODIFIED:   C. Stanhope     APR 6 2018
     *  - added try-catch for database access
     *
     * DeactivateCareSiteButton_Click()
     * Used to deactivate a care site in the database.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowInfoMessage()
     * CareSiteController.GetCareSiteByCareSiteID()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void DeactivateCareSiteButton_Click(object sender, EventArgs e)
    {
        if (selectedCareSite != null)
        {
            try
            {
                careSiteController.DeactivateCareSite(selectedCareSite);

                MessageUserControl.ShowSuccessMessage("The " + selectedCareSite.caresitename + " care site was successfully deactivated.");

                CareSiteDDL.SelectedIndex = 0;
                CareSiteNameTextBox.Text  = "";
                AddressTextBox.Text       = "";
                CityTextBox.Text          = "";
                AccountForm.Visible       = false;

                #region resetting care site ddl
                CareSiteDDL.AppendDataBoundItems = false; // clears old values
                CareSiteDDL.DataSourceID         = null;

                // get new list of care sites
                List <CareSiteDTO> ddlCareSites = careSiteController.GetActiveCareSites();

                // create a fake care site that acts as a "select" in the ddl
                CareSiteDTO fakeSelectCareSite = new CareSiteDTO();
                fakeSelectCareSite.caresiteid   = 0;
                fakeSelectCareSite.caresitename = "Select...";

                ddlCareSites.Add(fakeSelectCareSite);

                // put the new "select" care site at the top of the list
                ddlCareSites = ddlCareSites.OrderBy(site => site.caresiteid).ToList();

                // bind data source
                CareSiteDDL.DataSource = ddlCareSites;
                CareSiteDDL.DataBind();
                #endregion
            }
            catch (Exception ex)
            {
                MessageUserControl.ShowErrorMessage("Deactivating care site failed. Please try again. If error persists, please contact your administrator.", ex);
            }
        }
        else
        {
            MessageUserControl.ShowErrorMessage("No care site selected. The \"Deactivate Care Site\" button should not be available if no care site is selected. Please try again. If error persists, please contact your administrator.");
        }
    }
Ejemplo n.º 6
0
    /*
     * CREATED:     E. Lautner		Mar 22 2018
     *
     * SetPassword_Click()
     * Checks that the new password is identical in ConfirmPassTextBox and NewPassTextBox.
     * Attempts to change the password by passing the old password and new password.
     * Prompts MessageUserControl when action fails or passes.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowSuccessMessage()
     * MessageUserControl.ShowErrorMessage()
     * UserManager.FindById()
     * UserManager.CheckPassword()
     * MessageUserControl.ShowInfoMessage()
     */
    protected void SetPassword_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            if (ConfirmPassTextBox.Text == NewPassTextBox.Text)
            {
                if (NewPassTextBox.Text.Length < 8)
                {
                    MessageUserControl.ShowInfoMessage("New password must be at least 8 characters long.");
                }
                else
                {
                    try
                    {
                        string      userId        = Context.User.Identity.GetUserId();
                        UserManager userManager   = new UserManager();
                        var         currentUser   = userManager.FindById(userId);
                        bool        checkpassword = userManager.CheckPassword(currentUser, OldPassTextBox.Text);
                        if (checkpassword == true)
                        {
                            IdentityResult result = userManager.ChangePassword(Context.User.Identity.GetUserId(), OldPassTextBox.Text, NewPassTextBox.Text);

                            if (result.Succeeded)
                            {
                                MessageUserControl.ShowSuccessMessage("Password successfully updated.");
                            }
                        }
                        else
                        {
                            MessageUserControl.ShowInfoMessage("Old password was incorrect. Please try again.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageUserControl.ShowErrorMessage("Password change failed. Please try again. If error persists, please contact your administrator.", ex);
                    }
                }
            }
            else
            {
                MessageUserControl.ShowInfoMessage("New Password and Confirm Password did not match. Please try again.");
            }
        }
    }
Ejemplo n.º 7
0
    /*
     * CREATED:     E. Lautner		Apr 1 2018
     *
     * DeactivateUser_Click()
     * Deactivates the selected user by setting the users activeyn to false.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowSuccessMessage()
     * MessageUserControl.ShowErrorMessage()
     * UserManager.FindByName()
     * UserManager.Update()
     */
    protected void DeactivateUser_Click(object sender, EventArgs e)
    {
        sentUserName = Request.QueryString["id"];

        if (sentUserName == "" || sentUserName == null)
        {
            MessageUserControl.ShowErrorMessage("An account has not been selected. Please navigate back to the Account Search page and select an account. If error persists, please contact your administrator.");
        }
        else
        {
            try
            {
                UserManager userManager  = new UserManager();
                var         selectedUser = userManager.FindByName(UsernameLabel.Text);

                if (selectedUser.activeyn == true)
                {
                    selectedUser.activeyn = false;

                    userManager.Update(selectedUser);
                    MessageUserControl.ShowSuccessMessage("Account has been deactivated.");

                    PasswordBtn.Visible             = false;
                    DeactivateAccountButton.Visible = false;
                    UpdateAccountButton.Visible     = false;
                    FirstNameTB.Enabled             = false;
                    LastNameTB.Enabled = false;
                    EmailTB.Enabled    = false;
                    AuthorizationLevelRolesRadioList.Enabled = false;
                    CareSiteDDL.Enabled = false;
                }
                else
                {
                    MessageUserControl.ShowErrorMessage("Account is already inactive. Inactive accounts should not be available to edit.");
                }
            }
            catch (Exception ex)
            {
                MessageUserControl.ShowErrorMessage("Account deactivation failed. Please try again. If error persists, please contact your administrator.", ex);
            }
        }
    }
Ejemplo n.º 8
0
    /*
     * CREATED:     E. Lautner		Apr 1 2018
     *
     * ResetPassword_Click()
     * Resets the password for the given account by deleting the old one and then generating a new one.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowSuccessMessage()
     * UserManager.GenerateNewPassword()
     * UserManager.FindByName()
     * UserManager.RemovePassword()
     * UserManager.AddPassword()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void ResetPassword_Click(object sender, EventArgs e)
    {
        sentUserName = Request.QueryString["id"];

        try
        {
            UserManager userManager = new UserManager();
            string      newPassword = userManager.GenerateNewPassword();

            var selectedUser = userManager.FindByName(UsernameLabel.Text);
            userManager.RemovePassword(selectedUser.Id);
            userManager.AddPassword(selectedUser.Id, newPassword);

            string resultMessage = string.Format("Account password has been reset! UserName: {0} | Password: {1}", UsernameLabel.Text, newPassword);
            MessageUserControl.ShowSuccessMessage(resultMessage);
        }
        catch (Exception ex)
        {
            MessageUserControl.ShowErrorMessage("Reset password failed. Please try again. If error persists, please contact your administrator.", ex);
        }
    }
Ejemplo n.º 9
0
    /*
     * CREATED:     A. Valberg		MAR 3 2018
     * MODIFIED:    H. Conant		MAR 5 2018
     *  - Updated method signature
     *  - Updated method body code
     * MODIFIED:    H. Conant		MAR 27 2018
     *  - Updated method body code
     * MODIFIED:    H. L'Heureux	APR 03 2018
     *  - Updated method body code
     *
     * AddUnitButton_Click()
     * This method allows the user to add a specified unit in the database.
     *
     * PARAMETERS:
     * object sender - object on the page that is being targeted
     * EventArgs e - event that has triggered the method
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowInfoMessage()
     * UnitController.AddUnit()
     * MessageUserControl.ShowSuccessMessage()
     * MessageUserControl.ShowErrorMessage()
     * ClearPage()
     */
    protected void AddUnitButton_Click(object sender, EventArgs e)
    {
        string pattern = @"^[A-z 0-9 .-]{1,60}$";

        Regex reg = new Regex(pattern);

        Match unitNameFormat = reg.Match(AddUnitNameTB.Text);

        if (string.IsNullOrWhiteSpace(AddUnitNameTB.Text) || AddUnitNameTB.Text.Length > 60 || !unitNameFormat.Success)
        {
            MessageUserControl.ShowInfoMessage("Please enter a unit name up to 60 characters. Unit names can only contain letters, numbers, and the following symbols: . -");
        }
        else
        {
            int tempCareSiteID;
            int.TryParse(CareSiteDDL.SelectedValue, out tempCareSiteID);
            if (tempCareSiteID == 0)
            {
                MessageUserControl.ShowInfoMessage("Please select a care site.");
            }
            else
            {
                UnitDTO tempUnit = new UnitDTO();
                tempUnit.caresiteid = tempCareSiteID;
                tempUnit.unitname   = AddUnitNameTB.Text.Trim();
                try
                {
                    unitController.AddUnit(tempUnit);
                    MessageUserControl.ShowSuccessMessage("Unit " + AddUnitNameTB.Text + " has been added to the " + CareSiteDDL.SelectedItem.Text + " care site.");
                    ClearPage();
                }
                catch (Exception ex)
                {
                    MessageUserControl.ShowErrorMessage("Adding unit failed. Please try again. If error persists, please contact your administrator.", ex);
                }
            }
        }
    }
Ejemplo n.º 10
0
    /*
     * CREATED:     P. Chavez		MAR 22 2018
     * MODIFIED:   C. Stanhope     APR 5 2018
     *  - inputs now trim whitespace
     * MODIFIED:   C. Stanhope     APR 14 2018
     *  - user messages formatted the same as other pages
     *
     * AddAccountButton_Click()
     * This method creates a new account based on the input fields when the button is clicked.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * ErrorMessagesAndValidation.ErrorList()
     * MessageUserControl.ShowInfoMessage()
     * UserManager.GenerateNewPassword()
     * UserManager.AddAccountUser()
     * MessageUserControl.ShowSuccessMessage()
     * MessageUserControl.ShowErrorMessage()
     * MessageUserControl.ShowInfoList()
     */
    protected void AddAccountButton_Click(object sender, EventArgs e)
    {
        //Retrieve the values from the controls
        string firstNameText = FirstNameTextBox.Text.Trim();
        string lastNameText  = LastNameTextBox.Text.Trim();
        string emailText     = EmailTextBox.Text.Trim();
        string authLevelText = AuthorizationLevelRolesRadioList.SelectedValue;
        int    careSiteID    = int.Parse(CareSiteDDL.Visible == false ? "0" : CareSiteDDL.SelectedValue);

        List <string> errorList = new List <string>();
        bool          isValid   = true;

        #region check if any inputs are blank
        if (string.IsNullOrWhiteSpace(firstNameText))
        {
            errorList.Add("First Name");
            isValid = false;
        }

        if (string.IsNullOrWhiteSpace(lastNameText))
        {
            errorList.Add("Last Name");
            isValid = false;
        }

        if (string.IsNullOrWhiteSpace(emailText))
        {
            errorList.Add("Email");
            isValid = false;
        }
        if (string.IsNullOrWhiteSpace(authLevelText))
        {
            errorList.Add("Authorization Level");
            isValid = false;
        }
        #endregion

        if (!isValid)
        {
            ErrorMessagesAndValidation errMessAndVal = new ErrorMessagesAndValidation();
            string errorMessage = errMessAndVal.ErrorList(errorList);
            MessageUserControl.ShowInfoMessage(errorMessage);
        }
        else
        {
            bool          matchRegex     = true;
            List <string> regexErrorList = new List <string>();

            Regex regexName = new Regex(@"^(?m)[A-Za-z][A-Za-z`. -]*$", RegexOptions.IgnoreCase);
            if (!regexName.Match(firstNameText).Success)
            {
                matchRegex = false;
                regexErrorList.Add("First Name can only contain letters, dashes, apostrophes, grave accents, spaces and periods.");
            }
            if (!regexName.Match(lastNameText).Success)
            {
                matchRegex = false;
                regexErrorList.Add("Last Name can only contain letters, dashes, apostrophes, grave accents, spaces and periods.");
            }

            if (!emailText.Contains("@"))
            {
                matchRegex = false;
                regexErrorList.Add("Email must include an '@' symbol.");
            }

            if (careSiteID == 0 && authLevelText == AuthorizationLevelRoles.User)
            {
                matchRegex = false;
                regexErrorList.Add("The Authorization Level User must have a Care Site associated with the account.");
            }

            if (matchRegex)
            {
                try
                {
                    UserManager     userManager    = new UserManager();
                    string          newPassword    = userManager.GenerateNewPassword();
                    ApplicationUser newUserAccount = userManager.AddAccountUser(firstNameText, lastNameText, emailText, authLevelText, careSiteID, newPassword);
                    string          resultMessage  = string.Format("The new account was created! UserName: {0} | Password: {1}", newUserAccount.UserName, newPassword);
                    MessageUserControl.ShowSuccessMessage(resultMessage);

                    //Reset the fields
                    FirstNameTextBox.Text = "";
                    LastNameTextBox.Text  = "";
                    EmailTextBox.Text     = "";
                    AuthorizationLevelRolesRadioList.SelectedValue = AuthorizationLevelRoles.User;
                    CareSiteDDL.SelectedValue = "0";
                    CareSiteDDL.Visible       = true;
                    CareSiteLabel.Visible     = true;
                }
                catch (Exception ex)
                {
                    MessageUserControl.ShowErrorMessage("Adding account failed. Please try again. If error persists, please contact your administrator.", ex);
                }
            }
            else // A regex didn't match
            {
                MessageUserControl.ShowInfoList("The following errors caused adding a management account to fail: ", regexErrorList);
            }
        }
    }
Ejemplo n.º 11
0
    /*
     * CREATED:    C. Stanhope     MAR 21 2018
     * MODIFIED:   C. Stanhope     APR 5 2018
     *  - new word trims whitespace
     * MODIFIED:   C. Stanhope     APR 6 2018
     *  - added try-catch for database access
     *
     * UpdateAccessCodeButton_Click()
     * Triggered when the "UpdateAccessCodeButton" is clicked and is used to update the selected access code's word and status to whatever the user changed it to.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * ValidateAccessCodeWord()
     * AccessCodeController.UpdateAccessCode()
     * ClearPage()
     * ResetSearchFilters()
     * MessageUserControl.ShowInfoMessage()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void UpdateAccessCodeButton_Click(object sender, EventArgs e)
    {
        #region getting values from page
        string newWord = UpdateAccessCodeTextBox.Text.ToLower().Trim();
        bool   newStatus;
        if (UpdateAccessActiveStatusCodeRadioButtonList.SelectedItem.Value.Equals("y"))
        {
            newStatus = true;
        }
        else
        {
            newStatus = false;
        }
        #endregion

        if (newWord.Equals(selectedAccessCode.accesscodeword) && newStatus == selectedAccessCode.activeyn) // no changes made
        {
            MessageUserControl.ShowInfoMessage("No changes to update.");
        }
        else if (newWord.Equals(selectedAccessCode.accesscodeword)) // status changed but word did not
        {
            selectedAccessCode.activeyn = newStatus;
            try
            {
                accessCodeController.UpdateAccessCode(selectedAccessCode);

                if (newStatus == true)
                {
                    MessageUserControl.ShowSuccessMessage("Access code '" + newWord + "' was marked as active.");
                }
                else
                {
                    MessageUserControl.ShowSuccessMessage("Access code '" + newWord + "' was marked as inactive.");
                }

                ClearPage();
                ResetSearchFilters();
            }
            catch (Exception ex)
            {
                MessageUserControl.ShowErrorMessage("Updating access code failed. Please try again. If error persists, please contact your administrator.", ex);
            }
        }
        else // word was changed
        {
            if (ValidateAccessCodeWord(newWord))
            {
                selectedAccessCode.accesscodeword = newWord;
                selectedAccessCode.activeyn       = newStatus;

                try
                {
                    accessCodeController.UpdateAccessCode(selectedAccessCode);

                    MessageUserControl.ShowSuccessMessage("Access code '" + newWord + "' updated.");
                }
                catch (Exception ex)
                {
                    MessageUserControl.ShowErrorMessage("Updating access code failed. Please try again. If error persists, please contact your administrator.", ex);
                }

                ClearPage();
                ResetSearchFilters();
            }
            else // not a valid word
            {
                MessageUserControl.ShowInfoMessage("The access code '" + newWord + "' is not valid. Please ensure the access code is between 6 and 8 letters (no numbers or symbols are permitted).");
            }
        }
    }
Ejemplo n.º 12
0
    /*
     * CREATED:     C. Stanhope		MAR 23 2018
     * MODIFIED:   C. Stanhope     MAR 24 2018
     *  - Added validation, finished method
     * MODIFIED:   C. Stanhope     APR 5 2018
     *  - trim whitespace on inputs
     *  - validation now matches add care site
     * MODIFIED:   C. Stanhope     APR 6 2018
     *  - added try-catch for database access
     * MODIFIED:   C. Stanhope     APR 17 2018
     *  - fixed city regex to limit at 30 characters
     *  - fixed care site regex to limit at 80 characters
     *
     * UpdateCareSiteButton_Click()
     * Used to update a care site in the database. Validates all input fields and updates only if valid.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowInfoMessage()
     * CareSiteController.GetCareSiteByCareSiteID()
     * MessageUserControl.ShowErrorMessage()
     * ErrorMessagesAndValidation.ErrorList()
     */
    protected void UpdateCareSiteButton_Click(object sender, EventArgs e)
    {
        if (selectedCareSite != null)
        {
            bool          isValid   = true;
            List <string> errorList = new List <string>();

            #region regexes for validation
            Regex careSiteRegex = new Regex(@"^[A-z]{1}[A-z 0-9 .-]{4,79}$");
            Regex addressRegex  = new Regex(@"^[A-z 0-9 .#-]{1,40}$");
            Regex cityRegex     = new Regex(@"^[A-z]{1}[A-z .-]{0,29}$");
            #endregion

            #region get values from page and validate
            string careSiteName = CareSiteNameTextBox.Text.Trim();
            if (!careSiteRegex.IsMatch(careSiteName))
            {
                errorList.Add("Care site must be a minimum of 5 characters and a maximum of 80 characters long. It must start with a letter and can contain letters, numbers, and the following symbols: . -");
                isValid = false;
            }

            string address = AddressTextBox.Text.Trim();
            if (!addressRegex.IsMatch(address))
            {
                errorList.Add("Address must be a minimum of 1 character and a maximum of 40 characters long. It can contain letters, numbers, and the following symbols: # . -");
                isValid = false;
            }

            string city = CityTextBox.Text.Trim();
            if (!cityRegex.IsMatch(city))
            {
                errorList.Add("City must be a minimum of 1 letter and a maximum of 30 characters long. It must start with a letter and can contain letters and the following symbols: . -");
                isValid = false;
            }

            string province = ProvinceDDL.SelectedValue;

            #endregion

            if (isValid)
            {
                #region see if data changed
                bool dataChanged = false;
                if (selectedCareSite.caresitename != careSiteName)
                {
                    dataChanged = true;
                }
                else if (selectedCareSite.address != address)
                {
                    dataChanged = true;
                }
                else if (selectedCareSite.city != city)
                {
                    dataChanged = true;
                }
                else if (selectedCareSite.province != province)
                {
                    dataChanged = true;
                }
                #endregion

                if (dataChanged)
                {
                    #region put valid data into selectedCareSite, add to database, show success message, change DDL
                    selectedCareSite.caresitename = careSiteName;
                    selectedCareSite.address      = address;
                    selectedCareSite.city         = city;
                    selectedCareSite.province     = province;

                    try
                    {
                        careSiteController.UpdateCareSite(selectedCareSite);

                        MessageUserControl.ShowSuccessMessage("The " + selectedCareSite.caresitename + " care site was successfully updated.");

                        CareSiteDDL.SelectedItem.Text = selectedCareSite.caresitename;
                    }
                    catch (Exception ex)
                    {
                        MessageUserControl.ShowErrorMessage("Updating care site failed. Please try again. If error persists, please contact your administrator.", ex);
                    }
                    #endregion
                }
                else
                {
                    MessageUserControl.ShowInfoMessage("No changes to save.");
                }
            }
            else
            {
                #region show user message with "errors"

                ErrorMessagesAndValidation errMessAndVal = new ErrorMessagesAndValidation();

                string errorMessage = errMessAndVal.ErrorList(errorList);

                //MessageUserControl.ShowInfoMessage(errorMessage);
                MessageUserControl.ShowInfoList("The following errors caused adding a care site to fail: ", errorList);
                #endregion
            }
        }
        else // no care site selected
        {
            MessageUserControl.ShowErrorMessage("No care site selected. The \"Update Care Site\" button should not be available if no care site is selected. Please try again. If error persists, please contact your administrator.");
        }
    }
Ejemplo n.º 13
0
    /*
     * CREATED:     E. Lautner		APR 1 2018
     * MODIFIED:   C. Stanhope     APR 14 2018
     *  - changed validation to match the account_add validation
     *
     * ModifyUser_Click()
     * Gathers all given information on the page about the selected account. Sends this information to the userManager so that the account can be updated.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowSuccessMessage()
     * MessageUserControl.ShowErrorMessage()
     * UserManager.ModifyAccount()
     * UserManager.GetRoles()
     */
    protected void ModifyUser_Click(object sender, EventArgs e)
    {
        {
            sentUserName = Request.QueryString["id"];
            if (sentUserName == "" || sentUserName == null)
            {
                MessageUserControl.ShowErrorMessage("An account has not been selected. Please navigate back to the Account Search page and select an account. If error persists, please contact your administrator.");
            }

            else
            {
                //Retrieve the values from the controls
                string firstNameText = FirstNameTB.Text.Trim();
                string lastNameText  = LastNameTB.Text.Trim();
                string emailText     = EmailTB.Text.Trim();
                string authLevelText = AuthorizationLevelRolesRadioList.SelectedValue;
                int    careSiteID    = int.Parse(CareSiteDDL.Visible == false ? "0" : CareSiteDDL.SelectedValue);

                List <string> errorList = new List <string>();
                bool          isValid   = true;

                #region check if any inputs are blank
                if (string.IsNullOrWhiteSpace(firstNameText))
                {
                    errorList.Add("First Name");
                    isValid = false;
                }

                if (string.IsNullOrWhiteSpace(lastNameText))
                {
                    errorList.Add("Last Name");
                    isValid = false;
                }

                if (string.IsNullOrWhiteSpace(emailText))
                {
                    errorList.Add("Email");
                    isValid = false;
                }
                if (string.IsNullOrWhiteSpace(authLevelText))
                {
                    errorList.Add("Authorization Level");
                    isValid = false;
                }
                #endregion

                if (!isValid)
                {
                    ErrorMessagesAndValidation errMessAndVal = new ErrorMessagesAndValidation();
                    string errorMessage = errMessAndVal.ErrorList(errorList);
                    MessageUserControl.ShowInfoMessage(errorMessage);
                }
                else
                {
                    if (!emailText.Contains("@"))
                    {
                        MessageUserControl.ShowInfoMessage("Email must include an '@' symbol.");
                    }
                    else
                    {
                        if (System.Text.RegularExpressions.Regex.IsMatch(FirstNameTB.Text, @"^(?m)[A-Za-z][A-Za-z`. -]*$") && System.Text.RegularExpressions.Regex.IsMatch(LastNameTB.Text, @"^(?m)[A-Za-z][A-Za-z`. -]*$"))
                        {
                            if (int.Parse(CareSiteDDL.SelectedValue) == 0 && AuthorizationLevelRolesRadioList.SelectedValue == AuthorizationLevelRoles.User)
                            {
                                MessageUserControl.ShowInfoMessage("Authorization Level: User, must be associated with a care site");
                            }
                            else
                            {
                                try
                                {
                                    UserManager userManager  = new UserManager();
                                    var         selectedUser = userManager.FindByName(UsernameLabel.Text);
                                    var         userRoles    = userManager.GetRoles(selectedUser.Id);

                                    string userRole = string.Join("", userRoles.ToArray());

                                    string newUserName = userManager.ModifyAccount(UsernameLabel.Text, FirstNameTB.Text.Trim(), LastNameTB.Text.Trim(), EmailTB.Text.Trim(), int.Parse(CareSiteDDL.SelectedValue), userRole, AuthorizationLevelRolesRadioList.SelectedValue);
                                    if (newUserName != UsernameLabel.Text)
                                    {
                                        string resultMessage = string.Format("Update successful, new UserName is {0} ", newUserName);
                                        MessageUserControl.ShowSuccessMessage(resultMessage);
                                        UsernameLabel.Text = newUserName;
                                    }

                                    else
                                    {
                                        string resultMessage = string.Format("Update successful for user: {0}", UsernameLabel.Text);
                                        MessageUserControl.ShowSuccessMessage(resultMessage);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MessageUserControl.ShowErrorMessage("Update Failed. Please try again. If error persists, please contact your administrator. Error Message: " + ex.Message);
                                }
                            }
                        }
                        else
                        {
                            MessageUserControl.ShowInfoMessage("First Name and Last Name can only contain letters, dashes, apostrophes, grave accents, spaces and periods.");
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 14
0
    /*
     * CREATED:     C. Stanhope		MAR 23 2018
     * MODIFIED:   C. Stanhope     MAR 24 2018
     *  - moved error list method to its own class and call it
     *  - changed validation to account for care site name length
     * MODIFIED:   C. Stanhope     APR 5 2018
     *  - trim whitespace on inputs
     * MODIFIED:   C. Stanhope     APR 6 2018
     *  - added try-catch for database access
     * MODIFIED:   C. Stanhope     APR 17 2018
     *  - fixed city regex to limit at 30 characters
     *  - fixed care site regex to limit at 80 characters
     *
     * AddCareSiteButton_Click()
     * Used to add a care site to the database. Validates all input fields.
     *
     * PARAMETERS:
     * object sender - references the object that raised the Page_Load event
     * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty)
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * CareSiteController.AddCareSite()
     * MessageUserControl.ShowSuccessMessage()
     * MessageUserControl.ShowInfoMessage()
     * ErrorMessagesAndValidation.ErrorList()
     */
    protected void AddCareSiteButton_Click(object sender, EventArgs e)
    {
        bool          isValid   = true;
        List <string> errorList = new List <string>();

        #region regexes for validation
        Regex careSiteRegex = new Regex(@"^[A-z]{1}[A-z 0-9 .-]{4,79}$");
        Regex addressRegex  = new Regex(@"^[A-z 0-9 .#-]{1,40}$");
        Regex cityRegex     = new Regex(@"^[A-z]{1}[A-z .-]{0,29}$");
        #endregion

        #region get values from page and validate
        string careSiteName = CareSiteNameTextBox.Text.Trim();
        if (!careSiteRegex.IsMatch(careSiteName))
        {
            errorList.Add("Care site must be a minimum of 5 characters and a maximum of 80 characters long. It must start with a letter and can contain letters, numbers, and the following symbols: . -");
            isValid = false;
        }

        string address = AddressTextBox.Text.Trim();
        if (!addressRegex.IsMatch(address))
        {
            errorList.Add("Address must be a minimum of 1 letter and a maximum of 40 characters long. It can contain letters, numbers, and the following symbols: # . -");
            isValid = false;
        }

        string city = CityTextBox.Text.Trim();
        if (!cityRegex.IsMatch(city))
        {
            errorList.Add("City must be a minimum of 1 letter and a maximum of 30 characters long. It must start with a letter and can contain letters and the following symbols: . -");
            isValid = false;
        }

        string province = ProvinceDDL.SelectedValue;
        if (ProvinceDDL.SelectedIndex == 0)
        {
            errorList.Add("A province must be selected from the drop-down list");
            isValid = false;
        }

        #endregion

        if (isValid)
        {
            #region put valid data into DTO, add to database, show success message, clear page
            CareSiteDTO newCareSite = new CareSiteDTO();

            newCareSite.caresitename = careSiteName;
            newCareSite.address      = address;
            newCareSite.city         = city;
            newCareSite.province     = province;

            CareSiteController careSiteController = new CareSiteController();
            try
            {
                careSiteController.AddCareSite(newCareSite);

                // show message, clear page
                MessageUserControl.ShowSuccessMessage("New care site " + careSiteName + " was successfully added. Please navigate to the Manage Units page to add units to the new care site.");

                CareSiteNameTextBox.Text  = "";
                AddressTextBox.Text       = "";
                CityTextBox.Text          = "";
                ProvinceDDL.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageUserControl.ShowErrorMessage("Adding care site failed. Please try again. If error persists, please contact your administrator.", ex);
            }
            #endregion
        }
        else
        {
            MessageUserControl.ShowInfoList("The following errors caused adding a care site to fail: ", errorList);
        }
    }