public void Delete(PlayerHoleStatistics model)
 {
     using (var context = new BolfTrackerContext())
     {
         context.PlayerHoleStatistics.Remove(model);
         context.SaveChanges();
     }
 }
 public void Add(PlayerHoleStatistics model)
 {
     using (var context = new BolfTrackerContext())
     {
         context.PlayerHoleStatistics.Attach(model);
         context.Entry(model).State = EntityState.Added;
         context.SaveChanges();
     }
 }
Пример #3
0
        public void CalculatePlayerHoleStatistics(int month, int year)
        {
            Check.Argument.IsNotZeroOrNegative(month, "month");
            Check.Argument.IsNotZeroOrNegative(year, "year");

            DeletePlayerHoleStatistics(month, year);

            var players = _playerRepository.All().ToList();
            var shots = _shotRepository.GetByMonthAndYear(month, year);
            var holes = _holeRepository.All().ToList();

            foreach (var player in players)
            {
                var playerShots = shots.Where(s => s.Player.Id == player.Id);

                if (playerShots.Any())
                {
                    foreach (var hole in holes)
                    {
                        var playerHoleShots = playerShots.Where(s => s.Hole.Id == hole.Id);

                        if (playerHoleShots.Any())
                        {
                            var playerHoleStatistics = new PlayerHoleStatistics() { Player = player, Hole = hole, Month = month, Year = year };

                            playerHoleStatistics.ShotsMade = playerHoleShots.Count(s => s.ShotMade);
                            playerHoleStatistics.Attempts = playerHoleShots.Sum(s => s.Attempts);
                            playerHoleStatistics.ShootingPercentage = Decimal.Round((decimal)playerHoleStatistics.ShotsMade / (decimal)playerHoleStatistics.Attempts, 3, MidpointRounding.AwayFromZero);
                            playerHoleStatistics.PointsScored = playerHoleShots.Where(s => s.ShotType.Id != ShotTypePush).Sum(s => s.Points);
                            playerHoleStatistics.Pushes = playerHoleShots.Count(s => s.ShotType.Id == ShotTypePush);
                            playerHoleStatistics.Steals = playerHoleShots.Count(s => s.ShotType.Id == ShotTypeSteal);
                            playerHoleStatistics.SugarFreeSteals = playerHoleShots.Count(s => s.ShotType.Id == ShotTypeSugarFreeSteal);

                            _playerHoleStatisticsRepository.Add(playerHoleStatistics);
                        }
                    }
                }
            }
        }
Пример #4
0
        public void CalculatePlayerHoleStatistics(int month, int year)
        {
            Check.Argument.IsNotZeroOrNegative(month, "month");
            Check.Argument.IsNotZeroOrNegative(year, "year");

            DeletePlayerHoleStatistics(month, year);

            var players = _playerRepository.All();

            foreach (var player in players)
            {
                if (player.Shots.Any(s => s.Game.Date.Month == month && s.Game.Date.Year == year))
                {
                    var holes = _holeRepository.All();

                    foreach (var hole in holes)
                    {
                        var playerHoleShots = player.Shots.Where(s => s.Hole.Id == hole.Id && s.Game.Date.Month == month && s.Game.Date.Year == year);
                        var playerHoleStatistics = new PlayerHoleStatistics() { Player = player, Hole = hole, Month = month, Year = year };

                        if (playerHoleShots.Any())
                        {
                            playerHoleStatistics.ShotsMade = playerHoleShots.Count(s => s.ShotMade);
                            playerHoleStatistics.Attempts = playerHoleShots.Sum(s => s.Attempts);
                            playerHoleStatistics.ShootingPercentage = Decimal.Round(Convert.ToDecimal(playerHoleStatistics.ShotsMade) / Convert.ToDecimal(playerHoleStatistics.Attempts), 3, MidpointRounding.AwayFromZero);
                            playerHoleStatistics.PointsScored = playerHoleShots.Sum(s => s.Points);
                            playerHoleStatistics.Pushes = playerHoleShots.Count(s => s.ShotType.Id == ShotTypePush);
                            playerHoleStatistics.Steals = playerHoleShots.Count(s => s.ShotType.Id == ShotTypeSteal);
                            playerHoleStatistics.SugarFreeSteals = playerHoleShots.Count(s => s.ShotType.Id == ShotTypeSugarFreeSteal);
                        }

                        _playerHoleStatisticsRepository.Add(playerHoleStatistics);
                    }
                }
            }

            _unitOfWork.Commit();
        }