public void Delete(Hole model) { using (var context = new BolfTrackerContext()) { context.Holes.Remove(model); context.SaveChanges(); } }
public void Add(Hole model) { using (var context = new BolfTrackerContext()) { context.Holes.Attach(model); context.Entry(model).State = EntityState.Added; context.SaveChanges(); } }
public Hole CreateHole(int holeNumber, int par) { Check.Argument.IsNotZeroOrNegative(holeNumber, "holeNumber"); Check.Argument.IsNotZeroOrNegative(par, "par"); var hole = new Hole() { Id = holeNumber, Par = par }; _holeRepository.Add(hole); return hole; }
public static PlayerRivalryStatistics CreatePlayerRivalryStatistics(Game game, Player player, Player affectedPlayer, Hole hole, ShotType shotType) { return new PlayerRivalryStatistics { Game = game, Player = player, AffectedPlayer = affectedPlayer, Hole = hole, ShotType = shotType, Attempts = 10, Points = 5 }; }
public static HoleStatistics CreateHoleStatistics(Hole hole) { return new HoleStatistics { Hole = hole, Month = DateTime.Today.Month, Year = DateTime.Today.Year, Attempts = 10, ShotsMade = 5, ShootingPercentage = .500M, PointsScored = 12, Pushes = 3, Steals = 2, SugarFreeSteals = 1 }; }
public static Shot CreateShot(Game game, Player player, ShotType shotType, Hole hole) { return new Shot { Game = game, Player = player, ShotType = shotType, Hole = hole, ShotMade = true, Attempts = 1, Points = 10 }; }
public HoleResult GetHoleResult(Hole hole) { HoleResult result = new HoleResult(); if (hole.Shots != null && hole.Shots.Any()) { result.IsEmpty = false; //Get the last shot var shot = hole.Shots.FirstOrDefault(s => s.ShotMade == true || s.ShotType.Id == 3); //If it was made, see if it was a push, steal if (shot != null && shot.ShotMade == true) { result.Shot = shot; result.LastPlayer = shot.Player; //If a push switch (shot.ShotType.Id) { case 1 : result.FirstPlayer = null; result.Points = hole.Par; break; case 3 : var pushedShot = hole.Shots.FirstOrDefault(s => s.Attempts == shot.Attempts && s.Id != shot.Id && s.ShotMade == true); result.FirstPlayer = pushedShot.Player; break; case 4 : var stolenShot = hole.Shots.LastOrDefault(s => s.Attempts > shot.Attempts && s.ShotMade == true); result.FirstPlayer = stolenShot.Player; result.Points = hole.Par; break; //Try and find the players who pushed the hole case 5 : var lastPushedShot = hole.Shots.LastOrDefault(s => s.ShotMade == true && s.Attempts > shot.Attempts); var firstPushedShot = hole.Shots.LastOrDefault(s => s.ShotMade == true && s.Attempts == lastPushedShot.Attempts && s.Id != lastPushedShot.Id); result.FirstPlayer = new Player() { Initials = lastPushedShot.Player.Initials + "/" + firstPushedShot.Player.Initials }; result.Points = hole.Par; break; default : result.FirstPlayer = null; break; } if (result.Points > 0) { //loop through previous holes adding up score until last winning shot. for (int i = hole.Id - 1; i > 0; i--) { var previousHole = Holes.FirstOrDefault(h => h.Id == i); //Check for push if ((previousHole.Shots.Count(s => s.ShotMade == true && s.ShotType.Id == 3) > 0) || previousHole.Shots.Count(s => s.ShotMade == true) == 0) { result.Points += previousHole.Par; } else { break; } } } } } return result; }