예제 #1
0
        private void AddAward()
        {
            var addEditAwardForm = new AddEditAwardForm();
            var listOfAwards     = (List <Award>)ctlAwardsGrid.DataSource;

            if (addEditAwardForm.ShowDialog() == DialogResult.OK)
            {
                logic.AddAward(new Award(addEditAwardForm.Title, addEditAwardForm.Description));
            }

            ctlAwardsGrid.DataSource         = null;
            listOfAwards                     = logic.GetAllAwards();
            ctlAwardsGrid.DataSource         = GetListWithLastSort(listOfAwards);
            ctlAwardsGrid.Columns[0].Visible = false;
        }
예제 #2
0
        private void EditAward()
        {
            DataGridViewRow selectedRow = new DataGridViewRow();

            foreach (DataGridViewRow row in ctlAwardsGrid.Rows)
            {
                if (row.Selected)
                {
                    selectedRow = row;
                    break;
                }
            }

            var listOfAwards  = logic.GetAllAwards();
            int awardId       = (int)selectedRow.Cells[0].Value;
            var selectedAward = listOfAwards.FirstOrDefault(a => a.AwardId == awardId);

            if (selectedAward != null)
            {
                var addEditAwardForm     = new AddEditAwardForm(selectedAward);
                var listOfUsersViewModel = (List <UserViewModel>)ctlUsersGrid.DataSource;

                if (addEditAwardForm.ShowDialog() == DialogResult.OK)
                {
                    var indexOfSelectedAward = listOfAwards.IndexOf(selectedAward);
                    logic.EditAward(addEditAwardForm.Award, indexOfSelectedAward);
                }
                ctlUsersGrid.DataSource          = null;
                ctlAwardsGrid.DataSource         = null;
                listOfUsersViewModel             = logic.GetUsersForUI();
                listOfAwards                     = logic.GetAllAwards();
                ctlAwardsGrid.DataSource         = GetListWithLastSort(listOfAwards);
                ctlUsersGrid.DataSource          = GetListWithLastSort(listOfUsersViewModel);
                ctlUsersGrid.Columns[0].Visible  = false;
                ctlAwardsGrid.Columns[0].Visible = false;
            }
        }