protected void ListViewUsers_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {
            bool          isSuccsesfullyUpdate    = false;
            Panel         validationMsg           = (Panel)this.ListViewUsers.Items[e.ItemIndex].FindControl("editNameContainerIsValid");
            HtmlInputFile uploadEditImage         = (HtmlInputFile)this.ListViewUsers.Items[e.ItemIndex].FindControl("UploadProfileImageEdit");
            TextBox       textBoxUsername         = (TextBox)this.ListViewUsers.Items[e.ItemIndex].FindControl("TextBoxUsernameEdit");
            TextBox       textBoxResetPassword    = (TextBox)this.ListViewUsers.Items[e.ItemIndex].FindControl("TextBoxResetPassword");
            Literal       literalAppName          = (Literal)this.ListViewUsers.Items[e.ItemIndex].FindControl("LiteralAppNameEdit");
            Literal       literalOldUserName      = (Literal)this.ListViewUsers.Items[e.ItemIndex].FindControl("LiteralOldUserName");
            CheckBoxList  CheckBoxListRolesOfUser = (CheckBoxList)this.ListViewUsers.Items[e.ItemIndex].FindControl("CheckBoxListRolesOfUser");


            UserApplication updateUser = new UserApplication();

            updateUser.AppName = literalAppName.Text;
            updateUser.OldUsernameForUpdate = literalOldUserName.Text;
            updateUser.NewUsernameForUpdate = textBoxUsername.Text;
            updateUser.ResetUserPassword    = textBoxResetPassword.Text;

            foreach (System.Web.UI.WebControls.ListItem role in CheckBoxListRolesOfUser.Items)
            {
                if (role.Selected == true && !updateUser.UserRoles[0].Equals("The user isn't in roles"))
                {
                    updateUser.UserRoles.Add(role.Text);
                }
                if (role.Selected == true && updateUser.UserRoles[0].Equals("The user isn't in roles"))
                {
                    updateUser.UserRoles[0] = role.Text;
                }
            }

            //this.Page.Validate("ValidationGroupEditUser");
            if (!String.IsNullOrEmpty(updateUser.NewUsernameForUpdate))
            {
                isSuccsesfullyUpdate = UsersApplicationsBLL.UpdateUserApp(updateUser, uploadEditImage);

                if (isSuccsesfullyUpdate)
                {
                    Utility.ShowMessageAfterPOST(Page, Utility.GetStatusMessage(StatusMessages.SuccessfullUpdateUser) + " " + updateUser.NewUsernameForUpdate);
                    ListViewUsers.EditIndex = -1;
                }
                //else
                //{
                //    Utility.ShowMessageAfterPOST(Page, "Something wrongs");
                //}
                PopulateListViewUsers();
                validationMsg.Visible = false;
            }
            if (String.IsNullOrEmpty(updateUser.NewUsernameForUpdate))
            {
                validationMsg.Visible = true;
            }
        }
        protected void ButtonInsert_Click(object sender, EventArgs e)
        {
            //this.rolesIsValid.Visible = false;
            bool isInsertSuccsessfully = false;

            this.Page.Validate("ValidationGroupNames");
            if (this.Page.IsValid)
            {
                HideValidationMessages();
                try
                {
                    List <string> checkedRoles = new List <string>();
                    foreach (System.Web.UI.WebControls.ListItem role in this.CheckBoxListApplicationRoles.Items)
                    {
                        if (role.Selected)
                        {
                            checkedRoles.Add(role.Value);
                            this.rolesIsValid.Visible = false;
                        }
                        else
                        {
                            this.rolesIsValid.Visible = true;
                        }
                    }
                    if (checkedRoles.Count == 0)
                    {
                        this.rolesIsValid.Visible = true;
                    }
                    UserApplication newUser = new UserApplication();
                    newUser.AppName       = this.DropDownApplicationNewUser.SelectedItem.Text;
                    newUser.UserName      = this.TextBoxUsername.Text;
                    newUser.Password      = this.TextBoxPassword.Text;
                    newUser.UserRoles     = checkedRoles;
                    isInsertSuccsessfully = UsersApplicationsBLL.CreateNewUserApp(newUser, this.UploadProfileImage);

                    if (isInsertSuccsessfully)
                    {
                        Utility.Clear(this.InsertUserContent.Controls);
                        PopulateListViewUsers();
                        Utility.ShowMessageAfterPOST(Page, Utility.GetStatusMessage(StatusMessages.SuccessfullInsertNewUser));
                    }
                }
                catch (MembershipCreateUserException)
                {
                    Utility.ShowMessageAfterPOST(Page, Utility.GetStatusMessage(StatusMessages.UserAlreadyExist));
                }
            }
            else
            {
                ShowValidationMessages();
            }
        }
 private void PopulateListViewUsers()
 {
     if (this.DropDownApplications.SelectedValue == "---Select Application---" || this.DropDownApplications.SelectedValue == "All" || this.DropDownApplications.SelectedValue == "")
     {
         this.ListViewUsers.DataSource = UsersApplicationsBLL.GetAllUsersApps(SelectApplications.All);
         this.ListViewUsers.DataBind();
     }
     else
     {
         this.ListViewUsers.DataSource = UsersApplicationsBLL.GetAllUsersApps(SelectApplications.SpecifucApplication, this.DropDownApplications.SelectedItem.Text);
         this.ListViewUsers.DataBind();
     }
 }
        protected void ButtonExportToPDF_Click(object sender, EventArgs e)
        {
            List <UserApplication> users = new List <UserApplication>();
            string officeUsers           = "";

            if (this.DropDownApplications.SelectedValue == "---Select Application---" || this.DropDownApplications.SelectedValue == "All" || this.DropDownApplications.SelectedValue == "")
            {
                users       = UsersApplicationsBLL.GetAllUsersApps(SelectApplications.All);
                officeUsers = "All";
            }
            else
            {
                users       = UsersApplicationsBLL.GetAllUsersApps(SelectApplications.SpecifucApplication, this.DropDownApplications.SelectedItem.Text);
                officeUsers = this.DropDownApplications.SelectedValue;
            }
            ExportToPDF.Users(Page.Server, users, officeUsers, this.savePdfVersion);

            string pdfName = "http://res.cloudinary.com/hzgrm4rdh/image/upload/" + this.savePdfVersion.Value + "/PDFs/Users_" + officeUsers + ".pdf";

            Response.Redirect(pdfName);
        }
        protected void testBtn_Click(object sender, EventArgs e)
        {
            //CreatePDF();
            List <UserApplication> users = new List <UserApplication>();
            string officeUsers           = "";

            if (this.DropDownApplications.SelectedValue == "---Select Application---" || this.DropDownApplications.SelectedValue == "All" || this.DropDownApplications.SelectedValue == "")
            {
                users       = UsersApplicationsBLL.GetAllUsersApps(SelectApplications.All);
                officeUsers = "All";
            }
            else
            {
                users       = UsersApplicationsBLL.GetAllUsersApps(SelectApplications.SpecifucApplication, this.DropDownApplications.SelectedItem.Text);
                officeUsers = this.DropDownApplications.SelectedValue;
            }
            ExportToPDF.Users(Page.Server, users, officeUsers, this.savePdfVersion);

            Response.ContentType = "Application/pdf";
            Response.AppendHeader("Content-Disposition", "attachment; filename=Users.pdf");
            Response.TransmitFile(Server.MapPath("~/App_Data/Users.pdf"));
            Response.End();
        }
        protected void ListViewUsers_ItemDeleting(object sender, ListViewDeleteEventArgs e)
        {
            bool    isDeleteSuccsessfully = false;
            Label   literalUsername       = (Label)this.ListViewUsers.Items[e.ItemIndex].FindControl("LiteralUserName");
            Literal literalAppName        = (Literal)this.ListViewUsers.Items[e.ItemIndex].FindControl("LiteralAppName");

            UserApplication deleteUser = new UserApplication();

            deleteUser.AppName  = literalAppName.Text;
            deleteUser.UserName = literalUsername.Text;

            isDeleteSuccsessfully = UsersApplicationsBLL.DeleteUserApp(deleteUser);

            if (isDeleteSuccsessfully)
            {
                Utility.ShowMessageAfterAsync(Page, Utility.GetStatusMessage(StatusMessages.SuccessfullDeleteUser));
            }
            else
            {
                Utility.ShowMessageAfterAsync(Page, "Something wrongs with delete user");
            }
            PopulateListViewUsers();
        }