Exemple #1
0
        public HttpResponseMessage Get(int routeId, int userId, string s)
        {
            if (CompetitionDB.TblJudgesPapersClimb.FirstOrDefault(x => x.ClimberId == userId && x.RouteId == routeId) != null)
            {
                JudgesPaperClimbModel paper = CompetitionDB.TblJudgesPapersClimb.ToArray().Where(x => x.ClimberId == userId && x.RouteId == routeId).Select(x => new JudgesPaperClimbModel(x)).FirstOrDefault();

                //paper.Climber = CompetitionDB.TblUsers.FirstOrDefault(x => x.Id == paper.ClimberId).Name + CompetitionDB.TblUsers.FirstOrDefault(x => x.Id == paper.ClimberId).LastName;
                // paper.RouteNumber = CompetitionDB.TblRoutesClim.FirstOrDefault(x => x.Id == paper.RouteId).Number;

                return(ToJsonOK(paper));
            }

            return(ToJsonNotFound("Objektas nerastas."));
        }
        /** LAIPIOJIMO VARŽYBŲ KABORIŲ TIPO rezultatų skaičiavimo algoritmas*/
        public List <ResultsClimbKaboriai> KaboriaiResults(int compId, int resultType, string lytis)
        {
            //PRIDĖTI RŪŠIAVIMĄ PAGAL LYTĮ
            List <ResultsClimbKaboriai> results = new List <ResultsClimbKaboriai>();

            foreach (CompetitorsClimModel u in CompetitionDB.TblCompetitorsClim.ToArray().Where(x => x.CompetitionId == compId).Select(x => new CompetitorsClimModel(x)).ToList())
            {
                ResultsClimbKaboriai r = new ResultsClimbKaboriai();
                if (lytis == CompetitionDB.TblUsers.Find(u.ClimberId).Lytis)
                {
                    r.Climber = CompetitionDB.TblUsers.Find(u.ClimberId).Name + " " + CompetitionDB.TblUsers.Find(u.ClimberId).LastName;
                    int ClimberId = u.ClimberId;

                    foreach (RouteClimbModel route in CompetitionDB.TblRoutesClim.ToArray().Where(x => x.CompetitionId == compId).Select(x => new RouteClimbModel(x)).ToList())
                    {
                        /*  if(CompetitionDB.TblJudgesPapersClimb.First(x => x.RouteId == RouteId && x.ClimberId == ClimberId).ToString().Length != 0)
                         * {*/
                        JudgesPaperClimbModel paper = new JudgesPaperClimbModel(CompetitionDB.TblJudgesPapersClimb.First(x => x.RouteId == route.Id && x.ClimberId == ClimberId));
                        if (paper.TopAttempt == 1)
                        {
                            r.RoutePonts[route.Id - 1] = CompetitionDB.TblRoutesClim.Find(route.Id).PointsFlash;
                            r.PlusPoints(CompetitionDB.TblRoutesClim.Find(route.Id).PointsFlash);
                        }
                        else if (paper.TopAttempt == 2)
                        {
                            r.RoutePonts[route.Id - 1] = CompetitionDB.TblRoutesClim.Find(route.Id).PointsTop;
                            r.PlusPoints(CompetitionDB.TblRoutesClim.Find(route.Id).PointsTop);
                        }
                        else if (paper.BonusAttempt > 0)
                        {
                            r.RoutePonts[route.Id - 1] = CompetitionDB.TblRoutesClim.Find(route.Id).PointsBonus;
                            r.PlusPoints(CompetitionDB.TblRoutesClim.Find(route.Id).PointsBonus);
                        }
                        //}
                    }
                    results.Add(r);
                }
            }
            List <ResultsClimbKaboriai> resultsOrder = results.OrderByDescending(x => x.SumPoints).ToList();
            int p = 1;

            foreach (ResultsClimbKaboriai res in resultsOrder)
            {
                res.Place = p;
                p++;
            }

            return(resultsOrder);
        }
        /** LAIPIOJIMO VARŽYBŲ LBČ TIPO rezultatų skaičiavimo algoritmas*/
        public List <ResultsClimLBC> LBCResults(int compId, int resultType, string lytis)
        {
            //PRIDĖTI RŪŠIAVIMĄ PAGAL LYTĮ
            List <ResultsClimLBC> results = new List <ResultsClimLBC>();

            foreach (CompetitorsClimModel u in CompetitionDB.TblCompetitorsClim.ToArray().Where(x => x.CompetitionId == compId).Select(x => new CompetitorsClimModel(x)).ToList())
            {
                if (lytis == CompetitionDB.TblUsers.Find(u.ClimberId).Lytis)
                {
                    ResultsClimLBC r = new ResultsClimLBC();
                    r.Climber = CompetitionDB.TblUsers.Find(u.ClimberId).Name + " " + CompetitionDB.TblUsers.Find(u.ClimberId).LastName;
                    int ClimberId = u.ClimberId;

                    foreach (RouteClimbModel route in CompetitionDB.TblRoutesClim.ToArray().Where(x => x.CompetitionId == compId).Select(x => new RouteClimbModel(x)).ToList())
                    {
                        JudgesPaperClimbModel paper = new JudgesPaperClimbModel(CompetitionDB.TblJudgesPapersClimb.First(x => x.RouteId == route.Id && x.ClimberId == ClimberId));
                        if (paper.TopAttempt == 1)
                        {
                            r.PlusFlash();
                            r.PlusTop();
                            r.PlusBonus();
                        }
                        else if (paper.TopAttempt == 2)
                        {
                            r.PlusTop();
                            r.PlusBonus();
                        }
                        else if (paper.BonusAttempt > 0)
                        {
                            r.PlusBonus();
                        }
                    }
                    results.Add(r);
                }
            }
            List <ResultsClimLBC> resultsOrder = results.OrderByDescending(x => x.SumAttemptFlash).ThenByDescending(x => x.SumAttemptTop).ThenByDescending(x => x.SumAttemptBonus).ToList();
            int p = 1;

            foreach (ResultsClimLBC res in resultsOrder)
            {
                res.Place = p;
                p++;
            }

            return(resultsOrder);
        }
        /** LAIPIOJIMO VARŽYBŲ LBJT rezultatų skaičiavimo algoritmas*/
        public List <ResultsClim> ResultsClim(int compId, int resultType, string lytis, string group)
        {
            //PRIDĖTI RŪŠIAVIMĄ PAGAL LYTĮ
            List <ResultsClim> results = new List <ResultsClim>();

            foreach (CompetitorsClimModel u in CompetitionDB.TblCompetitorsClim.ToArray().Where(x => x.CompetitionId == compId && x.Group == group).Select(x => new CompetitorsClimModel(x)).ToList())
            {
                ResultsClim r = new ResultsClim();
                if (lytis == CompetitionDB.TblUsers.Find(u.ClimberId).Lytis)
                {
                    r.Climber = CompetitionDB.TblUsers.Find(u.ClimberId).Name + " " + CompetitionDB.TblUsers.Find(u.ClimberId).LastName;
                    int ClimberId = u.ClimberId;

                    // PAKEISTI PO TO Į 5, NES 4 TRASŲ ATRANKOJE
                    foreach (RouteClimbModel route in CompetitionDB.TblRoutesClim.ToArray().Where(x => x.CompetitionId == compId && x.Type == group).Select(x => new RouteClimbModel(x)).ToList())
                    {
                        JudgesPaperClimbModel paper = new JudgesPaperClimbModel(CompetitionDB.TblJudgesPapersClimb.First(x => x.RouteId == route.Id && x.ClimberId == ClimberId));
                        if (paper.TopAttempt > 0)
                        {
                            r.AddTop(paper.TopAttempt);
                        }

                        if (paper.BonusAttempt > 0)
                        {
                            r.AddBonus(paper.BonusAttempt);
                        }
                        //}
                    }
                    results.Add(r);
                }
            }
            List <ResultsClim> resultsOrder = results.OrderByDescending(x => x.TopNumber).ThenByDescending(x => x.BonusNumber).ThenBy(x => x.TopAttempt).ThenBy(x => x.BonusAttempt).ToList();
            int p = 1;

            foreach (ResultsClim res in resultsOrder)
            {
                res.Place = p;
                p++;
            }

            return(resultsOrder);
        }