/// <summary> /// Asynchronous export item's properties /// </summary> /// <returns>An <see cref="ExportableCI"/> instance containing all relevant properties</returns> public async Task <ExportableGroupCI> ExportAsync() { var competitorsTask = Competitors?.Select(async c => await c.ExportAsync().ConfigureAwait(false) as ExportableCompetitorCI); return(new ExportableGroupCI { Id = Id, Competitors = competitorsTask != null ? await Task.WhenAll(competitorsTask) : null, CompetitorsReferences = CompetitorsReferences?.ToDictionary(c => c.Key.ToString(), c => c.Value.ReferenceIds.ToDictionary(r => r.Key, r => r.Value)), Name = Name }); }
public string SelectNewLeader() { if (Competitors.Count < 2) { throw new InvalidOperationException("Selecting a new leader is not possible when Competition has less than 2 competitors"); } Competitors.RemoveAll(c => c.Login == Leader); string newLeader = Competitors.Select(c => c.Login).First(); Leader = newLeader; Name = newLeader; return(newLeader); }
public void RandomizeCompetitors() { var rnd = new Random(); var randomCompetitors = Competitors.Select(x => new { value = x, order = rnd.Next() }).OrderBy(x => x.order).Select(x => x.value).ToList(); for (int i = 1; i <= randomCompetitors.Count; i++) { randomCompetitors[i - 1].StartPosition = i; } OrbitsRunGridType = RunGridType.Random; Competitors = randomCompetitors; }
/// <summary> /// Asynchronous export item's properties /// </summary> /// <returns>An <see cref="ExportableCI"/> instance containing all relevant properties</returns> public async Task <ExportableCurrentSeasonInfoCI> ExportAsync() { var groupsTask = Groups?.Select(async g => await g.ExportAsync().ConfigureAwait(false)); var competitorsTask = Competitors?.Select(async c => await c.ExportAsync().ConfigureAwait(false) as ExportableCompetitorCI); return(new ExportableCurrentSeasonInfoCI { Id = Id.ToString(), Name = new Dictionary <CultureInfo, string>(Name), Year = Year, StartDate = StartDate, EndDate = EndDate, SeasonCoverage = SeasonCoverage != null ? await SeasonCoverage.ExportAsync().ConfigureAwait(false) : null, Groups = groupsTask != null ? await Task.WhenAll(groupsTask) : null, CurrentRound = CurrentRound != null ? await CurrentRound.ExportAsync().ConfigureAwait(false) : null, Competitors = competitorsTask != null ? await Task.WhenAll(competitorsTask) : null, Schedule = Schedule?.Select(s => s.ToString()).ToList() }); }
public string ToHtmlString() { var classes = Competitors.Select(c => c.ClassName).Distinct().ToList(); StringBuilder result = new StringBuilder(); if (!IncludeCompetitors || Competitors.Count < 1 || Name.ToLower().Contains("practice")) { return(string.Empty); } result.AppendLine("<h1>" + GroupName + "</h1>"); result.AppendLine("<div class=\"flex-container\">"); result.AppendLine("<div class=\"left-column\">"); result.AppendLine("<h2>" + Name + "</h2>"); result.AppendLine("<div class=\"starting-grid-container\">"); foreach (string className in classes) { if (classes.Count > 1) { result.AppendLine("<h3>" + className + "</h3>"); } result.AppendLine("<div class=\"starting-grid-container\">"); int currentPosition = 1; for (int i = 0; i < Competitors.Count; i++) { if (Competitors[i].ClassName == className) { result.AppendLine("<div class=\"driver\">"); result.AppendLine("<div class=\"driver-position\">" + currentPosition.ToString() + "</div>"); result.AppendLine("<div class=\"driver-name\">" + Competitors[i].Number + " " + Competitors[i].FirstName + " " + Competitors[i].LastName + "</div>"); if (OrbitsRunGridType == RunGridType.Points) { result.AppendLine("<div class=\"driver-points\">" + Competitors[i].Points.ToString() + " pts.</div>"); } result.AppendLine("</div>"); currentPosition++; } } if (currentPosition % 2 != 1) { result.AppendLine("<div class=\"driver\"> </div>"); } result.AppendLine("</div>"); } result.AppendLine("</div>"); result.AppendLine("<div class=\"right-column\">"); result.AppendLine("<h2>Points</h2>"); foreach (string className in classes) { if (classes.Count > 1) { result.AppendLine("<h3>" + className + "</h3>"); } result.AppendLine("<div class=\"driver-points-container\">"); var seasonPoints = PointsList.Where(pl => pl.Class == className).OrderByDescending(pl => pl.Points); foreach (PointsEntry entry in seasonPoints) { result.AppendLine("<div class=\"driver-points-name\">" + entry.Number.ToString() + " " + entry.Name + "</div>"); result.AppendLine("<div class=\"driver-points-points\">" + entry.Points.ToString() + "</div>"); } result.AppendLine("</div>"); } result.AppendLine("</div>"); result.AppendLine("</div>"); return(result.ToString()); }