Exemple #1
0
 public static AthleteProfile BuildProfile(Models.Athlete model)
 {
     return(new AthleteProfile
     {
         AthleteId = model.AthleteId,
         Category = model.Category,
         Club = model.Club,
         CountryName = model.CountryName,
         FirstName = model.FirstName,
         Sex = model.Sex.ToString(),
         ModeratorNotes = model.ModeratorNotes,
         ProfilePhotoName = model.ProfilePhotoName,
         Surname = model.Surname,
     });
 }
Exemple #2
0
            private ResultsListReportEntrySubresult BuildSingleSubresult(Models.Athlete athlete)
            {
                var disciplineId = components[0].Discipline.DisciplineId;
                var announcement = athlete.Announcements.FirstOrDefault(a => a.DisciplineId == disciplineId);
                var actualResult = athlete.ActualResults.LastOrDefault(a => a.DisciplineId == disciplineId);

                var subresult = new ResultsListReportEntrySubresult();

                if (allowAnnouncements)
                {
                    subresult.Announcement = BuildReportAnnouncement(announcement);
                }
                if (allowResults)
                {
                    subresult.CurrentResult = BuildReportActualResult(actualResult, null);
                    subresult.FinalPoints   = components[0].CalculateFinalPoints(actualResult);
                }
                return(subresult);
            }
        public async Task <IActionResult> PutByCrewAndPosition(int id, int position, [FromBody] Athlete athlete)
        {
            if (athlete is null)
            {
                return(BadRequest());
            }

            Models.Crew crew = await _context.Crews.Include("Athletes.Athlete").FirstAsync(x => x.BroeCrewId == id);

            Models.CrewAthlete crewAthlete = crew.Athletes.FirstOrDefault(x => x.Position == position);

            bool created = false;

            if (crewAthlete == null)
            {
                Models.Athlete dbAthlete = await _context.Athletes.FirstOrDefaultAsync(x => x.MembershipNumber == athlete.MembershipNumber);

                if (dbAthlete == null)
                {
                    crew.Athletes.Add(_mapper.Map <Models.CrewAthlete>(athlete));
                    created = true;
                }
                else
                {
                    crewAthlete = new Models.CrewAthlete
                    {
                        Athlete = dbAthlete
                    };

                    crew.Athletes.Add(crewAthlete);
                    _mapper.Map(athlete, crewAthlete);
                }
            }
            else
            {
                if (crewAthlete.Athlete.MembershipNumber == athlete.MembershipNumber)
                {
                    _mapper.Map(athlete, crewAthlete);
                }
                else
                {
                    Models.Athlete dbAthlete = await _context.Athletes.FirstOrDefaultAsync(x => x.MembershipNumber == athlete.MembershipNumber);

                    crew.Athletes.Remove(crewAthlete);
                    if (dbAthlete == null)
                    {
                        crew.Athletes.Add(_mapper.Map <Models.CrewAthlete>(athlete));
                        created = true;
                    }
                    else
                    {
                        Models.CrewAthlete newCrewAthlete = new Models.CrewAthlete {
                            Athlete = dbAthlete
                        };
                        crew.Athletes.Add(newCrewAthlete);
                        _mapper.Map(athlete, newCrewAthlete);
                    }
                }
            }
            await _context.SaveChangesAsync();

            if (created)
            {
                return(CreatedAtRoute("GetByCrewAndPosition", new { id = crew.BroeCrewId, position = athlete.Position }));
            }
            else
            {
                return(NoContent());
            }
        }
Exemple #4
0
 public ResultsListReportEntrySubresult BuildSubresult(Models.Athlete athlete)
 {
     return(isSingleDiscipline ? BuildSingleSubresult(athlete) : BuildCompositeSubresult(athlete));
 }