Exemplo n.º 1
0
        private static List <string> UpdateSemiFinalists(User user, Awesome.Models.DB.Result result)
        {
            List <string> list = new List <string> {
                user.UserBet.Semifinalist1,
                user.UserBet.Semifinalist2,
                user.UserBet.Semifinalist3,
                user.UserBet.Semifinalist4
            };
            List <string> list3 = new List <string> {
                result.Semifinalist1,
                result.Semifinalist2,
                result.Semifinalist3,
                result.Semifinalist4
            };
            List <string> list2 = new List <string>();

            foreach (string str in list3)
            {
                foreach (string str2 in list)
                {
                    if ((str2 != null) && (str2 == str))
                    {
                        list2.Add(str2);
                    }
                }
            }
            return(list2);
        }
Exemplo n.º 2
0
        public ActionResult ReportResult(AdminViewModel viewModel)
        {
            Result result = new Result();

            foreach (var r in viewModel.ReportedResult.Matches)
            {
                MatchResult match = new MatchResult()
                {
                    HomeTeam      = r.HomeTeam,
                    AwayTeam      = r.AwayTeam,
                    HomeScore     = r.HomeScore,
                    AwayScore     = r.AwayScore,
                    MatchResultId = r.MatchId,
                    Status        = r.Status
                };

                result.MatchResults.Add(match);
                result.Finalist1        = viewModel.ReportedResult.Finalist1;
                result.Finalist2        = viewModel.ReportedResult.Finalist2;
                result.Semifinalist1    = viewModel.ReportedResult.Semifinalist1;
                result.Semifinalist2    = viewModel.ReportedResult.Semifinalist2;
                result.Semifinalist3    = viewModel.ReportedResult.Semifinalist3;
                result.Semifinalist4    = viewModel.ReportedResult.Semifinalist4;
                result.QuarterFinalist1 = viewModel.ReportedResult.QuarterFinalist1;
                result.QuarterFinalist2 = viewModel.ReportedResult.QuarterFinalist2;
                result.QuarterFinalist3 = viewModel.ReportedResult.QuarterFinalist3;
                result.QuarterFinalist4 = viewModel.ReportedResult.QuarterFinalist4;
                result.QuarterFinalist5 = viewModel.ReportedResult.QuarterFinalist5;
                result.QuarterFinalist6 = viewModel.ReportedResult.QuarterFinalist6;
                result.QuarterFinalist7 = viewModel.ReportedResult.QuarterFinalist7;
                result.QuarterFinalist8 = viewModel.ReportedResult.QuarterFinalist8;
                result.Qualified1       = viewModel.ReportedResult.Qualified1;
                result.Qualified2       = viewModel.ReportedResult.Qualified2;
                result.Qualified3       = viewModel.ReportedResult.Qualified3;
                result.Qualified4       = viewModel.ReportedResult.Qualified4;
                result.Qualified5       = viewModel.ReportedResult.Qualified5;
                result.Qualified6       = viewModel.ReportedResult.Qualified6;
                result.Qualified7       = viewModel.ReportedResult.Qualified7;
                result.Qualified8       = viewModel.ReportedResult.Qualified8;
                result.Qualified9       = viewModel.ReportedResult.Qualified9;
                result.Qualified10      = viewModel.ReportedResult.Qualified10;
                result.Qualified11      = viewModel.ReportedResult.Qualified11;
                result.Qualified12      = viewModel.ReportedResult.Qualified12;
                result.Qualified13      = viewModel.ReportedResult.Qualified13;
                result.Qualified14      = viewModel.ReportedResult.Qualified14;
                result.Qualified15      = viewModel.ReportedResult.Qualified15;
                result.Qualified16      = viewModel.ReportedResult.Qualified16;
                result.TopScorer        = viewModel.ReportedResult.TopScorer;
                result.TotalGoals       = viewModel.ReportedResult.TotalGoals;
            }

            UserManager.AddResult(result, true);

            ViewBag.Message       = "Resultatet uppdaterat";
            viewModel.HasReported = true;

            return(View("Index", viewModel));
        }
Exemplo n.º 3
0
        public static Result GetResult()
        {
            using (DataModel db = new DataModel())
            {
                Result result = db.Results.Include("MatchResults").FirstOrDefault();

                return(result);
            }
        }
