Example #1
0
        private void EditUser()
        {
            DataGridViewRow selectedRow = new DataGridViewRow();

            foreach (DataGridViewRow row in ctlUsersGrid.Rows)
            {
                if (row.Selected)
                {
                    selectedRow = row;
                    break;
                }
            }
            var users        = logic.GetAllUsers();
            int userId       = (int)selectedRow.Cells[0].Value;
            var selectedUser = users.FirstOrDefault(u => u.Id == userId);

            if (selectedUser != null)
            {
                var addEditUserForm      = new AddEditUserForm(selectedUser, logic);
                var listOfUsersViewModel = (List <UserViewModel>)ctlUsersGrid.DataSource;

                if (addEditUserForm.ShowDialog() == DialogResult.OK)
                {
                    var indexOfSelectedUser = users.IndexOf(selectedUser);
                    logic.EditUser(addEditUserForm.NewUser, indexOfSelectedUser);
                }

                ctlUsersGrid.DataSource         = null;
                listOfUsersViewModel            = logic.GetUsersForUI();
                ctlUsersGrid.DataSource         = GetListWithLastSort(listOfUsersViewModel);
                ctlUsersGrid.Columns[0].Visible = false;
            }
        }
Example #2
0
        private void AddUser()
        {
            var addEditUserForm = new AddEditUserForm(logic);

            var listOfUsersViewModel = (List <UserViewModel>)ctlUsersGrid.DataSource;

            if (addEditUserForm.ShowDialog() == DialogResult.OK)
            {
                logic.AddUser(addEditUserForm.NewUser);
            }
            ctlUsersGrid.DataSource         = null;
            listOfUsersViewModel            = logic.GetUsersForUI();
            ctlUsersGrid.DataSource         = GetListWithLastSort(listOfUsersViewModel);
            ctlUsersGrid.Columns[0].Visible = false;
        }