private void Edit() { string url = this.main_form.config.ApiUrl + "users/Edit"; var api_acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, internalUsers = new InternalUsers { Id = this.user.Id, UserName = this.user.UserName, Email = "", PasswordHash = "", FullName = this.user.FullName, Department = this.user.Department, Status = this.user.Status, } }; APIResult result = APIClient.PUT(url, api_acc); InternalUsers user; if (result.Success) { user = JsonConvert.DeserializeObject <InternalUsers>(result.ReturnValue); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show(result.ErrorMessage.RemoveBeginAndEndQuote()); this.txtUserName.Focus(); } }
public InternalUsers LoadSingleUserFromServer(int?id) { if (!id.HasValue) { return(null); } try { APIResult get = APIClient.GET(this.main_form.config.ApiUrl + "Users/GetUserById", this.main_form.config.ApiKey, "&id=" + id.ToString()); if (get.Success) { InternalUsers user = JsonConvert.DeserializeObject <InternalUsers>(get.ReturnValue); return(user); } } catch (Exception ex) { if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { return(this.LoadSingleUserFromServer(id)); } } return(null); }
/** Convert Model to View-Model **/ public static InternalUsersVM ToViewModel(this InternalUsers user) { InternalUsersVM user_vm = new InternalUsersVM { Id = user.Id, UserName = user.UserName, Email = user.Email, PasswordHash = user.PasswordHash, FullName = user.FullName, Department = user.Department, Status = user.Status, CreDate = user.CreDate, NewPassword = string.Empty }; return(user_vm); }
private void btnChangePwd_Click(object sender, EventArgs e) { int user_id = (int)this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, colId); InternalUsers user = this.users.Where(u => u.Id == user_id).FirstOrDefault(); if (user == null) { return; } ChangePasswordDialog chg = new ChangePasswordDialog(this.main_form, user); if (chg.ShowDialog() == DialogResult.OK) { MessageBox.Show("เปลี่ยนรหัสผ่านของผู้ใช้รหัส \"" + user.UserName + "\" เรียบร้อย, กรุณาล็อกอินด้วยรหัสผ่านใหม่อีกคร้ง"); } }
private void AddUserDialog_Load(object sender, EventArgs e) { switch (this.form_mode) { case FORM_MODE.ADD: this.Text = "Add User"; break; case FORM_MODE.EDIT: this.Text = "Edit User"; break; default: this.Text = "Add User"; break; } foreach (var item in Enum.GetValues(typeof(InternalUsers.DEPARTMENT))) { this.cbDepartment.Properties.Items.Add(item); } foreach (var item in Enum.GetValues(typeof(InternalUsers.STATUS))) { this.cbStatus.Properties.Items.Add(item); } if (this.user != null) { this.txtUserName.Enabled = false; this.txtUserName.Text = this.user.UserName; this.txtFullName.Text = this.user.FullName; this.cbDepartment.Text = this.user.Department; this.cbStatus.Text = this.user.Status; } else { this.user = new InternalUsers(); this.cbDepartment.SelectedIndex = 0; this.cbStatus.SelectedIndex = 0; } }
private void btnDelete_Click(object sender, EventArgs e) { int user_id = (int)this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, colId); string user_name = (string)this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, colUserName); InternalUsers user = this.users.Where(u => u.Id == user_id).FirstOrDefault(); if (user == null) { return; } if (MessageBox.Show("ลบรหัสผู้ใช้ \"" + user_name + "\"", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.OK) { try { ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, internalUsers = user }; APIResult result = APIClient.DELETE(this.main_form.config.ApiUrl + "users/delete", acc); if (result.Success) { this.RefreshGridUsers(); } else { MessageBox.Show(result.ErrorMessage.RemoveBeginAndEndQuote()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnEdit_Click(object sender, EventArgs e) { int user_id = (int)this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, colId); try { APIResult result = APIClient.GET(this.main_form.config.ApiUrl + "users/", this.main_form.config.ApiKey, "&id=" + user_id); if (result.Success && result.ReturnValue != null) { InternalUsers user = JsonConvert.DeserializeObject <InternalUsers>(result.ReturnValue); UserAddEditDialog edit = new UserAddEditDialog(this.main_form, user); if (edit.ShowDialog() == DialogResult.OK) { this.RefreshGridUsers(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnOK_Click(object sender, EventArgs e) { this.splashScreenManager1.ShowWaitForm(); APIResult result = APIClient.POST(this.main_form.config.ApiUrl + "users/signin", new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, internalUsers = new InternalUsers { UserName = (string)this.txtUserName.EditValue, PasswordHash = (string)this.txtPassword.EditValue } }); if (result.Success && result.ReturnValue != null) { this.splashScreenManager1.CloseWaitForm(); InternalUsers user = JsonConvert.DeserializeObject <InternalUsers>(result.ReturnValue); if (user != null) { if (user.Status == "X") { MessageBox.Show("ผู้ใช้รายนี้ถูกห้ามใช้"); } else { this.user = user; this.DialogResult = DialogResult.OK; this.Close(); } } else { MessageBox.Show("รหัสผู้ใช้/รหัสผ่าน ไม่ถูกต้อง"); } } else { this.splashScreenManager1.CloseWaitForm(); MessageBox.Show(result.ErrorMessage.RemoveBeginAndEndQuote()); } }
private void btnResetPwd_Click(object sender, EventArgs e) { int user_id = (int)this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, colId); InternalUsers user = this.users.Where(u => u.Id == user_id).FirstOrDefault(); if (MessageBox.Show("รีเซ็ตรหัสผ่านของรหัสผู้ใช้ \"" + user.UserName + "\", ดำเนินการต่อ?", "Reset Password", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.OK) { if (user == null) { return; } try { APIResult result = APIClient.POST(this.main_form.config.ApiUrl + "users/resetpassword", new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, internalUsers = new InternalUsers { Id = user_id, } }); if (result.Success) { MessageBox.Show("รีเซ็ตรหัสผ่านของรหัสผู้ใช้ \"" + user.UserName + "\" เป็น \"" + user.UserName + "\" เรียบร้อย"); } else { MessageBox.Show(result.ErrorMessage.RemoveBeginAndEndQuote()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public async Task <bool> IsInternal() { return(await InternalUsers.AnyAsync(u => u.UserId == UserContext.UserId.ToString())); }
public ChangePasswordDialog(MainForm main_form, InternalUsers user) { InitializeComponent(); this.main_form = main_form; this.user = user; }
public UserAddEditDialog(MainForm main_form, InternalUsers user = null) : this() { this.main_form = main_form; this.form_mode = FORM_MODE.EDIT; this.user = user; }