Exemplo n.º 4
0
 public static void AddPointsToAllUsers()
 {
     Awesome.Models.DB.Result result = UserManager.GetResult();
     foreach (User user in from x in UserManager.GetUsers()
              where x.UserBet != null
              select x)
     {
         int points = 0;
         foreach (MatchResult r in from x in result.MatchResults
                  where x.Status == "FINISHED"
                  select x)
         {
             foreach (Match match in user.UserBet.Matches.Where <Match>((x => (x.HomeTeam == r.HomeTeam) && (x.AwayTeam == r.AwayTeam))))
             {
                 if ((match.HomeScore == r.HomeScore) && (match.AwayScore == r.AwayScore))
                 {
                     match.ResultColor = "green";
                     points           += 3;
                 }
                 else if ((match.HomeScore > match.AwayScore) && (r.HomeScore > r.AwayScore))
                 {
                     points++;
                     match.ResultColor = "yellow";
                 }
                 else if ((match.HomeScore < match.AwayScore) && (r.HomeScore < r.AwayScore))
                 {
                     points++;
                     match.ResultColor = "yellow";
                 }
                 else if ((match.HomeScore == match.AwayScore) && (r.HomeScore == r.AwayScore))
                 {
                     points++;
                     match.ResultColor = "yellow";
                 }
                 else
                 {
                     points           += 0;
                     match.ResultColor = "red";
                 }
                 UserManager.SetMatchColor(match, user);
             }
         }
         List <string> correctFinalists        = UpdateFinalists(user, result);
         List <string> correctSemifinalists    = UpdateSemiFinalists(user, result);
         List <string> correctQuarterfinalists = UpdateQuarterFinalists(user, result);
         List <string> correctQualified        = UpdateQualified(user, result);
         UserManager.SetFinalistsColor(user, correctFinalists, correctSemifinalists, correctQuarterfinalists, correctQualified);
         points += correctFinalists.Count * 7;
         points += correctSemifinalists.Count * 5;
         points += correctQuarterfinalists.Count * 3;
         points += correctQualified.Count * 2;
         UserManager.SaveUserTotalPoints(user, points);
     }
 }
Exemplo n.º 5
0
        private static List <string> UpdateQualified(User user, Awesome.Models.DB.Result result)
        {
            List <string> list = new List <string> {
                user.UserBet.Qualified1,
                user.UserBet.Qualified2,
                user.UserBet.Qualified3,
                user.UserBet.Qualified4,
                user.UserBet.Qualified5,
                user.UserBet.Qualified6,
                user.UserBet.Qualified7,
                user.UserBet.Qualified8,
                user.UserBet.Qualified9,
                user.UserBet.Qualified10,
                user.UserBet.Qualified11,
                user.UserBet.Qualified12,
                user.UserBet.Qualified13,
                user.UserBet.Qualified14,
                user.UserBet.Qualified15,
                user.UserBet.Qualified16,
            };
            List <string> list3 = new List <string> {
                result.Qualified1,
                result.Qualified2,
                result.Qualified3,
                result.Qualified4,
                result.Qualified5,
                result.Qualified6,
                result.Qualified7,
                result.Qualified8,
                result.Qualified9,
                result.Qualified10,
                result.Qualified11,
                result.Qualified12,
                result.Qualified13,
                result.Qualified14,
                result.Qualified15,
                result.Qualified16,
            };
            List <string> list2 = new List <string>();

            foreach (string str in list3)
            {
                foreach (string str2 in list)
                {
                    if ((str2 != null) && (str2 == str))
                    {
                        list2.Add(str2);
                    }
                }
            }
            return(list2);
        }
Exemplo n.º 6
0
 private static void CreateMatchResultTable()
 {
     Awesome.Models.DB.Result result = new Awesome.Models.DB.Result();
     foreach (Match match in TournamentUtility.CreateMatchList(new FootballApiClient().GetGroupStageMatches()))
     {
         MatchResult item = new MatchResult
         {
             HomeTeam        = match.HomeTeam,
             AwayTeam        = match.AwayTeam,
             HomeScore       = match.HomeScore,
             AwayScore       = match.AwayScore,
             MatchResultId   = match.MatchId,
             Status          = match.Status,
             ManuallyUpdated = false
         };
         result.MatchResults.Add(item);
     }
     UserManager.AddResult(result, false);
 }
Exemplo n.º 7
0
 private static void AutomaticUpdateResultsFromDb(Awesome.Models.DB.Result currentResult)
 {
     Awesome.Models.DB.Result result = new Awesome.Models.DB.Result();
     foreach (MatchResult result2 in currentResult.MatchResults)
     {
         if ((result2.Status == "FINISHED") && !result2.ManuallyUpdated)
         {
             MatchResult item = new MatchResult
             {
                 HomeTeam        = result2.HomeTeam,
                 AwayTeam        = result2.AwayTeam,
                 HomeScore       = result2.HomeScore,
                 AwayScore       = result2.AwayScore,
                 MatchResultId   = result2.MatchResultId,
                 Status          = result2.Status,
                 ManuallyUpdated = false
             };
             result.MatchResults.Add(item);
         }
     }
     UserManager.AddResult(result, false);
 }
