Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
 public void Delete(HoleStatistics model)
 {
     using (var context = new BolfTrackerContext())
     {
         context.HoleStatistics.Remove(model);
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void Add(HoleStatistics model)
 {
     using (var context = new BolfTrackerContext())
     {
         context.HoleStatistics.Attach(model);
         context.Entry(model).State = EntityState.Added;
         context.SaveChanges();
     }
 }