protected override void RemoveLinkedCollections(ClimbingContext2 context, LogicTransaction ltr) { if (AgeGroupAppearances != null && AgeGroupAppearances.Count > 0) { throw new InvalidOperationException("Can\'t delete age group. It is used at one or more competitions"); } }
private ClimbingContext2 LoadContext() { return(ClimbingContext2.CreateContextForBrowser(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["RemoteDbConnection"].ConnectionString, null, null, "API_CALL")); }
public int GetNextCode(ClimbingContext2 context) { Team parentTeam = this.ParentTeam; if (parentTeam == null && this.IidParent != null) { parentTeam = context.Teams.FirstOrDefault(t => t.Iid.Equals(this.IidParent, StringComparison.Ordinal)); } int result; IEnumerable <Team> enumer; if (parentTeam == null) { enumer = context.Teams.Where(t => t.IidParent == null); } else { enumer = parentTeam.ChildTeams; } result = (enumer == null || enumer.Count() < 1) ? 1 : (enumer.Max(t => t.Code) + 1); this.Code = result; CalculateFullCode(); return(result); }
private void SortSpeedFinalRound(IEnumerable <ListLineSpeed> results, ClimbingContext2 context) { var climbed = results.Where(r => r.HasResult()).ToList(); while (climbed.Count > 0) { var c1 = climbed.First(); var c2 = climbed.FirstOrDefault(c => c.Start == (c1.Start % 2 == 1 ? c1.Start + 1 : (c1.Start - 1))); int n; var c1Prev = this.PreviousRound.GetResult(c1.Climber.Iid, out n, context); if (c2 == null) { c1.Points = c1.Pos = c1Prev.Pos; c1.PosText = c1.PtsText = c1.Points.ToString(); climbed.RemoveAt(0); continue; } var c2Prev = this.PreviousRound.GetResult(c2.Climber.Iid, out n, context); if (c1.CompareTo(c2, true) > 0) { c2 = System.Threading.Interlocked.Exchange(ref c1, c2); } c1.Pos = Math.Min(c1Prev.Pos, c2Prev.Pos); c2.Pos = Math.Max(c1Prev.Pos, c2Prev.Pos); c1.Points = c1.Pos; c2.Points = c2.Pos; c1.PosText = c1.PtsText = c1.Pos.ToString(); c2.PosText = c2.PtsText = c2.Pos.ToString(); climbed.Remove(c1); climbed.Remove(c2); } }
private IEnumerable <IListLine> LoadResults(ClimbingContext2 context) { if (preloadedResults == null) { if (context == null) { throw new ArgumentNullException("context"); } if (this.ListType == ListType.LeadFlash) { preloadedResults = this.CreateFlashResults(context); } else { switch (this.Style) { case ClimbingStyles.Lead: preloadedResults = context.ResultsLead.Where(r => r.ListId == this.Iid).ToList(); break; case ClimbingStyles.Speed: preloadedResults = context.ResultsSpeed.Where(r => r.ListId == this.Iid).ToList(); break; case ClimbingStyles.Bouldering: preloadedResults = context.ResultsBoulder.Where(r => r.ListId == this.Iid).ToList(); break; } } } return(preloadedResults); }
private IListLine GetResult(String climberId, out int routeNumber, ClimbingContext2 context) { routeNumber = 0; switch (this.ListType) { case ClimbingCompetition.Common.ListType.LeadGroups: case ClimbingCompetition.Common.ListType.BoulderGroups: int n; foreach (var childList in this.Children) { routeNumber++; var res = childList.GetResult(climberId, out n, context); if (res != null) { if (n < 0) { routeNumber = n; } return(res); } } return(null); default: var result = this.LoadResults(context).FirstOrDefault(r => r.Climber.Iid == climberId); if (result == null || result.PreQf) { routeNumber = -1; } return(result); } }
protected override void RemoveLinkedCollections(ClimbingContext2 context, LogicTransaction ltr) { if (OrganizedCompetitions != null && OrganizedCompetitions.Count > 0) { throw new InvalidOperationException("Can\'t remove team. There\'re one or more competitions organized by this team"); } RemoveChildCollection(context, TeamClimbers, ltr); RemoveChildCollection(context, ChildTeams, ltr); if (this.TeamMainUsers != null) { foreach (var u in this.TeamMainUsers) { if (ltr != null) { ltr.AddUpdatedObjectBefore(u, context); } u.Team = null; u.TeamId = null; if (ltr != null) { ltr.AddUpatedObjectAfter(u, context); } } this.TeamMainUsers.Clear(); } }
protected override void RemoveLinkedCollections(ClimbingContext2 context, LogicTransaction ltr) { if (CompetitionAppearances != null && CompetitionAppearances.Count > 0) { throw new InvalidOperationException("This climber has appeared on several competitions"); } }
protected override void RemoveLinkedCollections(ClimbingContext2 context, LogicTransaction ltr) { if (this.ResultLists != null) { this.RemoveChildCollection(context, ResultLists.OrderByDescending(r => r.Iid), ltr); } this.RemoveChildCollection(context, AgeGroups, ltr); this.RemoveChildCollection(context, Parameters, ltr); }
private void SortBlock(IEnumerable <IListLine> block, ClimbingContext2 context) { var roundResults = block.Select(ln => { int routeNumber; var n = this.GetResult(ln.Climber.Iid, out routeNumber, context); return(new { Result = n, Route = routeNumber }); }) .ToList(); if (roundResults.Count(r => r.Result == null) > 0 || roundResults.Select(r => r.Route).Distinct().Count() > 1) { return; } roundResults.Sort((a, b) => a.Result.CompareTo(b.Result, this.PreviousRound != null)); var resultDict = block.ToDictionary(b => b.Climber.Iid); IListLine current = null; List <IListLine> currentBlock = this.PreviousRound == null ? null : new List <IListLine>(); int startPos = block.First().Pos; for (int i = 0; i < roundResults.Count; i++) { if (current != null && current.EqualResults(roundResults[i].Result)) { resultDict[roundResults[i].Result.Climber.Iid].Pos = resultDict[current.Climber.Iid].Pos; if (currentBlock != null) { if (currentBlock.Count < 1) { currentBlock.Add(resultDict[current.Climber.Iid]); } currentBlock.Add(resultDict[roundResults[i].Result.Climber.Iid]); } } else { if (currentBlock != null && currentBlock.Count > 1) { this.PreviousRound.SortBlock(currentBlock, context); currentBlock.Clear(); } current = roundResults[i].Result; resultDict[current.Climber.Iid].Pos = startPos + i; } } if (currentBlock != null && currentBlock.Count > 1) { this.PreviousRound.SortBlock(currentBlock, context); } }
protected override void RemoveLinkedCollections(ClimbingContext2 context, LogicTransaction ltr) { if (this.NextRounds != null) { foreach (var nr in this.NextRounds) { nr.PreviousRound = null; nr.PrevRoundIid = null; } this.NextRounds.Clear(); } this.RemoveChildCollection(context, Children, ltr); this.RemoveChildCollection(context, Results, ltr); }
private void SortSpeedFinals(IEnumerable <ListLineSpeed> results, ClimbingContext2 context) { if (this.PreviousRound.ListType == ListType.SpeedFinal && results.Count() <= 4 && this.PreviousRound.LoadResults(context).Count() <= 4) { this.SortSpeedFinalRound(results, context); } else if ((this.Competition.GetRules() & Rules.International) == Rules.International) { this.SortSpeedFinalsInternational(results, context); } else { this.SortSpeedFinalsRussian(results, context); } }
public void Sort(ClimbingContext2 context) { switch (this.ListType) { case ListType.SpeedFinal: this.SortSpeedFinals(this.LoadResults(context).OfType <ListLineSpeed>(), context); break; case ListType.LeadFlash: break; default: this.Sort(this.LoadResults(context), true, context); break; } }
private ClimbingContext2 LoadContext() { string ip, machine, user; IPAddress ipA; GetHttpContextData(out ip, out machine, out user); if (!IPAddress.TryParse(ip, out ipA)) { ipA = null; } return(ClimbingContext2.CreateContextForBrowser(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["RemoteDbConnection"].ConnectionString, user, ipA, machine)); }
private List <FlashListLine> CreateFlashResults(ClimbingContext2 context) { if (this.ListType != ClimbingCompetition.Common.ListType.LeadFlash || this.Children == null || this.Children.Count < 1) { return(new List <FlashListLine>()); } var routes = this.Children.OrderBy(a => a.RouteNumber).ToArray(); routes[0].Sort(context); var resultDict = routes[0].LoadResults(context).OfType <ListLine>().Select(r => { var fl = new FlashListLine { Climber = r.Climber, PreQf = r.PreQf }; fl.ChildResults.Add(r); return(fl); }) .ToDictionary(r => r.Climber.Iid); for (int i = 1; i < routes.Length; i++) { routes[i].Sort(context); foreach (var res in routes[i].LoadResults(context).OfType <ListLine>()) { if (!resultDict.ContainsKey(res.ClimberId)) { resultDict.Add(res.ClimberId, new FlashListLine { Climber = res.Climber }); } resultDict[res.ClimberId].ChildResults.Add(res); if (res.PreQf) { resultDict[res.ClimberId].PreQf = true; } } } var result = resultDict.Values.ToList(); result.ForEach(v => v.CalculatePts(this.PreviousRound != null)); this.Sort(result, true, context); return(result); }
public IEnumerable <IListLine> LoadSortedResults(ClimbingContext2 context) { if (preloadedResultSorted == null) { var pLpreloadedResultSorted = this.LoadResults(context) .ToList(); pLpreloadedResultSorted.Sort((a, b) => { int n = a.Pos.CompareTo(b.Pos); if (n != 0) { return(n); } return(a.CompareTo(b, this.PreviousRound != null)); }); this.preloadedResultSorted = pLpreloadedResultSorted; } return(this.preloadedResultSorted); }
public ClimberOnCompetition(ClimbingContext2 context) : base(context) { this.Qf = ClimberQf.Empty; this.Styles = 0; }
protected override void RemoveLinkedCollections(ClimbingContext2 context, LogicTransaction ltr) { RemoveChildCollection(context, Teams, ltr); }
public Team(ClimbingContext2 context) : base(context) { }
protected override void RemoveEntity(ClimbingContext2 context) { context.Teams.Remove(this); }
public Climber(ClimbingContext2 context) : base(context) { }
public Competition(ClimbingContext2 context) : base(context) { }
public ListLineBoulder(ClimbingContext2 context) : base(context) { this.ResultType = ResultType.RES; }
public AgeGroupOnCompetition(ClimbingContext2 context) : base(context) { this.StylesForGroup = 0; }
protected override void RemoveEntity(ClimbingContext2 context) { context.ResultsBoulder.Remove(this); }
public Person(ClimbingContext2 context) : base(context) { this.Name = this.Patronymic = string.Empty; this.Gender = Gender.Male; }
protected override void RemoveEntity(ClimbingContext2 context) { context.ClimbersOnCompetition.Remove(this); }
public ClimberTeamOnCompetition(ClimbingContext2 context) : base(context) { }
public AgeGroup(ClimbingContext2 context) : base(context) { this.Gender = Gender.Male; }
public UserWithTeam(ClimbingContext2 context) : base(context) { }