Ejemplo n.º 1
0
        private async Task <bool> SaveUser(bool isEdit)
        {
            CommonEngine.ShowWaitForm(this);
            SYS_tblUserDRO result = new SYS_tblUserDRO();

            try
            {
                result = await SYS_tblUserBUS.InsertUpdateUser(new SYS_tblUserDTO
                {
                    Username             = txtUsername.Text,
                    Password             = EncryptEngine.Encrypt(txtPassword.Text.Trim()),
                    GroupID              = gluGroupUser.EditValue + "",
                    EmpID                = chkIsEmployee.Checked ? gluEmployee.EditValue + "" : "",
                    FullName             = txtFullName.Text,
                    EffectiveDate        = dteEffectiveDate.DateTime,
                    ToDate               = dteToDate.EditValue == null ? (DateTime?)null : dteToDate.DateTime,
                    Locked               = chkLocked.Checked,
                    LockDate             = (chkLocked.Checked && dteLockDate.EditValue != null) ? dteLockDate.DateTime : (DateTime?)null,
                    UnlockDate           = (chkLocked.Checked && dteUnlockDate.EditValue != null) ? dteUnlockDate.DateTime : (DateTime?)null,
                    CanNotChangePassword = chkCanNotChangePassword.Checked,
                    ChangePassNextTime   = chkChangePassNextTime.Checked,
                    PassNeverExpired     = chkPasswordNeverExpired.Checked,
                    Email                = txtEmail.Text,
                    Note       = mmoNote.Text,
                    Activity   = (isEdit) ? BaseConstant.UPDATE_COMMAND : BaseConstant.INSERT_COMMAND,
                    UserID     = CommonEngine.userInfo.UserID,
                    LanguageID = ConfigEngine.Language
                }, new SYS_tblActionLogDTO
                {
                    Activity      = BaseConstant.COMMAND_INSERT_EN,
                    UserID        = txtUsername.Text,
                    LanguageID    = ConfigEngine.Language,
                    ActionEN      = BaseConstant.COMMAND_UPDATE_EN,
                    ActionVN      = BaseConstant.COMMAND_UPDATE_VI,
                    FunctionID    = "10",
                    DescriptionVN = string.Format("Tài khoản '{0}' vừa cập nhật thành công người dùng có tên tài khoản '{1}'.", CommonEngine.userInfo.UserID, txtUsername.Text.Trim()),
                    DescriptionEN = string.Format("Account '{0}' has updated user successfully with username is '{1}'.", CommonEngine.userInfo.UserID, txtUsername.Text.Trim())
                });

                if (CommonEngine.CheckValidResponseItem(result.ResponseItem))
                {
                    if (!string.IsNullOrEmpty(result.ResponseItem.Message))
                    {
                        CommonEngine.CloseWaitForm();
                        CommonEngine.ShowMessage(result.ResponseItem.Message, 0);
                        txtUsername.Focus();
                        return(false);
                    }
                    else
                    {
                        parent_form.GetAllUsers();
                    }
                }
                else
                {
                    CommonEngine.CloseWaitForm();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                CommonEngine.ShowExceptionMessage(ex);
                return(false);
            }
            finally
            {
                CommonEngine.CloseWaitForm();
            }

            return(true);
        }