public HttpResponseMessage Add(HttpRequestMessage request, AthleteDto athleteDto)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newAthleteDto = _athletesRepository.Add(athleteDto);
                    response = request.CreateResponse(HttpStatusCode.Created, newAthleteDto);
                }

                return response;
            });
        }
        public AthleteDto GetSingle(int athleteId)
        {
            var athlete = _context.Athletes.Single(x => x.Id == athleteId);

            var athleteDto = new AthleteDto()
            {
                Id = athlete.Id,
                FirstName = athlete.FirstName,
                LastName = athlete.LastName,
                Email = athlete.Email,
                RegistrationDate = DateTime.Now,
                Image = athlete.Image ?? "unknown.jpg",
                LactateThreshold = athlete.LactateThreshold,
                FunctionalThresholdPower = athlete.FunctionalThresholdPower,
                Weight = athlete.Weight,
                UniqueKey = athlete.UniqueKey
            };

            return athleteDto;
        }
        public AthleteDto Add(AthleteDto athleteDto)
        {
            var athlete = new Athlete()
            {
                Username = athleteDto.Username,
                FirstName = athleteDto.FirstName,
                LastName = athleteDto.LastName,
                Email = athleteDto.Email,
                RegistrationDate = DateTime.Now,
                Image = athleteDto.Image ?? "unknown.jpg",
                LactateThreshold = Math.Round(athleteDto.LactateThreshold, 2, MidpointRounding.AwayFromZero),
                FunctionalThresholdPower = Math.Round(athleteDto.FunctionalThresholdPower, 2, MidpointRounding.AwayFromZero),
                Weight = Math.Round(athleteDto.Weight, 2, MidpointRounding.AwayFromZero),
                UniqueKey = Guid.NewGuid()
            };

            _context.Athletes.Add(athlete);

            _context.SaveChanges();
    
            var newAthleteDto = new AthleteDto()
            {
                Id = athlete.Id,
                FirstName = athleteDto.FirstName,
                LastName = athleteDto.LastName,
                Email = athleteDto.Email,
                RegistrationDate = DateTime.Now,
                Image = athleteDto.Image ?? "unknown.jpg",
                LactateThreshold = athleteDto.LactateThreshold,
                FunctionalThresholdPower = athleteDto.FunctionalThresholdPower,
                Weight = athleteDto.Weight,
                UniqueKey = Guid.NewGuid()
            };

            return newAthleteDto;
        }
        public AthleteDto Edit(AthleteDto athleteDto)
        {
            var athlete = _context.Athletes.Single(x => x.Id == athleteDto.Id);

            athlete.FirstName = athleteDto.FirstName;
            athlete.LastName = athleteDto.LastName;
            athlete.Image = athleteDto.Image ?? "unknown.jpg";
            athlete.LactateThreshold = Math.Round(athleteDto.LactateThreshold, 2, MidpointRounding.AwayFromZero);
            athlete.FunctionalThresholdPower = Math.Round(athleteDto.FunctionalThresholdPower, 2, MidpointRounding.AwayFromZero);
            athlete.Weight = Math.Round(athleteDto.Weight, 2, MidpointRounding.AwayFromZero);
            athlete.Email = athleteDto.Email;

            _context.SaveChanges();

            var newAthleteDto = new AthleteDto()
            {
                Id = athlete.Id,
                FirstName = athlete.FirstName,
                LastName = athlete.LastName,
                Email = athlete.Email,
                RegistrationDate = DateTime.Now,
                Image = athlete.Image ?? "unknown.jpg",
                LactateThreshold = athlete.LactateThreshold,
                FunctionalThresholdPower = athlete.LactateThreshold,
                Weight = athlete.Weight,
                UniqueKey = athlete.UniqueKey
            };

            return newAthleteDto; 
        }
        public HttpResponseMessage Update(HttpRequestMessage request, AthleteDto athleteDto)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    _athletesRepository.Edit(athleteDto);
                    response = request.CreateResponse(HttpStatusCode.OK, athleteDto);
                }

                return response;
            });
        }