/// <summary>Adds the new unit.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ButtonNewUnitEventArgs"/> instance containing the event data.</param>
        private void AddNewUnit(object sender, ButtonNewUnitEventArgs e)
        {
            var myUnit = MakeUnitFromString(e.UnitName);

            using (var context = new ArmyDataContext())
            {
                var newUnit = new Engage_Unit
                {
                    ArmyId   = this.View.Model.ArmyID,
                    Size     = myUnit.InitialSize,
                    UnitType = myUnit.ServerID,
                    Squad    = null
                };

                context.Engage_Units.InsertOnSubmit(newUnit);
                context.SubmitChanges();

                var newWargear = from wargear in myUnit.SelectedWargearUpgrades
                                 join wargearName in context.Engage_WargearUpgrades on wargear.Key equals wargearName.Wargear
                                 select new Engage_Unit_Wargear {
                    UnitID = newUnit.UnitId, WargearID = wargearName.WargearID, Amount = wargear.Value
                };

                context.Engage_Unit_Wargears.InsertAllOnSubmit(newWargear);
                context.SubmitChanges();

                var editUrl    = this.ModuleContext.EditUrl("UnitId", newUnit.UnitId.ToString(CultureInfo.InvariantCulture), "EditUnit");
                var insertUnit = new ViewArmyManagerViewModel.UnitViewModel(myUnit, editUrl);
                this.View.Model.Army.Append(insertUnit);
            }

            this.RefreshView();
        }
        /// <summary>Makes the unit from server data.</summary>
        /// <param name="unitType">Type of the unit.</param>
        /// <param name="size">The size.</param>
        /// <param name="unitID">The unit identifier.</param>
        /// <param name="context">The context.</param>
        /// <returns>A <see cref="EditUnitViewModel"/></returns>
        public ViewArmyManagerViewModel.UnitViewModel MakeUnitFromServerData(int unitType, int size, int unitID, ArmyDataContext context)
        {
            Unit newUnit;

            switch (unitType)
            {
            case 1:
                newUnit = new Termagant();
                break;

            case 2:
                newUnit = new HiveTyrant();
                break;

            case 3:
                newUnit = new HiveGuard();
                break;

            case 4:
                newUnit = new Lictor();
                break;

            case 5:
                newUnit = new Zoanthrope();
                break;

            case 6:
                newUnit = new Venomthrope();
                break;

            case 7:
                newUnit = new Haruspex();
                break;

            case 8:
                newUnit = new Pyrovore();
                break;

            case 9:
                newUnit = new Gargoyle();
                break;

            case 10:
                newUnit = new Harpy();
                break;

            case 11:
                newUnit = new HiveCrone();
                break;

            case 12:
                newUnit = new SporeMine();
                break;

            case 13:
                newUnit = new Biovore();
                break;

            case 14:
                newUnit = new Tyrannofex();
                break;

            case 15:
                newUnit = new Deathleaper();
                break;

            case 16:
                newUnit = new OldOneEye();
                break;

            case 17:
                newUnit = new Hormagaunt();
                break;

            case 18:
                newUnit = new RipperSwarm();
                break;

            default:
                newUnit = new Termagant();
                break;
            }

            newUnit.CurrentSize = size;
            newUnit.UnitID      = unitID;

            var listWargear = (from wargear in context.Engage_Unit_Wargears
                               join names in context.Engage_WargearUpgrades on wargear.WargearID equals names.WargearID
                               where wargear.UnitID == unitID
                               select new { wargear.Amount, names.Wargear })
                              .ToDictionary(a => a.Wargear, a => a.Amount);

            foreach (var wargear in listWargear)
            {
                newUnit.SetWargear(wargear.Key, wargear.Value);
            }

            var listRules = from rules in context.Engage_Unit_Rules
                            join names in context.Engage_RulesUpgrades on rules.RuleID equals names.RuleID
                            where rules.UnitID == unitID
                            select names.RuleName;

            foreach (var rule in listRules)
            {
                newUnit.SetUpgrade(rule);
            }

            var editUrl = this.ModuleContext.EditUrl(
                "UnitId",
                unitID.ToString(CultureInfo.InvariantCulture),
                "EditUnit");

            var newUnitModel = new ViewArmyManagerViewModel.UnitViewModel(newUnit, editUrl);

            return(newUnitModel);
        }