private void btnDone_Click(object sender, EventArgs e)
        {
            SuperHero currentHero;

            using (var repo = new SuperHeroRepository())
            {
                currentHero = repo.GetByAssemblyName(_assemblyName);
                bool alreadyExists = currentHero != null;
                if (alreadyExists)
                {
                    DialogResult rs = MessageBox.Show("The selected assembly already exists on the record. Do you want to overwrite it?", "Superhero already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (rs == DialogResult.No)
                    {
                        return;
                    }
                }
                else
                {
                    currentHero = new SuperHero();
                }
                if (alreadyExists)
                {
                    repo.ResetPowers(currentHero);
                }
                var selectedType = _compatibleClasses.FirstOrDefault(x => x.FullName == comboBox1.SelectedValue.ToString());
                var hero         = (ISuperHero)Activator.CreateInstance(selectedType);
                currentHero.AssemblyName  = _assemblyName;
                currentHero.DateOfBirth   = hero.DateOfBirth;
                currentHero.Name          = hero.Name;
                currentHero.StringPowers  = hero.Powers;
                currentHero.SuperHeroName = this.textBox1.Text;
                currentHero.Base64Img     = GetSelectedImageBase64();
                currentHero.Powers        = new List <SuperHeroPower>();
                foreach (var str in hero.Powers)
                {
                    currentHero.Powers.Add(new SuperHeroPower()
                    {
                        PowerName = str,
                        SuperHero = currentHero
                    });
                }

                if (alreadyExists)
                {
                    repo.Update(currentHero);
                }
                else
                {
                    repo.Insert(currentHero);
                }

                repo.Save();
            }
            Close();
        }
Beispiel #2
0
 private void ReloadSelectedHero()
 {
     using (var repo = new SuperHeroRepository())
     {
         Heroes.Remove(_selectedHero);
         var hero = repo.GetById(_selectedHero.Id);
         _selectedHero = hero;
         Heroes.Add(_selectedHero);
         SetHero(_selectedHero);
     }
 }
Beispiel #3
0
        private async Task LoadComboBox()
        {
            using (var repo = new SuperHeroRepository())
            {
                Heroes = await repo.GetListAsync();

                cbLoadedSuperHeroes.DataSource    = Heroes;
                cbLoadedSuperHeroes.DisplayMember = "SuperHeroName";
                cbLoadedSuperHeroes.ValueMember   = "Id";
                if (Heroes.Count > 0)
                {
                    cbLoadedSuperHeroes.SelectedIndex = 0;
                }
            }
        }
Beispiel #4
0
 public SuperHeroAppService()
 {
     superHeroRepository = new SuperHeroRepository();
 }
Beispiel #5
0
 public FightAppService()
 {
     superHeroRepository = new SuperHeroRepository();
     villainRepository = new VillainRepository();
     fightingDomainService = new FightDomainService();
 }