protected void Button1_Click(object sender, EventArgs e) { if (ValidInputs()) { var name = UnitName.Value; var race = ArmyContext.GetRaceById(int.Parse(RaceDropdown.SelectedValue)); Enum.TryParse(XPLevelDropdown.SelectedValue, out Level level); Enum.TryParse(EquipmentDropdown.SelectedValue, out EquipmentLevel equipment); Enum.TryParse(UnitTypeDropdown.SelectedValue, out UnitTypes.UnitType unitType); Enum.TryParse(SizeDropdown.SelectedValue, out Dice size); List <Trait> unitTratits = new List <Trait>(); foreach (var sItem in TraitsList.Items.Cast <ListItem>().Where(sItem => sItem.Selected)) { var toAdd = ArmyContext.GetTraitById(int.Parse(sItem.Value)); unitTratits.Add(toAdd); } //Create unit from inputs var unit = new SaveableObjects.Unit(name, race, level, equipment, unitType, unitTratits, size); //Add Unit and Race to DataLists ArmyContext.AddUnit(unit); } }
protected void Button1_Click(object sender, EventArgs e) { var trait = new Trait() { Name = TraitName.Value, Description = TraitDesc.Value, Cost = int.Parse(TraitCost.Value) }; var listOfRaces = new List <Race>(); for (int i = 0; i < RaceCheckBoxList.Items.Count; i++) { if (RaceCheckBoxList.Items[i].Selected) { var race = ArmyContext.GetRaceById(int.Parse(RaceCheckBoxList.Items[i].Value)); race.RaceTraits.Add(trait); ArmyContext.UpdateRace(race); } } ArmyContext.AddTrait(trait); }