Пример #1
0
        public Task <StandingsViewModel> GetStandings(long competitionId, int sortingLevel)
        {
            var competition = competitionRepository.Get(competitionId);

            var teams = competition.Teams;

            var models = mapper.MapMulitpleDomainToModel(teams).ToList();

            var ranks = competition.Rankings.ToList();

            models.ForEach(model =>
            {
                ranks.Where(r => r.CompetitionTeam.Id == model.SeasonTeamId).ToList().ForEach(rank =>
                {
                    AddRankToModel(rank.GroupName, rank.Rank, rank.GroupLevel, model);
                });
            });

            var result = new StandingsViewModel()
            {
                StandingsName = competition.Name + " Standings",
                Teams         = models
            };

            result.SortByLevel(sortingLevel);

            return(Task.FromResult(result));
        }
Пример #2
0
 public ActionResult ChangeStandings(string team, int wins, int loses)
 {
     lock (locker)
     {
         try
         {
             Team t = DataAccess.DbAccess.Standings.ToList().Find(x => x.Team.TeamName == team).Team;
             //t.Standing.Wins = wins;
             //t.Standing.Loses = loses;
             DataAccess.DbAccess.UpdateStandings(t.TeamID, wins, loses);
             DataAccess.DbAccess.SaveChanges();
             DataAccess.RefreshDB();
             return(RedirectToAction("Standings", "Admin"));
         }
         catch
         {
             StandingsViewModel svm = new StandingsViewModel();
             foreach (var node in DataAccess.DbAccess.Teams.ToList())
             {
                 svm.teams.Add(node.TeamName);
             }
             svm.errorMSG = "Unknown error occured";
             return(View(svm));
         }
     }
 }
Пример #3
0
        public async Task RefreshData()
        {
            summary = await GameDataService.GetGameSummary();

            FirstDay  = summary.CurrentDay - 1;
            standings = await StandingsService.GetStandings(1, summary.CurrentYear, 1);

            playoffs = await PlayoffService.GetPlayoffSummary(2, summary.CurrentYear);

            if (Yesterday != null)
            {
                await Yesterday.RefreshData();
            }
            if (Today != null)
            {
                await Today.RefreshData();
            }
            if (Tomorrow != null)
            {
                await Tomorrow.RefreshData();
            }


            StateHasChanged();
        }
Пример #4
0
        public ActionResult Standings()
        {
            var vm = new StandingsViewModel();

            // hämta data för tabell
            var standings = new List <Standing>();

            using (var session = NHibernateFactory.OpenSession())
            {
                standings = session.Query <Standing>().Where(s => s.Year == DateTime.Now.Year).ToList();
            }

            foreach (var standing in standings)
            {
                var s = new StandingPlayerDTO()
                {
                    Placering     = standing.Place,
                    Namn          = string.Format("{0} {1}", standing.Player.FirstName, standing.Player.LastName),
                    PDGA          = standing.Player.PdgaNumber,
                    TotalPoang    = standing.TotalPoints,
                    DGT1Placering = standing.DGT1Place,
                    DGT1Poang     = standing.DGT1Points,
                    DGT2Placering = standing.DGT2Place,
                    DGT2Poang     = standing.DGT2Points,
                    DGT3Placering = standing.DGT3Place,
                    DGT3Poang     = standing.DGT3Points,
                    DGT4Placering = standing.DGT4Place,
                    DGT4Poang     = standing.DGT4Points,
                    DGT5Placering = standing.DGT5Place,
                    DGT5Poang     = standing.DGT5Points
                };
                vm.Standings.Add(s);
            }


            // Debug - test ...
            //for (int i = 0; i < 30; i++)
            //{
            //    vm.Standings.Add(new StandingPlayerDTO()
            //    {
            //        Placering = 30-i,
            //        Namn = "Peter Bygde",
            //        PDGA = "8558",
            //        TotalPoang = i + 23,
            //        DGT1Placering = 23,
            //        DGT1Poang = 12,
            //        DGT2Placering = 23,
            //        DGT2Poang = 12,
            //        DGT3Placering = 23,
            //        DGT3Poang = 12,
            //        DGT4Placering = 23,
            //        DGT4Poang = 12,
            //        DGT5Placering = 23,
            //        DGT5Poang = 12
            //    });
            //}

            return(View(vm));
        }
 public IActionResult Standings(StandingsViewModel viewModel)
 {
     ViewBag.SeasonDropDown = _repository.GetSeasonDropDown();
     return(View(new StandingsViewModel()
     {
         Rankings = _repository.GetStandings(viewModel.DivisionId), DivisionId = viewModel.DivisionId
     }));
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            DataContext = new StandingsViewModel((Game)e.Parameter);

            SystemNavigationManager systemNavigationManager = SystemNavigationManager.GetForCurrentView();

            systemNavigationManager.BackRequested += ScoreboardView_BackRequested;
            systemNavigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
        }
