Ejemplo n.º 1
0
        private void SaveUser()
        {
            ReturnInfo checkUser = _userInfo.GetUserByUsername(new SmartDB(), TextBoxUsername.Text);

            if (checkUser.Code == ErrorEnum.NoRecord ||
                checkUser.Code == ErrorEnum.NoError)
            {
                if (!string.IsNullOrWhiteSpace(TextBoxName.Text) &&
                    _currentUser.Role == "Administrator")
                {
                    TMF.Core.Model.UserInfo user = new TMF.Core.Model.UserInfo()
                    {
                        Id       = Guid.NewGuid().ToString("N"),
                        Username = TextBoxUsername.Text,
                        Password = TextBoxPassword.Text,
                        Name     = TextBoxName.Text,
                        Role     = ComboBoxRole.Text,
                        IsActive = false
                    };

                    var  createUser = _userInfo.Create(new SmartDB(), ref user);
                    bool flag       = createUser.Code == ErrorEnum.NoError;

                    if (createUser.Code == ErrorEnum.UniqueConstraint)
                    {
                        MessageBox.Show("Username Duplicate");
                        return;
                    }
                    if (flag)
                    {
                        MessageBox.Show("User Created");
                        ResetControls();
                        BindUserWithDataGrid();
                    }
                    else
                    {
                        MessageBox.Show("User not created");
                    }
                }
                else
                {
                    MessageBox.Show("No User to save or Contact Admin.");
                }
            }
        }