public async Task <IActionResult> RegisterAthlete([FromBody] Athlete athlete) { var response = new SingleModelResponse <Athlete>() as ISingleModelResponse <Athlete>; var listResponse = new ListModelResponse <Athlete>() as IListModelResponse <Athlete>; try { if (athlete == null) { throw new Exception("Model is missing"); } listResponse.Model = await Task.Run(() => { return(_context.GetAthletes()); }); foreach (Athlete existing in listResponse.Model) { if (existing.EmailAddress == athlete.EmailAddress) { throw new Exception("Email address already in use."); } if (existing.UserName == athlete.UserName) { throw new Exception("Username is already in use."); } } response.Model = await Task.Run(() => { return(_context.RegisterAthlete(athlete)); }); } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.Message; } return(response.ToHttpResponse()); }