public void CalculateHoleStatistics(int month, int year)
        {
            Check.Argument.IsNotZeroOrNegative(month, "month");
            Check.Argument.IsNotZeroOrNegative(year, "year");

            DeleteHoleStatistics(month, year);

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

            foreach (var hole in holes)
            {
                var holeShots = shots.Where(s => s.Hole.Id == hole.Id);

                if (holeShots.Any())
                {
                    var holeStatistics = new HoleStatistics() { Hole = hole, Month = month, Year = year };

                    holeStatistics.ShotsMade = holeShots.Count(s => s.ShotMade);
                    holeStatistics.Attempts = holeShots.Sum(s => s.Attempts);
                    holeStatistics.ShootingPercentage = Decimal.Round((decimal)holeStatistics.ShotsMade / (decimal)holeStatistics.Attempts, 3, MidpointRounding.AwayFromZero);
                    holeStatistics.PointsScored = holeShots.Sum(s => s.Points);
                    holeStatistics.Pushes = holeShots.Count(s => s.ShotType.Id == 3);
                    holeStatistics.Steals = holeShots.Count(s => s.ShotType.Id == 4);
                    holeStatistics.SugarFreeSteals = holeShots.Count(s => s.ShotType.Id == 5);

                    _holeStatisticsRepository.Add(holeStatistics);
                }
            }
        }
        public void CalculateHoleStatistics(int month, int year)
        {
            Check.Argument.IsNotZeroOrNegative(month, "month");
            Check.Argument.IsNotZeroOrNegative(year, "year");

            DeleteHoleStatistics(month, year);

            var holes = _holeRepository.All();

            foreach (var hole in holes)
            {
                var holeShots = hole.Shots.Where(s => s.Game.Date.Month == month && s.Game.Date.Year == year && s.Hole.Id == hole.Id);

                var holeStatistics = new HoleStatistics() { Hole = hole, Month = month, Year = year };

                if (holeShots.Any())
                {
                    holeStatistics.ShotsMade = holeShots.Count(s => s.ShotMade);
                    holeStatistics.Attempts = holeShots.Sum(s => s.Attempts);
                    holeStatistics.ShootingPercentage = Decimal.Round(Convert.ToDecimal(holeStatistics.ShotsMade) / Convert.ToDecimal(holeStatistics.Attempts), 3, MidpointRounding.AwayFromZero);
                    holeStatistics.PointsScored = holeShots.Sum(s => s.Points);
                    holeStatistics.Pushes = holeShots.Count(s => s.ShotType.Id == 3);
                    holeStatistics.Steals = holeShots.Count(s => s.ShotType.Id == 4);
                    holeStatistics.SugarFreeSteals = holeShots.Count(s => s.ShotType.Id == 5);
                }

                _holeStatisticsRepository.Add(holeStatistics);
            }

            _unitOfWork.Commit();
        }
 public void Delete(HoleStatistics model)
 {
     using (var context = new BolfTrackerContext())
     {
         context.HoleStatistics.Remove(model);
         context.SaveChanges();
     }
 }
 public void Add(HoleStatistics model)
 {
     using (var context = new BolfTrackerContext())
     {
         context.HoleStatistics.Attach(model);
         context.Entry(model).State = EntityState.Added;
         context.SaveChanges();
     }
 }