Ejemplo n.º 1
0
        private void BtnEdit_Click(object sender, RoutedEventArgs e)
        {
            var item = (Coalition)LstCoalitions.SelectedItem;

            if (item == null)
            {
                return;
            }

            Coalition result;

            if (!EditCoalitionDialog.TryEditCoalition(item, out result))
            {
                return;
            }

            var existingCoalitions = Properties.Settings.Default.Coalitions.Where(x => x.Name != item.Name).ToList();

            if (existingCoalitions.Any(x => x.Name == result.Name))
            {
                MessageBox.Show(
                    string.Format("Another coalition named \"{0}\" already exists, please choose another name", result.Name),
                    "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);

                BtnEdit_Click(sender, e);
                return;
            }

            Properties.Settings.Default.Coalitions = existingCoalitions.Concat(new[] { result }).ToList();
        }
Ejemplo n.º 2
0
        public static bool TryCreateCoalition(out Coalition coalition)
        {
            var dialog = new EditCoalitionDialog
            {
                Title = "Add Coalition"
            };

            return(TryGetResult(out coalition, dialog));
        }
Ejemplo n.º 3
0
        public static bool TryEditCoalition(Coalition editInput, out Coalition result)
        {
            var dialog = new EditCoalitionDialog
            {
                TxtName            = { Text = editInput.Name },
                TxtMemberAlliances = { Text = string.Join(",\n", editInput.MemberAlliances) },
                Title = "Edit Coalition"
            };

            return(TryGetResult(out result, dialog));
        }
Ejemplo n.º 4
0
        private static bool TryGetResult(out Coalition coalition, EditCoalitionDialog dialog)
        {
            if (dialog.ShowDialog().GetValueOrDefault())
            {
                coalition = new Coalition
                {
                    Name            = dialog.TxtName.Text,
                    MemberAlliances = dialog.TxtMemberAlliances.Text.Split(',', ':', ';').Select(x => x.Trim()).OrderBy(x => x).ToList()
                };

                return(true);
            }

            coalition = null;
            return(false);
        }
Ejemplo n.º 5
0
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            Coalition coalition;

            if (!EditCoalitionDialog.TryCreateCoalition(out coalition))
            {
                return;
            }

            var existingCoalitions = Properties.Settings.Default.Coalitions;

            if (existingCoalitions.Any(x => x.Name == coalition.Name))
            {
                MessageBox.Show(
                    string.Format("A coalition named \"{0}\" already exists, please choose another name", coalition.Name),
                    "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);

                BtnAdd_Click(sender, e);
                return;
            }

            Properties.Settings.Default.Coalitions = existingCoalitions.Concat(new[] { coalition }).ToList();
        }