Exemplo n.º 8
0
 public static void AutomaticUpdateResults()
 {
     Awesome.Models.DB.Result currentResult = UserManager.GetResult();
     if (currentResult == null)
     {
         CreateMatchResultTable();
     }
     else
     {
         Awesome.ApiIntegration.JsonGroupStageResult.JsonGroupStageResult groupStageMatches = new FootballApiClient().GetGroupStageMatches();
         if (groupStageMatches == null)
         {
             AutomaticUpdateResultsFromDb(currentResult);
         }
         else
         {
             Awesome.Models.DB.Result result = new Awesome.Models.DB.Result();
             foreach (Match match in TournamentUtility.CreateMatchList(groupStageMatches))
             {
                 if (match.Status == "FINISHED")
                 {
                     MatchResult item = new MatchResult
                     {
                         HomeTeam        = match.HomeTeam,
                         AwayTeam        = match.AwayTeam,
                         HomeScore       = match.HomeScore,
                         AwayScore       = match.AwayScore,
                         MatchResultId   = match.MatchId,
                         Status          = match.Status,
                         ManuallyUpdated = false
                     };
                     result.MatchResults.Add(item);
                 }
             }
             UserManager.AddResult(result, false);
         }
     }
 }
Exemplo n.º 9
0
        public static void AddResult(Result result, bool manuallyUpdate)
        {
            result.ResultId = 1;
            using (DataModel model = new DataModel())
            {
                Result result2 = model.Results.Include("MatchResults").FirstOrDefault(r => r.ResultId == result.ResultId);
                if (result2 != null)
                {
                    foreach (MatchResult newMatch in result.MatchResults)
                    {
                        foreach (var result3 in result2.MatchResults.Where(x => x.MatchResultId == newMatch.MatchResultId))
                        {
                            if (result3.ManuallyUpdated && !manuallyUpdate)
                            {
                                continue;
                            }

                            if (manuallyUpdate && ((result3.AwayScore != newMatch.AwayScore) || (result3.HomeScore != newMatch.HomeScore)))
                            {
                                result3.ManuallyUpdated = true;
                            }
                            result3.AwayScore = newMatch.AwayScore;
                            result3.AwayTeam  = newMatch.AwayTeam;
                            result3.HomeScore = newMatch.HomeScore;
                            result3.HomeTeam  = newMatch.HomeTeam;
                            result3.Status    = newMatch.Status;

                            if (result3.ManuallyUpdated)
                            {
                                result3.Status = "FINISHED";
                            }
                        }
                    }
                    if (manuallyUpdate)
                    {
                        result2.Finalist1        = result.Finalist1;
                        result2.Finalist2        = result.Finalist2;
                        result2.Semifinalist1    = result.Semifinalist1;
                        result2.Semifinalist2    = result.Semifinalist2;
                        result2.Semifinalist3    = result.Semifinalist3;
                        result2.Semifinalist4    = result.Semifinalist4;
                        result2.QuarterFinalist1 = result.QuarterFinalist1;
                        result2.QuarterFinalist2 = result.QuarterFinalist2;
                        result2.QuarterFinalist3 = result.QuarterFinalist3;
                        result2.QuarterFinalist4 = result.QuarterFinalist4;
                        result2.QuarterFinalist5 = result.QuarterFinalist5;
                        result2.QuarterFinalist6 = result.QuarterFinalist6;
                        result2.QuarterFinalist7 = result.QuarterFinalist7;
                        result2.QuarterFinalist8 = result.QuarterFinalist8;
                        result2.Qualified1       = result.Qualified1;
                        result2.Qualified2       = result.Qualified2;
                        result2.Qualified3       = result.Qualified3;
                        result2.Qualified4       = result.Qualified4;
                        result2.Qualified5       = result.Qualified5;
                        result2.Qualified6       = result.Qualified6;
                        result2.Qualified7       = result.Qualified7;
                        result2.Qualified8       = result.Qualified8;
                        result2.Qualified9       = result.Qualified9;
                        result2.Qualified10      = result.Qualified10;
                        result2.Qualified11      = result.Qualified11;
                        result2.Qualified12      = result.Qualified12;
                        result2.Qualified13      = result.Qualified13;
                        result2.Qualified14      = result.Qualified14;
                        result2.Qualified15      = result.Qualified15;
                        result2.Qualified16      = result.Qualified16;
                        result2.TotalGoals       = result.TotalGoals;
                    }
                    model.SaveChanges();
                }
                else
                {
                    Result[] entities = new Result[] { result };
                    model.Results.AddOrUpdate <Result>(entities);
                    model.SaveChanges();
                }
            }
        }