Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private bool IsValidSession()
        {
            if (Session["user"] == null)
            {
                return false;
            }

            _user = (Users)Session["user"];

            return _user.Id != 0;
        }
Ejemplo n.º 2
0
        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {

                Users user = new Users();
                user = user.GetUserByUserName(txtUserName.Text);
                if (user.Id != 0)
                {
                    if(user.UserPass != txtPassword.Text)
                    {
                        Alert.Show("User and password didn't match. Please re-enter the correct password.");
                        txtPassword.Focus();
                        return;
                    }

                    Session["user"] = user;
                    UserRoleMapping userRoles = new UserRoleMapping().GetUserRoleMappingByUserId(user.Id, user.CompanyId);
                    if (userRoles.Id != 0 && user.Id == 1)
                        user.IsSuperUser = true;
                    else
                        user.IsSuperUser = false;

                    if (user.CompanyId == 0 && !user.IsSuperUser)
                    {
                        Alert.Show("Sorry this user is not associated with any company. Contact your system administrator to fix this issue.");
                        return;
                    }

                    Response.Redirect(((_refPage == string.Empty || _refPage.ToLower() == "logout") ? "Default.aspx" : _refPage), false);
                }
                else
                {
                    Alert.Show("The user is not exist in the database. Please check the username.");
                    txtUserName.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                Alert.Show("Error during process user authentication. Error: "+ex.Message);
            }
        }
        private void LoadUserListCombo()
        {
            List<Users> lstUser = new Users().GetAllUsers(1);

            lstUser.Insert(0, new Users());
            rdropList.DataTextField = "UserName";
            rdropList.DataValueField = "Id";
            rdropList.DataSource = lstUser;
            rdropList.DataBind();

            rdropList.SelectedIndex = 0;
        }
Ejemplo n.º 4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (Regex.IsMatch(txtUserName.Text, @"^[a-zA-Z0-9_]{5,20}$") != true)
                {
                    Alert.Show("User name must be between 5 to 20 Characters Or Lowercase and Uppercase characters Or Alpha-Numeric And No Space And special character allowed");
                    txtUserName.Focus();
                    return;
                }
                int count = _user.CheckUserNameExistance((lblId.Text == string.Empty) ? 0 : int.Parse(lblId.Text), txtUserName.Text, isNewEntry);

                if (count > 0)
                {
                    Alert.Show("User name already exists. ");
                    return;
                }

                _user = new Users();
                _user.Id = (lblId.Text == string.Empty) ? 0 : int.Parse(lblId.Text);
                _user.UserName = txtUserName.Text;
                _user.UserPass = txtPassword.Text;
                _user.IsActive = (bool)chkIsActive.Checked;

                int success = 0;
                if (isNewEntry)
                {
                    success = _user.InsertUsers();
                    _user.Id = new Users().GetLastId(_user.CompanyId);
                }
                else
                    success = _user.UpdateUsers();

                if (success == 0)
                {

                    Alert.Show("Create user information was not successfull.");
                    return;
                }
                else
                {
                    //delete all roles from userrole mapping table
                    success = new UserRoleMapping().DeleteUserRoleMappingByUserId(_user.Id);
                    //get roles and update db
                    foreach (RadListBoxItem item in lbRole.CheckedItems)
                    {
                        if (item.Checked)
                        {
                            int roleId = int.Parse(item.Value);
                            UserRoleMapping role = new UserRoleMapping();

                            role.UserId = _user.Id;
                            role.RoleId = roleId;
                            role.CompanyId = _user.CompanyId;

                            role.InsertUserRoleMapping();
                        }
                    }

                    Alert.Show("User information created succssfully.");
                    this.ClearControls();
                    this.LoadUserGrid();
                }
            }
            catch (Exception ex)
            {
                Alert.Show("Error during user information save. Error: " + ex.Message);
            }
        }
Ejemplo n.º 5
0
        private void LoadUserGrid()
        {
            try
            {

                List<Users> userList = new Users().GetAllUsersList();
                if (userList.Count == 0)
                    userList.Add(new Users());

                dgvUser.DataSource = userList;
                dgvUser.DataBind();

            }
            catch (Exception ex)
            {
                Alert.Show("Error in method 'LoadLeaveDetailsGrid'. Error: " + ex.Message);
            }
        }
Ejemplo n.º 6
0
        private bool IsValidSession()
        {
            if (Session["user"] == null)
            {
                return false;
            }

            _user = (Users)Session["user"];

            if (Session["SuperUser"] != null)
                _IsSuperUser = (bool)Session["SuperUser"];
            else
                _IsSuperUser = false;

            return _user.Id != 0;
        }
Ejemplo n.º 7
0
        protected void dgvUser_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "btnSelect")
            {
                GridDataItem item = (GridDataItem)e.Item;

                lblId.Text = item["colId"].Text;
                txtUserName.Text = item["colName"].Text.Trim();
                txtPassword.Text = (item["colPass"].Text == "&nbsp;") ? "" : item["colPass"].Text.Trim();

                isNewEntry = false;
            }
            else if (e.CommandName == "btnDelete")
            {
                try
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    lblId.Text = item["colId"].Text;
                    int id = int.Parse(lblId.Text);
                    Users userDelete = new Users();
                    int success = userDelete.DeleteUsersById(id);
                    if (success == 0)
                    {
                        Alert.Show("Something is going Wrong!!!!");
                    }
                    else
                    {
                        Alert.Show("Successfully Deleted!!");
                        this.LoadUserGrid();
                    }
                }
                catch (Exception ex)
                {
                    Alert.Show("Error happen during delete attendance data. Error: " + ex.Message);
                }
            }
        }