Esempio n. 1
0
        public IActionResult UpgradeAthleteStatus(long id)
        {
            try
            {
                Athlete athlete = athleteRepository.GetById(id);
                if (athlete == null)
                {
                    return(BadRequest("Invalid athlete Id: " + id));
                }

                if (athlete.Status == AthleteStatusType.Advanced && (athlete.StatusExpirationDate == null || athlete.StatusExpirationDate.Value < DateTime.UtcNow))
                {
                    return(BadRequest("The athlete already has the Advanced status"));
                }

                bool success = athleteService.UpgradeAthleteStatus(athlete);
                if (!success)
                {
                    return(BadRequest("Cannot upgrade the athlete"));
                }

                athleteRepository.SaveChanges();

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, new { error = e.Message }));
            }
        }