public RoundAddViewModel(HandicapStatusViewModel handicapStatus, IList<Navigation.BreadcrumbNavItem> breadcrumb, IEnumerable<SelectListItem> stateListing, AntiforgeryTokenSet tokenSet, RoundAddEnteredData roundEnteredData) { HandicapStatus = handicapStatus; Breadcrumb = breadcrumb; StateListing = stateListing; TokenSet = tokenSet; RoundEnteredData = roundEnteredData; }
public static async Task<int> SaveRound(ToracGolfContext dbContext, int userId, int seasonId, RoundAddEnteredData roundData) { //build the round record var round = new Round { CourseId = roundData.CourseId, CourseTeeLocationId = roundData.TeeLocationId, RoundDate = roundData.RoundDate, Is9HoleScore = roundData.NineHoleScore, Score = roundData.Score.Value, UserId = userId, SeasonId = seasonId, GreensInRegulation = roundData.GreensInRegulation, Putts = roundData.Putts, FairwaysHit = roundData.FairwaysHit }; //go grab the tee location var teeLocation = await dbContext.CourseTeeLocations.AsNoTracking().FirstAsync(x => x.CourseTeeLocationId == roundData.TeeLocationId).ConfigureAwait(false); //add the round handicap now round.RoundHandicap = Handicapper.CalculateHandicap(new Last20Rounds[] { new Last20Rounds { Rating = teeLocation.Rating, Slope = teeLocation.Slope, RoundScore = round.Score } }).Value; //add the round dbContext.Rounds.Add(round); //save the round //await dbContext.SaveChangesAsync(); dbContext.SaveChanges(); //we need to go add the handicap records await RefreshHandicapRecords(dbContext, userId); //return the round id return round.RoundId; }