Ejemplo n.º 1
0
        public string GetCompetitionById(Int16 competitionid)
        {
            try {
                DBController dbc = new DBController();
                Competition competition = dbc.GetCompetitionByCompetitionId(competitionid);
                dbc.Close();

                return JsonConvert.SerializeObject(competition);
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                DBController dbc = new DBController();
                dbc.AddLog("GetCompetitionById?competitionid={competitionid}", null, null, competitionid, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), "");
                dbc.Close();
            }

            return "";
        }
Ejemplo n.º 2
0
        public string GetCompetitionForOverview(Int16 competitionid, Int16 carid)
        {
            try {
                DBController dbc = new DBController();
                int countrank = 1;

                List<CompetingIn> CompetingIns = new List<CompetingIn>();
                Competition competition = dbc.GetCompetitionByCompetitionId(competitionid);
                dbc.Close();

                CompetitionOverview comView = new CompetitionOverview(competition);

                CompetingIns = dbc.GetCompetitionInByCompetitionId(competition.CompetitionId);

                List<CompetingIn> scored = CompetingIns.Where(o => o.Attempts > 0).ToList();
                List<CompetingIn> notScored = CompetingIns.Where(o => o.Attempts == 0).ToList();

                comView.Leaderboard = scored.OrderBy(o => o.Score).ToList();
                comView.Leaderboard.AddRange(notScored);

                comView.ParticipantCount = comView.Leaderboard.Count;

                foreach (CompetingIn compin in comView.Leaderboard) {
                    if (compin.CarId == carid) {
                        comView.AttemptCount = compin.Attempts;
                        comView.Score = compin.Score;
                        comView.Rank = countrank;
                    } else { countrank++; }
                }

                return JsonConvert.SerializeObject(comView);

            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                DBController dbc = new DBController();
                dbc.AddLog("GetCompetitionForOverview?competitionid={competitionid}&carid={carid}", carid, null, competitionid, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), "");
                dbc.Close();
            }

            return "";
        }