public static async Task <string> AddRace(Race race)
        {
            var raceService = new RaceService();
            var response    = await raceService.AddRace(race);

            return(response.ToString());
        }
Exemple #2
0
        private void TryCreateNewRace(string[] input)
        {
            if (input.Length == 5)
            {
                _raceService.AddRace(new Model.Race(input));
                logger.Info("Race created");
                return;
            }

            logger.Info("Could not create race, wrong number of arguments");
        }
        private static string ProcessText(string pdfText, DateTime?raceDate, SACServiceContext db)
        {
            string[] lines = pdfText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            int currentAgeRankId = -1;

            using (RaceService raceService = new RaceService(db))
                using (AgeRankService ageRankService = new AgeRankService(db))
                    using (TeamService teamService = new TeamService(db))
                        using (AthleteService athleteService = new AthleteService(db))
                            using (RaceResultService raceResultService = new RaceResultService(db))
                            {
                                int raceId = -1;
                                for (int i = 0; i < lines.Length; i++)
                                {
                                    if (i < 2)
                                    {
                                        continue;
                                    }
                                    if (string.IsNullOrEmpty(lines[i]))
                                    {
                                        continue;
                                    }
                                    if (i == 2)
                                    {
                                        if ((raceId = raceService.RaceExists(lines[i])) != -1)
                                        {
                                            return("A Race with this name already exists!");
                                        }
                                        raceId = raceService.AddRace(lines[i], raceDate).Id;
                                        continue;
                                    }
                                    if (lines[i].StartsWith("Class."))
                                    {
                                        string currentAgeRank = lines[i - 1];
                                        if (currentAgeRank.ToLower().Contains("(cont.)"))
                                        {
                                            continue;
                                        }
                                        if ((currentAgeRankId = ageRankService.AgeRankExists(currentAgeRank)) == -1)
                                        {
                                            currentAgeRankId = ageRankService.AddAgeRank(SAC.Models.AgeRankMappings.GetAgeRankNameByCode(currentAgeRank)).Id;
                                        }
                                        continue;
                                    }
                                    string[] result = lines[i].Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries);
                                    if (result.Length < 5)
                                    {
                                        continue;
                                    }

                                    int    test;
                                    int    position;
                                    int    bibNumber;
                                    string athleteName;
                                    string teamName;
                                    int    points;
                                    if (int.TryParse(result[1].Trim(), out test))
                                    {
                                        position    = Convert.ToInt16(result[0].Replace("º", "").Trim());
                                        bibNumber   = Convert.ToInt16(result[1].Trim());
                                        athleteName = result[2];
                                        teamName    = result[3];
                                        points      = 0;
                                        Int32.TryParse(result[4].Trim(), out points);
                                    }
                                    else
                                    {
                                        position    = Convert.ToInt16(result[0].Replace("º", "").Trim());
                                        bibNumber   = Convert.ToInt16(result[2].Trim());
                                        athleteName = result[1];
                                        teamName    = result[3];
                                        points      = 0;
                                        Int32.TryParse(result[4].Trim(), out points);
                                    }

                                    int athleteId;
                                    if ((athleteId = athleteService.AthleteExists(bibNumber)) == -1)
                                    {
                                        int teamId;
                                        if ((teamId = teamService.TeamExists(teamName)) == -1)
                                        {
                                            teamId = teamService.AddTeam(teamName).Id;
                                        }
                                        athleteId = athleteService.AddAthlete(athleteName, bibNumber, currentAgeRankId, teamId).Id;
                                    }
                                    else
                                    {
                                        Athlete athlete = athleteService.GetAthlete(athleteId);
                                        if (athlete.AgeRankId != currentAgeRankId)
                                        {
                                            athleteService.UpdateAthlete(athleteId, currentAgeRankId);
                                        }
                                    }

                                    if (raceId != -1)
                                    {
                                        raceResultService.AddRaceResult(position, points, athleteId, currentAgeRankId, raceId);
                                    }
                                }
                            }

            return(string.Empty);
        }