/// <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>Deletes the unit.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ButtonDeleteUnitEventArgs"/> instance containing the event data.</param>
        private void DeleteUnit(object sender, ButtonDeleteUnitEventArgs e)
        {
            using (var context = new ArmyDataContext())
            {
                var myUnit =
                    (from unit in context.Engage_Units
                     where unit.UnitId == e.UnitId
                     where unit.ArmyId == this.View.Model.ArmyID
                     select unit).SingleOrDefault();

                var myRules = from unitRules in context.Engage_Unit_Rules
                              where unitRules.UnitID == e.UnitId
                              select unitRules;

                var myWargear = from unitWargear in context.Engage_Unit_Wargears
                                where unitWargear.UnitID == e.UnitId
                                select unitWargear;

                context.Engage_Unit_Rules.DeleteAllOnSubmit(myRules);
                context.Engage_Unit_Wargears.DeleteAllOnSubmit(myWargear);
                context.Engage_Units.DeleteOnSubmit(myUnit);
                context.SubmitChanges();
            }

            this.RefreshView();
        }
Пример #3
0
        /// <summary>Updates the rules.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RuleUpgradeCheckedEventArgs"/> instance containing the event data.</param>
        private void UpdateRules(object sender, RuleUpgradeCheckedEventArgs e)
        {
            var checkUnit = this.View.Model.DisplayUnit;

            var newRules     = e.SelectedValues.Except(checkUnit.Unit.SelectedRuleUpgrades);
            var deletedRules = checkUnit.Unit.SelectedRuleUpgrades.Except(e.SelectedValues);

            using (var context = new ArmyDataContext())
            {
                var myUnit = context.Engage_Units.SingleOrDefault(unit => unit.UnitId == e.UnitId);

                var rules = (from rule in context.Engage_RulesUpgrades
                             where newRules.Contains(rule.RuleName)
                             select new { rule.RuleID, UnitID = myUnit.UnitId, })
                            .AsEnumerable()
                            .Select(rule => new Engage_Unit_Rule {
                    RuleID = rule.RuleID, UnitID = rule.UnitID,
                });

                var deleteRules = from rule in context.Engage_Unit_Rules
                                  join ruleName in context.Engage_RulesUpgrades on rule.RuleID equals ruleName.RuleID
                                  where rule.UnitID == myUnit.UnitId
                                  where deletedRules.Contains(ruleName.RuleName)
                                  select rule;

                context.Engage_Unit_Rules.DeleteAllOnSubmit(deleteRules);
                context.Engage_Unit_Rules.InsertAllOnSubmit(rules);

                context.SubmitChanges();
            }

            this.RefreshEditView();
        }
Пример #4
0
        /// <summary>Updates the wargear.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ButtonWargearEventArgs"/> instance containing the event data.</param>
        private void UpdateWargear(object sender, ButtonWargearEventArgs e)
        {
            var checkUnit        = this.View.Model.DisplayUnit;
            var newWargearValues = e.Wargear;

            foreach (var upgrade in newWargearValues)
            {
                checkUnit.Unit.SetWargear(upgrade.Key, upgrade.Value);
            }

            using (var context = new ArmyDataContext())
            {
                var myUnit = context.Engage_Units.SingleOrDefault(unit => unit.UnitId == e.UnitID);

                foreach (var wargear in checkUnit.Unit.SelectedWargearUpgrades)
                {
                    var myWargear = (from wargearTable in myUnit.Engage_Unit_Wargears
                                     join wargearNames in context.Engage_WargearUpgrades on wargearTable.WargearID equals wargearNames.WargearID
                                     where wargearNames.Wargear == wargear.Key
                                     select wargearTable).SingleOrDefault();

                    myWargear.Amount = wargear.Value;
                }

                context.SubmitChanges();
            }

            this.RefreshEditView();
        }
        /// <summary>Makes the army.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ButtonNewArmyEventArgs"/> instance containing the event data.</param>
        private void MakeArmy(object sender, ButtonNewArmyEventArgs e)
        {
            using (var context = new ArmyDataContext())
            {
                var newArmy = new Engage_Army();
                newArmy.ArmyName  = e.ArmyName;
                newArmy.MaxPoints = e.Points;

                context.Engage_Armies.InsertOnSubmit(newArmy);
                context.SubmitChanges();
                this.View.Model.MaxPoints = newArmy.MaxPoints;
                this.View.Model.Name      = newArmy.ArmyName;
                this.View.Model.ArmyID    = newArmy.ArmyID;
            }

            this.Response.Redirect(Globals.NavigateURL(this.TabId, string.Empty, "ArmyId=" + this.View.Model.ArmyID.ToString(CultureInfo.InvariantCulture)));
        }
Пример #6
0
        /// <summary>Updates the size.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ButtonSetSizeEventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.InvalidOperationException">Cannot update a unit that does not exist.</exception>
        private void UpdateSize(object sender, ButtonSetSizeEventArgs e)
        {
            var checkUnit = this.View.Model.DisplayUnit;

            checkUnit.Unit.CurrentSize = e.Size;
            var size = checkUnit.Unit.CurrentSize;

            using (var context = new ArmyDataContext())
            {
                var myUnit = context.Engage_Units.SingleOrDefault(unit => unit.UnitId == e.UnitID);

                if (myUnit == null)
                {
                    throw new InvalidOperationException("Cannot update a unit that does not exist.");
                }

                myUnit.Size = size;
                context.SubmitChanges();
            }

            this.RefreshEditView();
        }