Esempio n. 1
0
        public List <ScoreInfo> getForTour(int TourId)
        {
            List <ScoreInfo> ScoreInfos = new List <ScoreInfo>();

            if (TourId > 0)
            {
                Tour Tour = _tourInfo.getTour(TourId);
                if (Tour != null)
                {
                    var TourType   = Tour.TourType;
                    var ScorerType = Tour.ScorerType;
                    if (ScorerType.ToString().Contains("Ryder"))
                    {
                        var Scores = _context.Score.Where(r => r.TourEvent && r.TourId == TourId).OrderBy(r => r.MatchGrp).ThenBy(r => r.MatchPlayerNum);
                        foreach (Score score in Scores)
                        {
                            Member member = _context.Member.FirstOrDefault(r => r.MemberId == score.MemberId);
                            Course course = _context.Course.FirstOrDefault(r => r.CourseId == score.CourseId);

                            ScoreInfo scoreInfo = new ScoreInfo(member, course, score);

                            ScoreInfos.Add(scoreInfo);
                        }
                    }
                    else
                    {
                        if (TourType == TourType.SingleDay)
                        {
                            var Scores = _context.Score.Where(r => r.TourEvent && r.TourId == TourId).OrderByDescending(r => r.ScoreDate).ThenBy(i => i.TourScore).ThenBy(i => i.Tiebreaker);
                            foreach (Score score in Scores)
                            {
                                Member member = _context.Member.FirstOrDefault(r => r.MemberId == score.MemberId);
                                Course course = _context.Course.FirstOrDefault(r => r.CourseId == score.CourseId);

                                ScoreInfo scoreInfo = new ScoreInfo(member, course, score);

                                ScoreInfos.Add(scoreInfo);
                            }
                        }
                        else
                        {
                            var TourDays = _context.TourDay.Where(r => r.TourId == Tour.TourId).OrderByDescending(r => r.TourDate);
                            foreach (TourDay TourDay in TourDays)
                            {
                                var Scores = _context.Score.Where(r => r.TourEvent && r.ScoreDate.Date == TourDay.TourDate).OrderBy(i => i.TourScore).ThenBy(i => i.Tiebreaker);
                                foreach (Score score in Scores)
                                {
                                    Member member = _context.Member.FirstOrDefault(r => r.MemberId == score.MemberId);
                                    Course course = _context.Course.FirstOrDefault(r => r.CourseId == score.CourseId);

                                    ScoreInfo scoreInfo = new ScoreInfo(member, course, score);

                                    ScoreInfos.Add(scoreInfo);
                                }
                            }
                        }
                    }
                }
            }
            return(ScoreInfos);
        }
