示例#1
0
        public double GetPoints(string rulesName, PerformanceDto performance)
        {
            if (string.IsNullOrEmpty(rulesName))
            {
                throw new ArgumentNullException("Missing RulesName");
            }
            if (performance == null)
            {
                throw new ArgumentNullException("Missing Performance");
            }

            var rules = rulesRepository.Get(rulesName);

            if (rules == RulesUnknown.Default)
            {
                throw new ArgumentOutOfRangeException("Unknown RulesName " + rulesName);
            }

            return(rules.GetPoints(ExtractPerformance(performance)));
        }
示例#2
0
        public override string Extract(TInput input)
        {
            var rulesName   = rulesExtractor(input);
            var performance = performanceExtractor(input);
            var rules       = rulesRepository.Get(rulesName);

            if (rules == null)
            {
                return("");
            }
            return(ExportedTableColumnExtractors.Performance(rules.PrimaryComponent, performance));
        }
示例#3
0
        public void PostAthlete(string raceId, string athleteId, AthleteDto incomingAthlete)
        {
            if (string.IsNullOrEmpty(raceId))
            {
                throw new ArgumentNullException("Missing RaceId");
            }
            if (string.IsNullOrEmpty(athleteId))
            {
                throw new ArgumentNullException("Missing AthleteId");
            }
            var  repositorySet  = repositorySetProvider.GetRepositorySet(raceId);
            bool requireProfile = false;

            var athleteModel = repositorySet.Athletes.FindAthlete(athleteId);

            if (athleteModel == null)
            {
                athleteModel               = new Athlete();
                athleteModel.AthleteId     = athleteId;
                athleteModel.Announcements = new List <Announcement>();
                athleteModel.ActualResults = new List <ActualResult>();
                requireProfile             = true;
            }

            if (incomingAthlete.Profile == null)
            {
                if (requireProfile)
                {
                    throw new ArgumentNullException("Missing Profile");
                }
            }
            else
            {
                if (string.IsNullOrEmpty(incomingAthlete.Profile.FirstName))
                {
                    throw new ArgumentNullException("Missing FirstName");
                }
                if (string.IsNullOrEmpty(incomingAthlete.Profile.Surname))
                {
                    throw new ArgumentNullException("Missing Surname");
                }
                athleteModel.FirstName        = incomingAthlete.Profile.FirstName;
                athleteModel.Surname          = incomingAthlete.Profile.Surname;
                athleteModel.Club             = incomingAthlete.Profile.Club;
                athleteModel.CountryName      = incomingAthlete.Profile.CountryName;
                athleteModel.ProfilePhotoName = incomingAthlete.Profile.ProfilePhotoName;
                athleteModel.Sex            = Sex.Parse(incomingAthlete.Profile.Sex);
                athleteModel.Category       = incomingAthlete.Profile.Category;
                athleteModel.ModeratorNotes = incomingAthlete.Profile.ModeratorNotes;
            }

            if (incomingAthlete.Announcements != null)
            {
                foreach (var incomingAnnouncement in incomingAthlete.Announcements)
                {
                    string disciplineId = incomingAnnouncement.DisciplineId;
                    if (string.IsNullOrEmpty(disciplineId))
                    {
                        throw new ArgumentNullException("Missing Announcement.DisciplineId");
                    }
                    Discipline discipline = repositorySet.Disciplines.FindDiscipline(disciplineId);
                    if (discipline == null)
                    {
                        throw new ArgumentOutOfRangeException("Unknown Announcement.DisciplineId " + disciplineId);
                    }
                    IRules disciplineRules = rulesRepository.Get(discipline.Rules);

                    if (discipline.AnnouncementsClosed)
                    {
                        throw new ArgumentOutOfRangeException("Discipline " + disciplineId + " already closed announcements");
                    }

                    if (incomingAnnouncement.Performance == null)
                    {
                        athleteModel.Announcements.RemoveAll(a => a.DisciplineId == disciplineId);
                    }
                    else
                    {
                        var newAnnouncement   = false;
                        var announcementModel = athleteModel.Announcements.FirstOrDefault(a => a.DisciplineId == disciplineId);
                        if (announcementModel == null)
                        {
                            announcementModel = new Announcement();
                            announcementModel.DisciplineId = incomingAnnouncement.DisciplineId;
                            newAnnouncement = true;
                        }

                        if (disciplineRules.HasDuration && incomingAnnouncement.Performance.Duration == null)
                        {
                            throw new ArgumentNullException("Missing Announcement.Duration for " + disciplineId);
                        }
                        if (disciplineRules.HasDepth && incomingAnnouncement.Performance.Depth == null)
                        {
                            throw new ArgumentNullException("Missing Announcement.Depth for " + disciplineId);
                        }
                        if (disciplineRules.HasDistance && incomingAnnouncement.Performance.Distance == null)
                        {
                            throw new ArgumentNullException("Missing Announcement.Distance for " + disciplineId);
                        }

                        announcementModel.ModeratorNotes = incomingAnnouncement.ModeratorNotes;
                        announcementModel.Performance    = ExtractPerformance(incomingAnnouncement.Performance);
                        if (newAnnouncement)
                        {
                            athleteModel.Announcements.Add(announcementModel);
                        }
                    }
                }
            }

            repositorySet.Athletes.SaveAthlete(athleteModel);
        }
示例#4
0
 public ActionResult <ManagementRule> Get(int id) => _rulesRepository.Get(id);