示例#1
0
        protected void BtnSubmitClick(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateTransactionPaymentControl())
                {
                    return;
                }

                var k = UpdateTransactionPayment();
                if (k < 1)
                {
                    ErrorDisplay1.ShowError("The Transaction Payment information could not be Updated.");
                    return;
                }

                if (!AddTransactionPaymentHistory(k))
                {
                    ErrorDisplay1.ShowError("The Transaction Payment information could not be Updated.");
                    return;
                }

                ErrorDisplay1.ShowSuccess("The Transaction Payment information was updated successfully.");

                if (!LoadTransactionPayments())
                {
                }
            }

            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                ErrorDisplay1.ShowError("An unknown error was encountered. Please try again soon or contact the Admin.");
            }
        }
        protected void BtnUpdateRecordClick(Object sender, EventArgs e)
        {
            ErrorDisplay1.ClearError();
            if (txtEmail.Text == "")
            {
                ErrorDisplay1.ShowError("Email Address is required");
                return;
            }
            int k = ValidateRole();

            if (k < 1)
            {
                ErrorDisplay1.ShowError("User must belong to at least a role");
                return;
            }

            var mUser = Membership.GetUser(txtUserName.Text.Trim());

            if (mUser == null)
            {
                ErrorDisplay1.ShowError("Fatal Error occurred! Please try again soon");
                return;
            }
            mUser.Email      = txtEmail.Text.Trim();
            mUser.IsApproved = chkActive.Checked;
            Membership.UpdateUser(mUser);
            string[] mRoles = Roles.GetRolesForUser(txtUserName.Text.Trim());

            if (mRoles != null)
            {
                if (mRoles.Length > 0)
                {
                    Roles.RemoveUserFromRoles(txtUserName.Text.Trim(), mRoles);
                }
            }

            var mNewRoles = new string[k];
            int h         = 0;

            for (int i = 0; i < chkRoles.Items.Count; i++)
            {
                if (chkRoles.Items[i].Selected)
                {
                    mNewRoles[h] = chkRoles.Items[i].Value.Trim();
                    h           += 1;
                }
            }
            if (mNewRoles[0].Length > 0)
            {
                Roles.AddUserToRoles(txtUserName.Text.Trim(), mNewRoles);
                BindUsersList();
                HideTables();
                listDV.Visible = true;
                ErrorDisplay1.ShowSuccess("User Information was updated successfully.");
            }
            else
            {
                ErrorDisplay1.ShowError("Fatal Error occurred! User information could not be updated");
            }
        }
        protected void DgPortalRoleDeleteCommand(Object source, DataGridCommandEventArgs e)
        {
            ErrorDisplay1.ClearError();
            try
            {
                dgPortalRole.SelectedIndex = e.Item.ItemIndex;
                int    id       = (DataCheck.IsNumeric(dgPortalRole.DataKeys[e.Item.ItemIndex].ToString())) ? int.Parse(dgPortalRole.DataKeys[e.Item.ItemIndex].ToString()) : 0;
                string roleName = ((LinkButton)dgPortalRole.SelectedItem.FindControl("lblRole")).Text;
                if (roleName.Length == 0)
                {
                    ErrorDisplay1.ShowError("Process Error! Please try again later");
                    return;
                }

                //Check if the role name is PortalAdmin, then terminate the process
                if (roleName.ToLower() == "PortalAdmin".ToLower())
                {
                    ErrorDisplay1.ShowError("Sorry, you can not delete this role");
                    return;
                }
                //Check to see that the current user has right to delete role
                if (!Page.User.IsInRole("PortalAdmin"))
                {
                    ErrorDisplay1.ShowError("Sorry, you are not authorized to delete a role");
                }

                //If role has registered users, remove the users from the role.
                try
                {
                    if (Roles.GetUsersInRole(roleName).Length > 0)
                    {
                        string[] mUsersInRole = Roles.GetUsersInRole(roleName);
                        Roles.RemoveUsersFromRole(mUsersInRole, roleName);
                    }
                }
                catch (Exception ex)
                {
                    ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                    ErrorDisplay1.ShowError(ex.Message);
                    return;
                }
                //'Now delete the role!
                if (Roles.DeleteRole(roleName, false))
                {
                    BindRoleItems();
                    ErrorDisplay1.ShowSuccess("Role Item Was Removed");
                }
                else
                {
                    ErrorDisplay1.ShowError("Role Item could not be removed");
                }
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                ErrorDisplay1.ShowError(ex.Message);
                return;
            }
        }
        protected void BtnprocessAssetCategoryClick(object sender, EventArgs e)
        {
            ErrorDisplay1.ClearError();
            try
            {
                if (!ValidateControls())
                {
                    return;
                }

                switch (int.Parse(btnProcessAssetCategory.CommandArgument))
                {
                case 1:
                    if (!AddAssetCategory())
                    {
                        return;
                    }

                    break;

                case 2:
                    if (!UpdateAssetCategory())
                    {
                        return;
                    }

                    break;

                default:
                    ErrorDisplayProcessAssetCategory.ShowError("Invalid process call!");
                    mpeProcessAssetCategory.Show();
                    break;
                }

                if (!LoadAssetCategories())
                {
                    return;
                }

                ErrorDisplay1.ShowSuccess("Asset Category information was successfully processed.");
            }

            catch (Exception ex)
            {
                ErrorDisplay1.ShowError("An unknown error was encountered. Please try again soon or contact the Admin. Please try again soon or contact the Admin.");
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                throw;
            }
        }
        protected void DgPortalUsersDeleteCommand(Object source, DataGridCommandEventArgs e)
        {
            ErrorDisplay1.ClearError();
            if (!Page.User.IsInRole("PortalAdmin"))
            {
                ErrorDisplay1.ShowError("Sorry: You are not authorized to delete a user");
                return;
            }
            try
            {
                dgPortalUsers.SelectedIndex = e.Item.ItemIndex;
                var userId = (DataCheck.IsNumeric(dgPortalUsers.DataKeys[e.Item.ItemIndex].ToString())) ? long.Parse(dgPortalUsers.DataKeys[e.Item.ItemIndex].ToString()) : 0;
                if (userId < 1)
                {
                    ErrorDisplay1.ShowError("Invalid Selection");
                    return;
                }
                string mName = ((LinkButton)dgPortalUsers.SelectedItem.FindControl("lblUserName")).Text;
                if (mName.Length < 2)
                {
                    ErrorDisplay1.ShowError("No User Item Selected");
                    return;
                }
                if (HttpContext.Current.User.Identity.Name.ToLower() == mName.ToLower())
                {
                    ErrorDisplay1.ShowError("You cannot delete the current user!");
                    return;
                }
                var mUser = Membership.GetUser(mName, false);
                if (mUser == null)
                {
                    ErrorDisplay1.ShowError("Username not found!");
                    return;
                }
                mUser.IsApproved = false;
                Membership.UpdateUser(mUser);

                //Membership.DeleteUser(mName);
                //new PortalServiceManager().DeletePortalUser(userId);
                BindUsersList();
                ErrorDisplay1.ShowSuccess("User Record Was Deleted");
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                ErrorDisplay1.ShowError(ex.Message);
            }
        }