Esempio n. 2
0
        public async Task <IActionResult> Put(int id, [FromBody] ScoresInfo model)
        {
            try
            {
                Score Score = _context.Score.SingleOrDefault(m => m.ScoreId == id);
                //Score.CourseId = model.CourseId;
                //Score.Color = model.Color;
                //Score.ScoreDate = model.ScoreDate;
                //Score.EnteredById = model.EnteredBy.MemberId;
                Score.Hole01         = model.Hole01;
                Score.Hole02         = model.Hole02;
                Score.Hole03         = model.Hole03;
                Score.Hole04         = model.Hole04;
                Score.Hole05         = model.Hole05;
                Score.Hole06         = model.Hole06;
                Score.Hole07         = model.Hole07;
                Score.Hole08         = model.Hole08;
                Score.Hole09         = model.Hole09;
                Score.Hole10         = model.Hole10;
                Score.Hole11         = model.Hole11;
                Score.Hole12         = model.Hole12;
                Score.Hole13         = model.Hole13;
                Score.Hole14         = model.Hole14;
                Score.Hole15         = model.Hole15;
                Score.Hole16         = model.Hole16;
                Score.Hole17         = model.Hole17;
                Score.Hole18         = model.Hole18;
                Score.HoleIn         = model.HoleIn;
                Score.HoleOut        = model.HoleOut;
                Score.HoleTotal      = model.HoleTotal;
                Score.Round          = model.Round;
                Score.MatchGrp       = model.MatchGrp;
                Score.MatchPlayerNum = model.MatchPlayerNum;
                Score.MatchPoints    = model.MatchPoints;

                int holesPlayed = 0;
                if (Score.Hole01 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole02 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole03 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole04 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole05 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole06 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole07 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole08 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole09 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole10 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole11 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole12 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole13 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole14 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole15 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole16 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole17 > 0)
                {
                    holesPlayed++;
                }
                if (Score.Hole18 > 0)
                {
                    holesPlayed++;
                }

                int lastHolePlayed = 0;
                lastHolePlayed = setLastHolePlayed(lastHolePlayed, 1, model.Hole01);
                lastHolePlayed = setLastHolePlayed(lastHolePlayed, 2, model.Hole02);
                lastHolePlayed = setLastHolePlayed(lastHolePlayed, 3, model.Hole03);
                lastHolePlayed = setLastHolePlayed(lastHolePlayed, 4, model.Hole04);
                lastHolePlayed = setLastHolePlayed(lastHolePlayed, 5, model.Hole05);
                lastHolePlayed = setLastHolePlayed(lastHolePlayed, 6, model.Hole06);
                lastHolePlayed = setLastHolePlayed(lastHolePlayed, 7, model.Hole07);
                lastHolePlayed = setLastHolePlayed(lastHolePlayed, 8, model.Hole08);
                lastHolePlayed = setLastHolePlayed(lastHolePlayed, 9, model.Hole09);
                if (lastHolePlayed == 0 || lastHolePlayed >= 9)
                {
                    lastHolePlayed = setLastHolePlayed(lastHolePlayed, 10, model.Hole10);
                    lastHolePlayed = setLastHolePlayed(lastHolePlayed, 11, model.Hole11);
                    lastHolePlayed = setLastHolePlayed(lastHolePlayed, 12, model.Hole12);
                    lastHolePlayed = setLastHolePlayed(lastHolePlayed, 13, model.Hole13);
                    lastHolePlayed = setLastHolePlayed(lastHolePlayed, 14, model.Hole14);
                    lastHolePlayed = setLastHolePlayed(lastHolePlayed, 15, model.Hole15);
                    lastHolePlayed = setLastHolePlayed(lastHolePlayed, 16, model.Hole16);
                    lastHolePlayed = setLastHolePlayed(lastHolePlayed, 17, model.Hole17);
                    lastHolePlayed = setLastHolePlayed(lastHolePlayed, 18, model.Hole18);
                }
                Score.LastHolePlayed = lastHolePlayed;

                //Score.TourEvent = model.TourEvent;
                //Score.TourId = model.TourId;
                //if (model.AboutGame == null) model.AboutGame = "";
                //Score.AboutGame = model.AboutGame;

                Score.NetScore  = 199;
                Score.TourScore = 199;
                float HcpAllowPct = 100.0F;
                float MultiAdj    = 0.0F;
                Tour  Tour;


                Handicap     Handicap     = _handicap.getHandicapForDate(Score.MemberId, Score.ScoreDate);
                CourseDetail CourseDetail = _courseDetail.get(Score.CourseId, Score.Color);
                Course       Course       = _courseData.get(Score.CourseId);

                if (Score.TourEvent == true && (Tour = _tourInfo.getTour(Score.TourId)) != null)
                {
                    HcpAllowPct = Tour.HcpAllowPct;
                    if (Tour.AllowMultiTee == true)
                    {
                        CourseDetail BaseCourse = _courseDetail.get(Course.CourseId, Tour.BaseColor.ToString());
                        MultiAdj = (float)(BaseCourse.Rating - CourseDetail.Rating);
                    }
                }

                if (Handicap != null && Handicap.HcpIndex > 0)
                {
                    float courseHandicap  = Handicap.HcpIndex * CourseDetail.Slope / 113;
                    float courseHandicapT = (Handicap.HcpIndex * CourseDetail.Slope / 113 - MultiAdj) * (HcpAllowPct / 100);
                    Score.NetScore  = (int)Math.Round(model.HoleTotal - courseHandicap * holesPlayed / 18.0);
                    Score.TourScore = (int)Math.Round(model.HoleTotal - courseHandicapT * holesPlayed / 18.0);
                }
                else
                {
                    float courseHandicap  = getS36Hcp(Score, Course) * CourseDetail.Slope / 113;
                    float courseHandicapT = getS36Hcp(Score, Course) * (HcpAllowPct / 100) * CourseDetail.Slope / 113;
                    Score.NetScore  = (int)Math.Round(model.HoleTotal - courseHandicap * holesPlayed / 18.0);
                    Score.TourScore = (int)Math.Round(model.HoleTotal - courseHandicapT * holesPlayed / 18.0);
                }

                countScores(Score, Course);
                Score.Tiebreaker = _scoreInfo.getTiebreaker(Score);

                //Score.LastUpdatedBy = User.Identity.Name;
                Score.LastUpdatedBy = "Live Score";
                Score.LastUpdatedTs = DateTime.Now;


                _context.Update(Score);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ScoreExists(model.ScoreId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok());
        }