Example #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.IsAdvanced)
                {
                    return(BadRequest("The athlete already has the Advanced status"));
                }

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

                athleteRepository.SaveChanges();

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