Пример #7
0
        public ActionResult ChangeStandings()
        {
            StandingsViewModel svm = new StandingsViewModel();

            foreach (var node in DataAccess.DbAccess.Teams.ToList())
            {
                svm.teams.Add(node.TeamName);
            }
            svm.errorMSG = "";
            return(View(svm));
        }
        public StandingsView()
        {
            InitializeComponent();

            if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1, 0))
            {
                StatusBar.SetIsVisible(this, false);
            }

            DataContext = new StandingsViewModel();
            viewModel   = DataContext as StandingsViewModel;
        }
Пример #9
0
        public ActionResult Standings(int id)
        {
            using (var context = new ApplicationDbContext())
            {
                var model = new StandingsViewModel();

                if (ModelState.IsValid)
                {
                    var pool = context.Pools.Find(id);
                    var currentIntervalId = GetCurrentInterval();
                    model.Seasons = new SelectList(pool.Seasons, "Id", "Name").ToList();
                    model.SelectedSeasonID = Convert.ToInt32(model.Seasons.Last().Value);
                    model.StandingRows = new List<StandingRow>();
                }

                return View(model);
            }
        }
        public ActionResult Standings(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            var teams = db.Teams
                        .Include(t => t.Matches)
                        .Where(t => t.LeagueId == id)
                        .OrderByDescending(t => t.Points)
                        .ThenByDescending(t => t.GoalsFor - t.GoalsAgainst)
                        .ThenByDescending(t => t.GoalsFor)
                        .ToList();

            var viewModel = new StandingsViewModel
            {
                LeagueId = id,
                League   = db.Leagues.Find(id),
                Teams    = teams
            };

            //Setting match history for each team
            var matches = db.Matches
                          .Include(m => m.HomeTeam)
                          .Include(m => m.AwayTeam)
                          .ToList();

            foreach (var team in viewModel.Teams)
            {
                team.Matches = matches.Where(
                    m => (m.HomeTeam.Name == team.Name || m.AwayTeam.Name == team.Name) &&
                    m.IsResultUpdated)
                               .ToList();

                team.NextMatch = matches
                                 .Where(m => !m.IsResultUpdated && (m.HomeTeam.Name == team.Name || m.AwayTeam.Name == team.Name))
                                 .OrderBy(m => m.DateTime)
                                 .FirstOrDefault();
            }

            return(View(viewModel));
        }
Пример #11
0
        /// <summary>
        /// Renders view with standings of the tournament specified by identifier.
        /// </summary>
        /// <param name="tournamentId">Identifier of the tournament.</param>
        /// <param name="tournamentName">Name of the tournament.</param>
        /// <returns>View with standings of the tournament.</returns>
        public ActionResult Standings(int tournamentId, string tournamentName)
        {
            if (_gameReportService.IsStandingAvailable(tournamentId))
            {
                var standings = _gameReportService.GetStandings(tournamentId);
                var pivots    = _gameReportService.GetPivotStandings(tournamentId);

                var mapedStandings = standings.Divisions
                                     .Select(item =>
                {
                    var standingsTable = DivisionStandingsViewModel.Map(item);
                    TeamStandingsViewModelBase.SetPositions(standingsTable.StandingsEntries);
                    return(standingsTable);
                })
                                     .ToList();

                var pivotTables = pivots.Divisions.Select(item => new PivotTableViewModel(item)).ToList();

                var standingsViewModel = new StandingsViewModel
                {
                    TournamentId   = tournamentId,
                    TournamentName = tournamentName,
                    StandingsTable = mapedStandings,
                    PivotTable     = pivotTables
                };

                return(View(standingsViewModel));
            }
            else
            {
                var standingsViewModel = new StandingsViewModel
                {
                    TournamentId   = tournamentId,
                    TournamentName = tournamentName,
                    Message        = Resources.UI.GameReportViews.StandingsNotAvaliable
                };
                return(View("StandingsNotAvailable", standingsViewModel));
            }
        }
