コード例 #1
0
ファイル: PowerPopup.cs プロジェクト: Oskar619/superheroapp
        private void button1_Click(object sender, EventArgs e)
        {
            if (selectedHero == null)
            {
                return;
            }
            SuperHeroPower pw;

            using (var repo = new SuperHeroPowerRepository())
            {
                if (selectedPowerId == 0)
                {
                    pw             = new SuperHeroPower();
                    pw.PowerName   = textBox1.Text;
                    pw.SuperHeroId = selectedHero.Id;
                    repo.Insert(pw);
                }
                else
                {
                    pw = selectedHero.Powers.FirstOrDefault(x => x.Id == selectedPowerId);
                    if (pw != null)
                    {
                        pw.PowerName = textBox1.Text;
                    }
                    repo.Update(pw);
                }
                repo.Save();
            }
            UpdateRequired = true;
            Close();
        }
コード例 #2
0
        private void btnDeletePower_Click(object sender, EventArgs e)
        {
            DialogResult rs = MessageBox.Show("Are you sure you want to delete this power?", "Power Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (rs == DialogResult.No)
            {
                return;
            }
            using (var repo = new SuperHeroPowerRepository())
            {
                repo.Delete(_selectedPower);
                repo.Save();
            }
            ReloadSelectedHero();
        }