예제 #1
0
        public void SaveTest()
        {
            var obj = new Pengguna
            {
                role_id       = "c58ee40a-5ae2-4067-b6ad-8cae9c65913c",
                nama_pengguna = "Joko",
                pass_pengguna = "20b1ce8e61ee5b49320ef0a78c75521b",
                is_active     = true
            };

            var validationError = new ValidationError();

            var result = _bll.Save(obj, ref validationError);

            Console.WriteLine("Error : " + validationError.Message);

            Assert.IsTrue(result != 0);

            var newObj = _bll.GetByID(obj.nama_pengguna);

            Assert.IsNotNull(newObj);
            Assert.AreEqual(obj.pengguna_id, newObj.pengguna_id);
            Assert.AreEqual(obj.role_id, newObj.role_id);
            Assert.AreEqual(obj.nama_pengguna, newObj.nama_pengguna);
            Assert.AreEqual(obj.pass_pengguna, newObj.pass_pengguna);
            Assert.AreEqual(obj.is_active, newObj.is_active);
        }
예제 #2
0
        protected override void Simpan()
        {
            if (txtPassword.Text.Length > 0 && txtKonfirmasiPassword.Text.Length > 0)
            {
                if (txtPassword.Text != txtKonfirmasiPassword.Text)
                {
                    MsgHelper.MsgWarning("Password dan konfirmasi password harus sama");
                    txtPassword.Focus();
                    txtPassword.SelectAll();
                    return;
                }
            }

            if (_isNewData)
            {
                _operator = new Pengguna();
            }

            _operator.nama_pengguna = txtNama.Text;
            _operator.pass_pengguna = txtPassword.Text;

            if (txtKonfirmasiPassword.Text.Length > 0)
            {
                _operator.konf_pass_pengguna = CryptoHelper.GetMD5Hash(txtKonfirmasiPassword.Text, MainProgram.securityCode);
            }

            var role = listOfRole[cmbRole.SelectedIndex];

            _operator.role_id   = role.role_id;
            _operator.Role      = role;
            _operator.is_active = rdoAktif.Checked;

            var result          = 0;
            var validationError = new ValidationError();

            if (_isNewData)
            {
                result = _bll.Save(_operator, ref validationError);
            }
            else
            {
                result = _bll.Update(_operator);
            }

            if (result > 0)
            {
                Listener.Ok(this, _isNewData, _operator);

                if (_isNewData)
                {
                    base.ResetForm(this);
                    txtNama.Focus();
                }
                else
                {
                    this.Close();
                }
            }
            else
            {
                if (validationError.Message.Length > 0)
                {
                    MsgHelper.MsgWarning(validationError.Message);
                    base.SetFocusObject(validationError.PropertyName, this);
                }
                else
                {
                    MsgHelper.MsgUpdateError();
                }
            }
        }