Example #1
0
        private async void dgvAdmins_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                var      adminId  = dgvAdmins.Rows[e.RowIndex].Cells["AdminId"].Value;
                var      action   = dgvAdmins.Columns[e.ColumnIndex].Name;
                MenuForm menuForm = (MenuForm)this.MdiParent;

                if (action == "Edit")
                {
                    AddEditAdminForm form = new AddEditAdminForm(menuForm, _currentUsername, int.Parse(adminId.ToString()))
                    {
                    };
                    _helper.ShowForm(form, 15);
                }
                else if (action == "Delete")
                {
                    var confirm = MessageBox.Show("Are you sure to delete this admin? You will be logged out if you delete yourself.", "Confirm Delete", MessageBoxButtons.YesNo);
                    if (confirm == DialogResult.Yes)
                    {
                        var mbox  = new CustomMessageBox();
                        var admin = await _apiService.GetById <Model.Admin>(adminId);

                        var message = await _apiService.Delete <string>(adminId);

                        if (admin.Account.Username == _currentUsername)
                        {
                            LoginForm form = new LoginForm();
                            form.Show();
                            var menu = (MenuForm)this.MdiParent;
                            menu.Close();
                        }
                        else
                        {
                            AdminsForm form = new AdminsForm(_currentUsername)
                            {
                                MdiParent = (MenuForm)this.MdiParent,
                                Dock      = DockStyle.Fill
                            };
                            form.Show();
                            this.Close();
                        }
                        mbox.Show(message, "success");
                    }
                }
            }
        }
Example #2
0
        private void AddAdminBtn_Click(object sender, EventArgs e)
        {
            AddEditAdminForm form = new AddEditAdminForm((MenuForm)this.MdiParent, _currentUsername);

            _helper.ShowForm(form, 15);
        }