示例#6
0
        private long UpdateTransactionPayment()
        {
            ErrorDisplay1.ClearError();
            try
            {
                if (Session["_staffExpenseTransactionPayment"] == null)
                {
                    ErrorDisplay1.ShowError("Expense Transaction Payment list is empty or session has expired.");
                    return(0);
                }

                var expenseTransactionPayment = Session["_staffExpenseTransactionPayment"] as StaffExpenseTransactionPayment;

                if (expenseTransactionPayment == null || expenseTransactionPayment.StaffExpenseTransactionId < 1)
                {
                    ErrorDisplayCompletePayment.ShowError("Invalid record selection.");
                    mpeSelectDateRangePopup.Show();
                    return(0);
                }

                expenseTransactionPayment.Balance                   = expenseTransactionPayment.Balance - double.Parse(txtAmountPaid.Value.Trim());
                expenseTransactionPayment.TotalAmountPayable        = double.Parse(txtApprovedTotalAmount.Text.Trim());
                expenseTransactionPayment.StaffExpenseTransactionId = expenseTransactionPayment.StaffExpenseTransactionId;
                expenseTransactionPayment.LastPaymentDate           = DateMap.GetLocalDate();
                expenseTransactionPayment.LastPaymentTime           = DateMap.GetLocalTime();
                expenseTransactionPayment.Status     = 1;
                expenseTransactionPayment.AmountPaid = double.Parse(txtAmountPaid.Value.Trim()) + expenseTransactionPayment.AmountPaid;

                var k = ServiceProvider.Instance().GetStaffExpenseTransactionPaymentServices().UpdateStaffExpenseTransactionPayment(expenseTransactionPayment);

                if (k < 1)
                {
                    ErrorDisplay1.ShowError("The Transaction information could not be updated");
                    return(0);
                }

                ErrorDisplay1.ShowSuccess("Expense Transaction Information was successfully updated");
                return(k);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                ErrorDisplay1.ShowError("An unknown error was encountered. Please try again soon or contact the Admin.");
                return(0);
            }
        }
 protected void RemoveItem(int id)
 {
     try
     {
         if (id > 0)
         {
             if (!(new PortalServiceManager()).DeleteSiteMap(id))
             {
                 ErrorDisplay1.ShowError("Process Failed!");
                 return;
             }
         }
         BindSitemMapItemList();
         ErrorDisplay1.ShowSuccess("Portal SiteMap Item Was Removed");
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
     }
 }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Page.Validate("regValidation");
            if (!Page.IsValid)
            {
                ErrorDisplay1.ShowError("Please provider all required information");
                return;
            }
            MembershipUser memUser = Membership.GetUser(HttpContext.Current.User.Identity.Name.Trim());

            if (memUser == null)
            {
                ErrorDisplay1.ShowError("User Profile cannot be obtained! Please try again soon");
                return;
            }
            if (!memUser.ChangePassword(this.txtCurrentPassword.Text, this.txtNewPassword.Text))
            {
                ErrorDisplay1.ShowError("Password Was Not Modified! Please check old password and try again");
                return;
            }
            ErrorDisplay1.ShowSuccess("Password Was Changed Successfully");
        }
        private bool AddAssetCategory()
        {
            try
            {
                var newAssetCategory = new AssetCategory
                {
                    Name   = txtName.Text.Trim(),
                    Code   = long.Parse(txtCode.Text.Trim()),
                    Status = chkAssetCategory.Checked ? 1 : 0
                };
                var k = ServiceProvider.Instance().GetAssetCategoryServices().AddAssetCategoryCheckDuplicate(newAssetCategory);

                if (k < 1)
                {
                    if (k == -3)
                    {
                        ErrorDisplay1.ShowError("Asset Category already exists.");
                        txtName.Focus();
                        mpeProcessAssetCategory.Show();
                        return(false);
                    }
                    ErrorDisplay1.ShowError("Asset Category could not be added. Please contact the Admin.");
                    txtName.Focus();
                    mpeProcessAssetCategory.Show();
                    return(false);
                }

                ErrorDisplay1.ShowSuccess("Asset Category was added successfully.");
                return(true);
            }

            catch (Exception ex)
            {
                ErrorDisplay1.ShowError("An unknown error was encountered. Please try again soon or contact the Admin. Please try again soon or contact the Admin.");
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(false);
            }
        }
        private void SaveData()
        {
            try
            {
                if (Session["defaultUserProfile"] == null)
                {
                    ErrorDisplay1.ShowError("Session Expired! Please try again soon");
                    return;
                }

                portaluser mUser;
                try
                {
                    mUser = (portaluser)Session["defaultUserProfile"];
                    if (mUser == null)
                    {
                        ErrorDisplay1.ShowError("Session Expired! Please try again soon");
                        return;
                    }
                }
                catch
                {
                    ErrorDisplay1.ShowError("Session Expired! Please try again soon");
                    return;
                }

                mUser.DateRegistered = XPLUG.WEBTOOLS.DateMap.GetLocalDate();
                mUser.Designation    = this.txtDesignation.Text.Trim();
                mUser.FirstName      = this.txtFirstName.Text.Trim();
                mUser.LastName       = this.txtLastName.Text.Trim();
                mUser.MobileNumber   = txtMobileNumber.Text.Trim();
                var k = new PortalServiceManager().UpdatePortalUser(mUser);
                if (k < 1)
                {
                    if (k == -3)
                    {
                        ErrorDisplay1.ShowError("The user name already exists.");
                        return;
                    }

                    if (k == -4)
                    {
                        ErrorDisplay1.ShowError("A user with the same mobile number already exists.");
                        return;
                    }

                    if (k == -5)
                    {
                        ErrorDisplay1.ShowError("The user information already exists.");
                        return;
                    }
                }

                MembershipUser myuser = Membership.GetUser(HttpContext.Current.User.Identity.Name.ToString(CultureInfo.InvariantCulture));
                if (myuser != null)
                {
                    myuser.Email = this.txtEmail.Text;
                    Membership.UpdateUser(myuser);
                }

                Session["defaultUserProfile"] = mUser;
                ErrorDisplay1.ShowSuccess("Profile Information Was Updated");
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                ErrorDisplay1.ShowError(ex.Message);
                return;
            }
        }
        protected void BtnSubmitClick(Object sender, EventArgs e)
        {
            ErrorDisplay1.ClearError();
            try
            {
                if (ddlTabParent.SelectedIndex == 0)
                {
                    ErrorDisplay1.ShowError("Please select parent tab");
                    return;
                }

                if (txtTabName.Text == "")
                {
                    ErrorDisplay1.ShowError("Tab name is required");
                    return;
                }

                if (ddlTabType.SelectedIndex == 0)
                {
                    ErrorDisplay1.ShowError("Please select tab type");
                    return;
                }


                if (ValidateRole() < 1)
                {
                    ErrorDisplay1.ShowError("You must select at least one role");
                    return;
                }


                string mRoles = String.Empty;
                for (int i = 0; i < chkRoles.Items.Count; i++)
                {
                    if (chkRoles.Items[i].Selected)
                    {
                        mRoles += ";" + chkRoles.Items[i].Value;
                    }
                }

                if (mRoles.Length > 0)
                {
                    if (mRoles.StartsWith(";"))
                    {
                        mRoles = mRoles.Substring(1);
                    }
                    if (mRoles.EndsWith(";"))
                    {
                        mRoles = mRoles.Substring(0, mRoles.Length - 1);
                    }
                }
                else
                {
                    ErrorDisplay1.ShowError("Tab name is required");
                    return;
                }


                var mInfo = new sitemap
                {
                    DateCreated = DateMap.GetLocalDate(),
                    Description = txtDescription.Text,
                    Parent      = (DataCheck.IsNumeric(ddlTabParent.SelectedValue.ToString(CultureInfo.InvariantCulture)))? int.Parse(ddlTabParent.SelectedValue.ToString(CultureInfo.InvariantCulture)): 0,
                    Roles       = mRoles,
                    Title       = txtTabName.Text,
                    TabType     = (DataCheck.IsNumeric(ddlTabType.SelectedValue.ToString(CultureInfo.InvariantCulture)))? int.Parse(ddlTabType.SelectedValue.ToString(CultureInfo.InvariantCulture)): 0,
                    TabOrder    = (DataCheck.IsNumeric(ddlTabOrder.SelectedValue.ToString(CultureInfo.InvariantCulture)))? int.Parse(ddlTabOrder.SelectedValue.ToString(CultureInfo.InvariantCulture)): 0,
                    Url         = txtLink.Text
                };


                switch (int.Parse(btnSubmit.CommandArgument))
                {
                case 1:     //Add
                    long k = (new PortalServiceManager()).AddSiteMap(mInfo);
                    if (k < 1)
                    {
                        if (k == -1)
                        {
                            ErrorDisplay2.ShowError("Duplicate Tab Name! This Tab Name is already registered");
                            mpeDisplayJobDetails.Show();
                            return;
                        }
                        ErrorDisplay2.ShowError("Item was not be added");
                        mpeDisplayJobDetails.Show();
                        return;
                    }
                    Reset();
                    //HideMainDvs();
                    BindSitemMapItemList();
                    //this.listDV.Visible = true;
                    ErrorDisplay1.ShowSuccess("Item Was Added Successfully");
                    mpeDisplayJobDetails.Hide();
                    break;

                case 2:     //Update
                    int id = (DataCheck.IsNumeric(ViewState["mRecordID"].ToString())) ? int.Parse(ViewState["mRecordID"].ToString()) : 0;
                    if (id < 1)
                    {
                        ErrorDisplay2.ShowError("Process Validation Failed!");
                        mpeDisplayJobDetails.Show();
                        return;
                    }
                    mInfo.ID = id;
                    int flag = 0;
                    if (!(new PortalServiceManager()).UpdateSiteMap(mInfo, ref flag))
                    {
                        if (flag == -1)
                        {
                            ErrorDisplay2.ShowError("Duplicate Tab Name! This Tab Name is already registered");
                            mpeDisplayJobDetails.Show();
                            return;
                        }
                        ErrorDisplay2.ShowError("Update failed!");
                        mpeDisplayJobDetails.Show();
                        return;
                    }
                    Reset();
                    BindSitemMapItemList();
                    btnSubmit.Text = "Add New Tab";
                    mpeDisplayJobDetails.Hide();
                    ErrorDisplay1.ShowSuccess("Item Was Updated Successfully");
                    break;
                }
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
            }
        }
        protected void DgPortalUsersDeleteCommand(Object source, DataGridCommandEventArgs e)
        {
            ErrorDisplay1.ClearError();
            //if (!Page.User.IsInRole("PortalAdmin"))
            //{
            //    ErrorDisplay1.ShowError("Sorry: You are not authorized to delete a user");
            //    return;
            //}
            try
            {
                dgPortalUsers.SelectedIndex = e.Item.ItemIndex;
                var portaluserId = (DataCheck.IsNumeric(dgPortalUsers.DataKeys[e.Item.ItemIndex].ToString())) ? long.Parse(dgPortalUsers.DataKeys[e.Item.ItemIndex].ToString()) : 0;
                if (portaluserId < 1)
                {
                    ErrorDisplay1.ShowError("Invalid Selection");
                    return;
                }

                int userId = int.Parse(((HiddenField)dgPortalUsers.SelectedItem.FindControl("hndUId")).Value.ToString(CultureInfo.InvariantCulture));
                if (userId < 1)
                {
                    ErrorDisplay1.ShowError("No User Item Selected");
                    return;
                }
                string userName = ((Label)dgPortalUsers.SelectedItem.FindControl("lblUserName")).Text;

                if (userName.Length < 2)
                {
                    ErrorDisplay1.ShowError("Invalid UserName!");
                    return;
                }

                var mUser = Membership.GetUser(userName, false);
                if (mUser == null)
                {
                    ErrorDisplay1.ShowError("Username not found!");
                    return;
                }
                //if (HttpContext.Current.User.Identity.Name.ToLower() == mName.ToLower())
                //{
                //    ErrorDisplay1.ShowError("You cannot delete the current user!");
                //    return;
                //}

                var ret = new PortalServiceManager().UpdateLockedUser(userId);

                if (!ret)
                {
                    ErrorDisplay1.ShowError("Unsuccessful Reset Operation!");
                    return;
                }


                string newPassword;
                try
                {
                    newPassword = mUser.ResetPassword();
                }
                catch (MembershipPasswordException ex)
                {
                    ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                    ErrorDisplay1.ShowError("Invalid password answer. Please re-enter and try again.");
                    return;
                }

                var body = string.Format("Password reset. Your new password is: {0}", Server.HtmlEncode(newPassword));

                if (Mailsender(mUser.Email, "ExpenseManager : User Credential Reset.", body))
                {
                    BindUsersList();
                    ErrorDisplay1.ShowSuccess("User Record has been Reset");
                }
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                ErrorDisplay1.ShowError(ex.Message);
            }
        }
        protected void BtnSubmitClick(object sender, EventArgs e)
        {
            ErrorDisplay1.ClearError();
            Page.Validate("regValidation");
            if (!Page.IsValid)
            {
                ErrorDisplay2.ShowError("Please enter all required fields");
                mpeDisplayJobDetails.Show();
                return;
            }



            try
            {
                if (ValidateRole() < 1)
                {
                    ErrorDisplay2.ShowError("You must select at least one role");
                    mpeDisplayJobDetails.Show();
                    return;
                }

                switch (int.Parse(btnSubmit.CommandArgument))
                {
                case 1:         //Add
                    if (!ValidateControls())
                    {
                        mpeDisplayJobDetails.Show();
                        return;
                    }
                    SaveData();
                    break;

                case 2:         //Update
                    if (!ValidateControlsForUpdate())
                    {
                        mpeDisplayJobDetails.Show();
                        return;
                    }

                    if (Session["_selectedUser"] == null)
                    {
                        ErrorDisplay2.ShowError("Session Has Expired!");
                        mpeDisplayJobDetails.Show();
                        return;
                    }
                    try
                    {
                        var user = (portaluser)Session["_selectedUser"];
                        if (user == null)
                        {
                            ErrorDisplay2.ShowError("Session Has Expired!");
                            mpeDisplayJobDetails.Show();
                            return;
                        }
                        if (user.UserId < 1)
                        {
                            ErrorDisplay2.ShowError("Session Has Expired!");
                            mpeDisplayJobDetails.Show();
                            return;
                        }
                        if (!(new PortalServiceManager()).CheckUniqueEmailNo(user.UserId, txtEmail.Text.Trim()))
                        {
                            ErrorDisplay2.ShowError("Supplied Email address has been used by another User");
                            mpeDisplayJobDetails.Show();
                            return;
                        }
                        if (!(new PortalServiceManager()).CheckUniqueMobileNo(user.PortalUserId, txtMobileNumber.Text.Trim()))
                        {
                            ErrorDisplay2.ShowError("Supplied Mobile Number already been used by another User");
                            mpeDisplayJobDetails.Show();
                            return;
                        }

                        if (!UpdateData(user))
                        {
                            mpeDisplayJobDetails.Show();
                            return;
                        }
                    }
                    catch (Exception)
                    {
                        ErrorDisplay2.ShowError("Session Has Expired!");
                        mpeDisplayJobDetails.Show();
                        return;
                    }

                    // mpeDisplayJobDetails.Show();
                    ErrorDisplay1.ShowSuccess("User Information Was Updated");
                    btnSubmit.Text            = "Add New User";
                    btnSubmit.CommandArgument = "1";
                    mpeDisplayJobDetails.Hide();
                    break;
                }
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
            }
        }
        protected void BtnSubmitClick(Object sender, EventArgs e)
        {
            ErrorDisplay1.ClearError();
            try
            {
                if (txtRoleName.Text == "")
                {
                    ErrorDisplay1.ShowError("Role name is required");
                    return;
                }

                switch (int.Parse(btnSubmit.CommandArgument))
                {
                case 1:     //Add
                    var roles = Roles.GetAllRoles();
                    if (roles == null || roles.Length < 1)
                    {
                        ErrorDisplay2.ShowError("The Portal Roles could not be retrieved. Please try again soon.");
                        mpeDisplayJobDetails.Show();
                        return;
                    }

                    if (roles.Any(role => role.ToLower().Replace(" ", string.Empty.Trim()) == txtRoleName.Text.Trim().ToLower().Replace(" ", string.Empty.Trim())))
                    {
                        ErrorDisplay2.ShowError("This Portal Role already exist");
                        mpeDisplayJobDetails.Show();
                        return;
                    }

                    Roles.CreateRole(txtRoleName.Text.Trim());
                    //HideTables();
                    BindRoleItems();

                    ErrorDisplay1.ShowSuccess("Portal Role Was Added Successfully");
                    //this.listDV.Visible = true;
                    mpeDisplayJobDetails.Hide();
                    break;

                case 2:     //Update
                    if (Roles.DeleteRole(ViewState["mRoleName"].ToString().Trim(), false))
                    {
                        Roles.CreateRole(txtRoleName.Text.Trim());
                        //HideTables();
                        BindRoleItems();

                        ErrorDisplay1.ShowSuccess("Portal Role Was Updated Successfully");
                        //this.listDV.Visible = true;
                        btnSubmit.Text = "Add New Role";
                        mpeDisplayJobDetails.Hide();
                    }
                    else
                    {
                        ErrorDisplay2.ShowError("Error Occurred! Please try again later");
                        mpeDisplayJobDetails.Show();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                ErrorDisplay1.ShowError(ex.Message);
            }
        }
        private void SaveData()
        {
            try
            {
                var memUser = Membership.GetUser(txtUserName.Text.Trim());

                if (memUser != null)
                {
                    if (memUser.UserName.Length > 1)
                    {
                        ErrorDisplay2.ShowError("User Already Exist!");
                        mpeDisplayJobDetails.Show();
                        return;
                    }
                }

                var memUser2 = Membership.CreateUser(txtUserName.Text.Trim(), txtPassword.Text.Trim(), txtEmail.Text.Trim());

                if (memUser2.UserName == "")
                {
                    ErrorDisplay2.ShowError("Process Failed! User Information was not registered");
                    mpeDisplayJobDetails.Show();
                    return;
                }

                memUser2.IsApproved = chkActive.Checked;
                Membership.UpdateUser(memUser2);
                var userId = new PortalServiceManager().GetUserIdByUsername(txtUserName.Text.Trim());
                if (userId < 1)
                {
                    Membership.DeleteUser(txtUserName.Text.Trim());
                    ErrorDisplay2.ShowError("Process Failed! Please try again soon");
                    mpeDisplayJobDetails.Show();
                    return;
                }

                var mUser = new portaluser
                {
                    DateRegistered = DateMap.GetLocalDate(),
                    Designation    = txtDesignation.Text.Trim(),
                    FirstName      = txtFirstName.Text.Trim(),
                    LastName       = txtLastName.Text.Trim(),
                    MobileNumber   = txtMobileNumber.Text.Trim(),
                    SexId          = int.Parse(ddlSex.SelectedValue),
                    TimeRegistered = DateTime.Now.ToString("hh:mm:ss"),
                    UserName       = txtUserName.Text.Trim(),
                    UserId         = userId,
                    Status         = chkActive.Checked
                };

                var k = (new PortalServiceManager()).AddPortalUser(mUser);

                if (k < 1)
                {
                    Membership.DeleteUser(txtUserName.Text.Trim());
                    ErrorDisplay2.ShowError("User Information Was Not Saved!");
                    mpeDisplayJobDetails.Show();
                    return;
                }

                //Add Roles
                string[] mRoles = Roles.GetRolesForUser(txtUserName.Text.Trim());

                if (mRoles != null)
                {
                    if (mRoles.Length > 0)
                    {
                        Roles.RemoveUserFromRoles(txtUserName.Text.Trim(), mRoles);
                    }
                }

                try
                {
                    foreach (ListItem item in chkRoles.Items)
                    {
                        if (item.Selected)
                        {
                            Roles.AddUserToRole(txtUserName.Text.Trim(), item.Value.Trim());
                        }
                    }
                }
                catch (Exception)
                {
                    Membership.DeleteUser(txtUserName.Text.Trim());
                    (new PortalServiceManager()).DeletePortalUser(k);
                    ErrorDisplay2.ShowError("Process Failed! Please try again soon");
                    return;
                }

                BindUsersList();

                ErrorDisplay2.ClearControls(tbUserInfo);
                ErrorDisplay1.ClearError();
                ErrorDisplay1.ShowSuccess("User Information Was Saved");
                mpeDisplayJobDetails.Hide();
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                ErrorDisplay2.ShowError(ex.Message);
                mpeDisplayJobDetails.Show();
            }
        }
示例#16
0
        protected async void btnForgotPassword_Click(object sender, EventArgs e)
        {
            string msg = "";

            try
            {
                var userList = _db.AspNetUsers.Where(m => m.Email == txtEmail.Text);
                if (!userList.Any())
                {
                    ErrorDisplay1.ShowError("Email does not exist!");

                    return;
                }

                if (String.IsNullOrEmpty(txtEmail.Text))
                {
                    ErrorDisplay1.ShowError("Please enter your email !");


                    return;
                }

                var newPass = GeneratePassword();
                await ResetPassword(txtEmail.Text, newPass);

                using (MailMessage mm = new MailMessage(ConfigurationManager.AppSettings["SMTPuser"], txtEmail.Text))
                {
                    mm.Subject    = "MyClassPapers Password Reset";
                    mm.Body       = CreateBody();
                    mm.IsBodyHtml = true;
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host      = ConfigurationManager.AppSettings["Host"];
                    smtp.EnableSsl = true;

                    NetworkCredential NetworkCred = new NetworkCredential(ConfigurationManager.AppSettings["SMTPuser"], ConfigurationManager.AppSettings["SMTPpassword"]);
                    smtp.UseDefaultCredentials = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSSL"]);
                    smtp.Credentials           = NetworkCred;
                    smtp.Port = int.Parse(ConfigurationManager.AppSettings["EmailPort"]);
                    smtp.Send(mm);
                    ErrorDisplay1.ShowSuccess("Your new Password has been sent to your Email");
                    txtEmail.Text = "";
                }



                //await ResetPassword(txtEmail.Text, newPass);

                ////await ApplicationUtil.Execute();
                //await ApplicationUtil.SendPassword(newPass, txtEmail.Text);



                //ErrorDisplay1.ShowSuccess(msg);

                ////////

                //MailMessage message = new MailMessage();
                //MailAddress to = new MailAddress(txtEmail.Text.ToString());
                //MailAddress from = new MailAddress("*****@*****.**");
                //message.To.Add(to);
                //message.From = from;
                //message.Subject = "Password Reset";
                //message.Body = "Your new password is"+ newPass;
                //message.IsBodyHtml = false;
                //message.SubjectEncoding = System.Text.Encoding.UTF8;

                //SmtpClient Client = new SmtpClient();
                //Client.Host = "smtp.gmail.com";
                //Client.Port = 587;


                //System.Net.NetworkCredential myAccount = new System.Net.NetworkCredential("*****@*****.**", "Emmy1997");
                //Client.Credentials = myAccount;
                //Client.EnableSsl = true;
                //Client.UseDefaultCredentials = false;
                //Client.Send(message);
                //ErrorDisplay1.ShowSuccess("Your new Password has been sent to your Email");
            }
            catch (Exception ex)
            {
                ErrorDisplay1.ShowError("An error occurred, please contact administrator !: " + msg);
            }
        }
        private bool UpdateData(portaluser user)
        {
            try
            {
                var memUser = Membership.GetUser(user.UserName);
                if (memUser == null)
                {
                    ErrorDisplay2.ShowError("Session Has Expired!");
                    return(false);
                }
                if (memUser.Email.Length < 5)
                {
                    ErrorDisplay2.ShowError("Session Has Expired!");
                    return(false);
                }

                memUser.Email      = txtEmail.Text.Trim();
                memUser.IsApproved = chkActive.Checked;
                Membership.UpdateUser(memUser);

                user.Designation  = txtDesignation.Text.Trim();
                user.FirstName    = txtFirstName.Text.Trim();
                user.LastName     = txtLastName.Text.Trim();
                user.MobileNumber = txtMobileNumber.Text.Trim();
                user.SexId        = int.Parse(ddlSex.SelectedValue);
                user.Status       = chkActive.Checked;

                var k = (new PortalServiceManager()).UpdatePortalUser(user);

                if (k < 1)
                {
                    Membership.DeleteUser(txtUserName.Text.Trim());
                    ErrorDisplay2.ShowError("User Information Was Not Updated!");
                    return(false);
                }

                string[] mRoles = Roles.GetRolesForUser(txtUserName.Text.Trim());

                if (mRoles != null)
                {
                    if (mRoles.Length > 0)
                    {
                        Roles.RemoveUserFromRoles(txtUserName.Text.Trim(), mRoles);
                    }
                }

                try
                {
                    foreach (ListItem item in chkRoles.Items)
                    {
                        if (item.Selected)
                        {
                            Roles.AddUserToRole(txtUserName.Text.Trim(), item.Value.Trim());
                        }
                    }
                }
                catch (Exception)
                {
                    Membership.DeleteUser(txtUserName.Text.Trim());
                    (new PortalServiceManager()).DeletePortalUser(user.UserId);
                    ErrorDisplay2.ShowError("Process Failed! Please try again soon");
                    return(false);
                }
                BindUsersList();

                ErrorDisplay2.ClearControls(tbUserInfo);
                ErrorDisplay1.ClearError();
                ErrorDisplay1.ShowSuccess("User record was updated successfully.");
                return(true);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                ErrorDisplay2.ShowError(ex.Message);
                mpeDisplayJobDetails.Show();
                return(false);
            }
        }