예제 #1
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            // determine deletions first
            if (_oldLineups?.Lineups != null)
            {
                foreach (var lineup in _oldLineups.Lineups)
                {
                    var delete = listView1.Items.Cast <ListViewItem>().All(item => (string)item.Tag != lineup.Lineup);
                    if (delete)
                    {
                        SdApi.RemoveLineup(lineup.Lineup);
                    }
                }
            }

            // add the new lineups
            foreach (ListViewItem item in listView1.Items)
            {
                var add = true;
                if (_oldLineups?.Lineups != null)
                {
                    if (_oldLineups.Lineups.Any(lineup => (string)item.Tag == lineup.Lineup))
                    {
                        add = false;
                    }
                }

                if (!add)
                {
                    continue;
                }
                if (SdApi.AddLineup((string)item.Tag))
                {
                    NewLineups.Add((string)item.Tag);
                }
                else
                {
                    MessageBox.Show($"Failed to add lineup \"{(string) item.Tag}\" to your account. Check the log for more details.");
                }
            }
            Cancel = false;
            Close();
        }