Пример #12
0
 public StandingsView(StandingsViewModel model)
 {
     Model = model;
 }
Пример #13
0
        private async Task <List <StandingsViewModel> > GetStandingsBySubscriptions(List <Subscription> subscriptionList)
        {
            List <StandingsViewModel> standingsList = new List <StandingsViewModel>();

            int points, played, won, drawn, lost, goalsFor, goalsAgainst, goalsDifference, percentage;

            var result = await _matchChampionshipRepository.GetAll();

            foreach (var item in subscriptionList)
            {
                points          = 0;
                played          = 0;
                won             = 0;
                drawn           = 0;
                lost            = 0;
                goalsFor        = 0;
                goalsAgainst    = 0;
                goalsDifference = 0;
                percentage      = 0;

                List <MatchChampionship> _matchChampionshipList = result.Where(p => p.Calculate == true && (p.HomeSubscriptionId == item.Id || p.GuestSubscriptionId == item.Id)).ToList();

                foreach (var item2 in _matchChampionshipList)
                {
                    played += 1;

                    if (item.Id == item2.Id)
                    {
                        if (item2.HomePoints > item2.GuestPoints)
                        {
                            points       += 3;
                            won          += 1;
                            goalsFor     += item2.HomePoints;
                            goalsAgainst += item2.GuestPoints;
                        }
                        else if (item2.HomePoints < item2.GuestPoints)
                        {
                            lost         += 1;
                            goalsFor     += item2.HomePoints;
                            goalsAgainst += item2.GuestPoints;
                        }
                        else if (item2.HomePoints == item2.GuestPoints)
                        {
                            points       += 1;
                            drawn        += 1;
                            goalsFor     += item2.HomePoints;
                            goalsAgainst += item2.GuestPoints;
                        }
                    }
                    else
                    {
                        if (item2.HomePoints > item2.GuestPoints)
                        {
                            lost         += 1;
                            goalsFor     += item2.GuestPoints;
                            goalsAgainst += item2.HomePoints;
                        }
                        else if (item2.HomePoints < item2.GuestPoints)
                        {
                            points       += 3;
                            won          += 1;
                            goalsFor     += item2.GuestPoints;
                            goalsAgainst += item2.HomePoints;
                        }

                        else if (item2.HomePoints == item2.GuestPoints)
                        {
                            points       += 1;
                            drawn        += 1;
                            goalsFor     += item2.GuestPoints;
                            goalsAgainst += item2.HomePoints;
                        }
                    }
                }

                goalsDifference = goalsFor - goalsAgainst;

                if (points != 0)
                {
                    percentage = (points * 100) / (played * 3);
                }

                StandingsViewModel standings = new StandingsViewModel
                {
                    Name            = item.Team.Name,
                    Played          = played,
                    Points          = points,
                    Won             = won,
                    Drawn           = drawn,
                    Lost            = lost,
                    GoalsFor        = goalsFor,
                    GoalsAgainst    = goalsAgainst,
                    GoalsDifference = goalsDifference,
                    Percentage      = percentage
                };

                standingsList.Add(standings);
            }

            return(standingsList.OrderByDescending(p => p.Points).ThenByDescending(p => p.Won).ThenByDescending(p => p.GoalsDifference).ThenByDescending(p => p.GoalsFor).ToList());;
        }
