public async Task <HttpResponseMessage> PutMatchup(int weekId, int matchupId, TeamMatchupWithMatches teamMatchup) { if (teamMatchup.Id != matchupId) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var databaseTeamMatchup = await this.Db.teammatchups.Include(y => y.week).Include("week.year").FirstOrDefaultAsync(x => x.id == teamMatchup.Id); if (databaseTeamMatchup == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new { errors = new string[] { "Couldn't find requested teammatchup." } })); } ScoreEntry scoreEntry = new ScoreEntry(teamMatchup, databaseTeamMatchup.week); if (!scoreEntry.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new { errors = scoreEntry.Errors })); } teammatchup persistedTeamMatchup = null; try { persistedTeamMatchup = await scoreEntry.SaveScoresAsync(this.Db); } catch (Exception e) { Logger.Error(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, new { errors = new string[] { "There was an error saving scores/matches. " + e.Message } })); } try { if (scoreEntry.ShouldCalculateLeaderBoards(persistedTeamMatchup)) { var lbc = new PostScoreEntryProcessor(this.Db, persistedTeamMatchup.id); lbc.Execute(); } } catch (Exception e) { Logger.Error(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, new { errors = new string[] { "There was an error saving handicaps and leaderboards. " + e.Message } })); } return(Request.CreateResponse(HttpStatusCode.OK)); }