Example #1
0
        public void TestCopyOverwrite()
        {
            TemplatesService ts = new TemplatesService(storage);

            ts.Start();
            ITeamTemplatesProvider teamtemplateprovider = ts.TeamTemplateProvider;
            LMTeam teamB = LMTeam.DefaultTemplate(5);

            teamB.Name          = "B";
            teamB.TeamName      = "Template B";
            teamB.FormationStr  = "1-4";
            teamB.List [0].Name = "Paco";
            teamtemplateprovider.Save(teamB);
            LMTeam teamA = new LMTeam();

            teamA.Name         = "A";
            teamA.TeamName     = "Template A";
            teamA.FormationStr = "1-4-3-3";
            teamtemplateprovider.Save(teamA);

            LMTeam auxdelete = teamA;

            teamtemplateprovider.Copy(teamB, "A");
            teamtemplateprovider.Delete(auxdelete);
            teamA = teamtemplateprovider.Templates [0] as LMTeam;

            Assert.AreEqual(4, teamtemplateprovider.Templates.Count);
            Assert.AreEqual("A", teamA.Name);
            Assert.AreEqual("Template B", teamA.TeamName);
            Assert.AreEqual(teamB.List.Count, teamA.List.Count);
            Assert.AreEqual("1-4", teamA.FormationStr);
            Assert.AreEqual("Paco", teamA.List [0].Name);
        }
Example #2
0
        void HandleNewTeamClicked(object sender, EventArgs e)
        {
            bool create = false;
            bool force  = false;

            EntryDialog dialog = new EntryDialog(Toplevel as Gtk.Window);

            dialog.ShowCount          = true;
            dialog.Text               = Catalog.GetString("New team");
            dialog.AvailableTemplates = templatesNames;

            while (dialog.Run() == (int)ResponseType.Ok)
            {
                if (dialog.Text == "")
                {
                    MessagesHelpers.ErrorMessage(dialog, Catalog.GetString("The template name is empty."));
                    continue;
                }
                else if (dialog.Text == "default")
                {
                    MessagesHelpers.ErrorMessage(dialog, Catalog.GetString("The template can't be named 'default'."));
                    continue;
                }
                else if (provider.Exists(dialog.Text))
                {
                    var msg = Catalog.GetString("The template already exists. " +
                                                "Do you want to overwrite it?");
                    if (MessagesHelpers.QuestionMessage(this, msg))
                    {
                        create = true;
                        force  = true;
                        break;
                    }
                }
                else
                {
                    create = true;
                    break;
                }
            }

            if (create)
            {
                if (force)
                {
                    try {
                        provider.Delete(dialog.Text);
                    } catch (Exception ex) {
                        Log.Exception(ex);
                    }
                }
                if (dialog.SelectedTemplate != null)
                {
                    provider.Copy(dialog.SelectedTemplate, dialog.Text);
                }
                else
                {
                    Team team;
                    team          = Team.DefaultTemplate(dialog.Count);
                    team.TeamName = dialog.Text;
                    team.Name     = dialog.Text;
                    if (!SaveTemplate(team))
                    {
                        dialog.Destroy();
                        return;
                    }
                }
                Load(dialog.Text);
            }
            dialog.Destroy();
        }