public static ONLTeamsCompLink AddTeamToCompetition(this ONLteam team, long compID, int?ranking = null)
        {
            int rToSet = (ranking == null ? int.MaxValue : ranking.Value);

            if (team.ONLTeamsCompLinks.Count(l => l.comp_id == compID) > 0)
            {
                ONLTeamsCompLink lnkF = dc.ONLTeamsCompLinks.First(l => l.team_id == team.iid && l.comp_id == compID);
                if (ranking != null && lnkF.ranking_pos != rToSet)
                {
                    lnkF.ranking_pos = rToSet;
                    dc.SaveChanges();
                }
                return(lnkF);
            }
            long newID;

            try { newID = dc.ONLTeamsCompLinks.OrderByDescending(l => l.iid).First().iid + 1; }
            catch { newID = 1; }
            int secretaryID;

            try
            {
                secretaryID = dc.ONLTeamsCompLinks.Where(l => l.comp_id == compID).
                              OrderByDescending(li => li.secretary_id).First().secretary_id + 1;
            }
            catch { secretaryID = 1; }
            ONLTeamsCompLink ln = ONLTeamsCompLink.CreateONLTeamsCompLink(newID, team.iid, compID, secretaryID, rToSet);

            dc.ONLTeamsCompLinks.AddObject(ln);
            dc.SaveChanges();
            return(ln);
        }
Example #2
0
 private bool SetTeam(ONLteam t)
 {
     if (t == null)
     {
         return(false);
     }
     panelEdit.Visible = true;
     SetCompVisible();
     lblIid.Text = t.iid.ToString();
     tbName.Text = t.name;
     if (cbUsedNow.Visible)
     {
         cbUsedNow.Checked = (t.ONLTeamsCompLinks.Count(lnk => lnk.comp_id == compID) > 0);
         if (cbUsedNow.Checked)
         {
             ONLTeamsCompLink lnk = t.ONLTeamsCompLinks.First(ln => ln.comp_id == compID);
             tbRanking.Text = (lnk.ranking_pos > 0 && lnk.ranking_pos < int.MaxValue) ? lnk.ranking_pos.ToString() : String.Empty;
         }
         else
         {
             tbRanking.Text = String.Empty;
         }
     }
     try
     {
         if (t.group_id == null || !t.group_id.HasValue)
         {
             cbGroupToSet.SelectedIndex = 0;
         }
         else
         {
             cbGroupToSet.SelectedValue = t.group_id.Value.ToString();
         }
     }
     catch { cbGroupToSet.SelectedIndex = 0; }
     lblError.Text = String.Empty;
     return(true);
 }