Пример #14
0
        // GET: Tour/TourStandings/5
        public async Task <IActionResult> TourStandings(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            HttpContext.Session.SetInt32("ChosenTourId", (int)id);

            // New Code, build a TourViewModel with necessary components
            TourViewModel tvm = new TourViewModel();

            var t = (from tour in _context.Tours
                     where tour.TourId == id
                     select tour).FirstOrDefault();

            tvm.Tour = t;


            var players = (from player in _context.Users
                           where player.UserTours.Any(ut => ut.UserId.Equals(player.Id) && ut.TourId == id)
                           select player).ToList();
            var placementrulesquery = (from placementrule in _context.PlacementRules
                                       where placementrule.TourId == tvm.Tour.TourId
                                       select placementrule).ToList();
            var standings    = new Dictionary <ApplicationUser, StandingsViewModel>();
            var placementmap = new Dictionary <int, PlacementRule>();

            foreach (var player in players)
            {
                standings.Add(player, new StandingsViewModel {
                    Score = 0, Player = player
                });
            }
            foreach (var placementrule in placementrulesquery)
            {
                placementmap.Add(placementrule.Place, placementrule);
            }

            var tourevents = (from tourevent in _context.TourEvents
                              where tourevent.TourId == tvm.Tour.TourId
                              select tourevent).ToList();
            var tourresults = new List <TourResult>();

            foreach (var tourevent in tourevents)
            {
                var toureventresults = (from toureventresult in _context.TourResult
                                        where toureventresult.TourEventId == tourevent.TourEventId
                                        select toureventresult).Include(ter => ter.User).ToList();
                tourresults.AddRange(toureventresults);
            }

            foreach (var tourresult in tourresults)
            {
                StandingsViewModel standing      = standings[tourresult.User];
                PlacementRule      placementrule = placementmap[tourresult.Place];
                standing.Score += placementrule.Points;
            }

            tvm.Standings = standings.Values.OrderByDescending(s => s.Score).ToList();

            return(View(tvm));
        }
Пример #15
0
        public ActionResult Index()
        {
            /* This method will pass two models to the view Index to use in the sidebar */

            var drivers = (db.Drivers.Select(driver => new DriverModel
            {
                firstName = driver.firstName,
                lastName = driver.lastName,
                age = Convert.ToString(driver.age),
                weight = driver.weight,
                height = driver.height,
                nationality = driver.nationality,
                championshipsWon = driver.championshipsWon,
                profileImage = driver.profileImageUrl,
                championshipPoints = driver.championshipPoints,
                teamName = driver.Team.teamName
            })).OrderByDescending(d => d.championshipPoints);

            /* Selecting all the teams from the DB and ordering it by the championship points */
            var constructors =
            (db.Teams.Select(team => new TeamModel
                                         {
                                             teamName = team.teamName,
                                             championshipPoints = team.championshipPoints
                                         })).OrderByDescending(t => t.championshipPoints);

            /* Select the next race date from the database */
            var currentDate = @DateTime.Now;

            /* Selecting all the races from the RaceCalendar table and ordering them so that the first race of the season is on top */
            var allRaces = db.RaceCalendars.Select(t => t).OrderBy(t => t.startDate);
            var nextRaceIndex = 0;
            var startDate = new DateTime();
            var endDate = new DateTime();

            foreach (var raceCalendar in allRaces)
            {
                var result = DateTime.Compare(raceCalendar.startDate, currentDate);

                if(result > 0)
                {
                    /* The start date from the database is AFTER The current Date */
                    nextRaceIndex = raceCalendar.raceId;
                    startDate = raceCalendar.startDate;
                    endDate = raceCalendar.endDate;

                    break;
                    /* Jumping out of the for loop because we got the upcoming race so we can discard the rest of the data */
                }

            }

            /* Creating a blank track model*/
            var trackModel = new TrackModel();

            var raceInformation = db.Tracks.Where(track => track.raceId == nextRaceIndex);
            foreach (var track in raceInformation)
            {
                /* There will only be one track in the loop */
                trackModel.trackName = track.trackName;
                trackModel.location = track.location;
                trackModel.fastestLap = track.fastestLap;
                trackModel.fastestLapHolder = track.fastestLapHolder;
                trackModel.imageUrl = track.trackImageUrl;
                trackModel.pastWinner = track.pastWinner;
            }

            /* Coverting the LINQ to a list of tracks */
            var nextTrack = new List<TrackModel>();
            nextTrack.Add(trackModel);

            /* Converting the LINQ to a list of drivers */
            List<DriverModel> allDrivers = drivers.ToList();

            /* Converting the LINQ to a list of teams */
            List<TeamModel> allTeams = constructors.ToList();

            var model = new StandingsViewModel()
                                           {
                                               DriverModel = allDrivers,
                                               TeamModel = allTeams,
                                               TrackModels = nextTrack,
                                               StartDate = startDate,
                                               EndDate = endDate
                                           };

            return View(model);
        }
Пример #16
0
        public StandingsPage(StandingsViewModel vm)
        {
            InitializeComponent();

            BindingContext = vm;
        }