private void btn_RewardUser_Click(object sender, EventArgs e)
        {
            var user = dgv_Users.CurrentRow?.DataBoundItem as User;

            if (user != null)
            {
                var form = new UserRewardForm(awardBL.GetList(), user.GetAwards().Select(a => a.Title));

                if (form.ShowDialog() == DialogResult.OK)
                {
                    var awardsNow      = awardBL.GetList().Where(a => user.GetAwards().Any(ua => ua.Title == a.Title));
                    var selectedAwards = awardBL.GetList().Where(a => form.SelectedAwards.Contains(a.Title));

                    var awardToAdd    = selectedAwards.Where(sa => !awardsNow.Any(a => a.Id == sa.Id));
                    var awardToDelete = awardsNow.Where(a => !selectedAwards.Any(sa => sa.Id == a.Id));

                    foreach (var toAdd in awardToAdd)
                    {
                        userBL.AddAward(user.Id, toAdd.Id);
                    }

                    foreach (var toDelete in awardToDelete)
                    {
                        userBL.RemoveAward(user.Id, toDelete.Id);
                    }

                    DisplayUsers();
                }
            }
        }
Esempio n. 2
0
        private void btn_RewardUser_Click(object sender, EventArgs e)
        {
            var user = dataGridView1.CurrentRow?.DataBoundItem as User;

            if (user != null)
            {
                var form = new UserRewardForm(awardBL.GetList(), user.GetAwards());

                if (form.ShowDialog() == DialogResult.OK)
                {
                    user.UpdateAwards(form.SelectedAwards);

                    DisplayUsers();
                }
            }
        }
Esempio n. 3
0
        private void btn_RewardUser_Click(object sender, EventArgs e)
        {
            var user = dataGridView1.CurrentRow?.DataBoundItem as User;

            if (user != null)
            {
                var form = new UserRewardForm(awardList, user.GetAwards());

                if (form.ShowDialog() == DialogResult.OK)
                {
                    user.ClearAwards();

                    user.AddAwards(form.SelectedAwards);

                    dataGridView1.Refresh();
                }
            }
        }