public ActionResult Index()
        {
            MatchPlayerViewModel model = new MatchPlayerViewModel();

            model.Players = new List <PlayerDetail>();
            return(View(model));
        }
        public IActionResult Delete(MatchPlayerViewModel model, int matchId, int matchPlayerId)
        {
            Match match = matchRepository.Matches.FirstOrDefault(c => c.MatchID == matchId);

            if (ModelState.IsValid)
            {
                MatchPlayer matchPlayer = match.MatchPlayers.FirstOrDefault(mp => mp.MatchPlayerID == matchPlayerId);
                match.MatchPlayers.Remove(matchPlayer);
                calculateGoals(match);
                matchRepository.Save(match);
                TempData["message"] = $"An event has been removed for {matchPlayer.TeamPlayer.Player.FullName}.";
            }
            return(RedirectToAction("Detail", "Match", new { matchId }));
        }
        public IActionResult Edit(int matchID, int matchPlayerID)
        {
            MatchPlayer matchPlayer = matchRepository.Matches.FirstOrDefault(m => m.MatchID == matchID)
                                      .MatchPlayers.FirstOrDefault(mp => mp.MatchPlayerID == matchPlayerID);
            Team team = teamRepository.Teams.FirstOrDefault(t => t.TeamID == matchPlayer.TeamPlayer.Team.TeamID);
            MatchPlayerViewModel modelView = new MatchPlayerViewModel
            {
                MatchPlayer          = matchPlayer,
                TeamPlayers          = team.Players.ToList(),
                TeamID               = team.TeamID,
                SelectedTeamPlayerID = matchPlayer.TeamPlayer.TeamPlayerID
            };

            return(View(modelView));
        }
        private MatchPlayerViewModel GetPlayer(MatchPlayer player, CompetitionDetails competition)
        {
            var result = default(MatchPlayerViewModel);

            if (player.IsNotNull())
            {
                var cp = competition.Players.FirstOrDefault(p => p.Id == player.Id);
                if (cp.IsNotNull())
                {
                    result      = new MatchPlayerViewModel(player);
                    result.Rank = cp.CompetitionRank;
                }
            }
            return(result);
        }
        public IActionResult Create(int matchId, int teamId)
        {
            Match match = matchRepository.Matches.FirstOrDefault(c => c.MatchID == matchId);
            Team  team  = teamRepository.Teams.FirstOrDefault(t => t.TeamID == teamId);

            MatchPlayerViewModel model = new MatchPlayerViewModel
            {
                MatchPlayer = new MatchPlayer {
                    Match = match
                },
                TeamPlayers = team.Players.ToList(),
                TeamID      = team.TeamID
            };

            return(View("Edit", model));
        }
Exemple #6
0
        private DataRow CreateRow(MatchPlayerViewModel player, DataTable dataTable, string index, string ClumeName)
        {
            var row = dataTable.NewRow();

            if (player != null)
            {
                row[ClumeName] = index + " " + player.FullName;
            }
            else
            {
                row[ClumeName] = index;
            }
            m_TabaleDictionary.Add(DictionaryIndex, row);
            DictionaryIndex++;
            return(row);
        }
        public IActionResult Edit(MatchPlayerViewModel model, int matchId, int teamId)
        {
            Match match = matchRepository.Matches.FirstOrDefault(c => c.MatchID == matchId);
            Team  team  = teamRepository.Teams.FirstOrDefault(t => t.TeamID == teamId);

            if (ModelState.IsValid)
            {
                model.MatchPlayer.Match      = match;
                model.MatchPlayer.TeamPlayer = team.Players.FirstOrDefault(tp => tp.TeamPlayerID == model.SelectedTeamPlayerID);

                if (model.MatchPlayer.MatchPlayerID == 0)
                {
                    match.MatchPlayers.Add(model.MatchPlayer);
                }
                else
                {
                    MatchPlayer matchPlayerDb = match.MatchPlayers.First(mp => mp.MatchPlayerID == model.MatchPlayer.MatchPlayerID);
                    matchPlayerDb.TeamPlayer  = model.MatchPlayer.TeamPlayer;
                    matchPlayerDb.Goals       = model.MatchPlayer.Goals;
                    matchPlayerDb.YellowCards = model.MatchPlayer.YellowCards;
                    matchPlayerDb.RedCards    = model.MatchPlayer.RedCards;
                }

                calculateGoals(match);

                matchRepository.Save(match);
                TempData["message"] = $"An event has been created to {model.MatchPlayer.TeamPlayer.Player.FullName} for the match.";
                return(RedirectToAction("Detail", "Match", new { matchId }));
            }
            else
            {
                MatchPlayerViewModel modelView = new MatchPlayerViewModel
                {
                    MatchPlayer = new MatchPlayer {
                        Match = match
                    },
                    TeamPlayers = team.Players.ToList(),
                    TeamID      = team.TeamID
                };
                return(View(modelView));
            }
        }
Exemple #8
0
        public ActionResult Create(MatchPlayerViewModel mv)
        {
            if (ModelState.IsValid)
            {
                if (mv.playerSelect != null)
                {
                    //pobranie wszystkich zawodników drużyn które biorą udział w turnieju
                    var player1 = db.Player.Where(s => s.PlayerTeam.Any(c => (c.TeamID == mv.Match.TeamID1 || c.TeamID == mv.Match.TeamID) &&
                                                                        (c.TournamentID == mv.Match.TournamentID && c.TournamentID != null))).ToList();

                    if (player1 != null)
                    {
                        foreach (Player value in player1)
                        {
                            if (mv.playerSelect.Contains(value.PlayerID))
                            {
                                db.PlayerMatch.Add(new PlayerMatch()
                                {
                                    MatchID  = mv.Match.MatchID,
                                    PlayerID = value.PlayerID,
                                });
                            }
                            else
                            {
                                db.PlayerMatch.Add(new PlayerMatch()
                                {
                                    MatchID  = mv.Match.MatchID,
                                    PlayerID = value.PlayerID,
                                    reserve  = true
                                });
                            }
                        }
                    }
                }
                mv.Match.isPlayed        = true;
                db.Entry(mv.Match).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Details", "Matches", new { id = mv.Match.MatchID, ids = mv.Match.TournamentID }));
            }
            return(View(mv));
        }
Exemple #9
0
        public ActionResult Create(int?id, int?ids)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            MatchPlayerViewModel match = new MatchPlayerViewModel();

            match.Match = db.Match.Find(id);

            if (match.Match.isBreak == true)
            {
                return(RedirectToAction("Index", "Matches", new { id = match.Match.TournamentID }));
            }

            if (match.Match == null)
            {
                return(HttpNotFound());
            }

            if (match.Match.isPlayed == true)
            {
                return(RedirectToAction("Details", "Matches", new { id = match.Match.MatchID, ids = match.Match.TournamentID }));
            }

            var player = db.Player.Where(s => s.PlayerTeam.Any(c => c.TeamID == match.Match.TeamID && c.TournamentID == ids && c.delete == false)).ToList();

            match.PlayerList = player;
            var player1 = db.Player.Where(s => s.PlayerTeam.Any(c => c.TeamID == match.Match.TeamID1 && c.TournamentID == ids && c.delete == false)).ToList();

            match.PlayerList1 = player1;


            return(View(match));
        }
 public ActionResult SubmitData(MatchPlayerViewModel model)
 {
     return(View());
 }
Exemple #11
0
        public ActionResult Details(int?id, int?ids)

        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            MatchPlayerViewModel match = new MatchPlayerViewModel();

            match.Match = db.Match.Find(id);

            if (match.Match == null)
            {
                return(HttpNotFound());
            }

            if (match.Match.LocationID != null)
            {
                string lat = match.Match.Google_Map.lat;
                string lng = match.Match.Google_Map.lng;

                ViewBag.lat = lat;
                ViewBag.lng = lng;
            }
            else
            {
                ViewBag.brak = "brak";
            }

            if (match.Match.isBreak == false)
            {
                if (match.Match.isPlayed == true)
                {
                    //lita zawodników biorących udzial
                    match.listPlayerMatch  = db.PlayerMatch.Where(s => s.Player.PlayerTeam.Any(c => c.TeamID == match.Match.TeamID)).Where(s => s.MatchID == match.Match.MatchID).OrderBy(o => o.reserve ? 1 : 0).ToList();
                    match.listPlayerMatch1 = db.PlayerMatch.Where(s => s.Player.PlayerTeam.Any(c => c.TeamID == match.Match.TeamID1)).Where(s => s.MatchID == match.Match.MatchID).OrderBy(o => o.reserve ? 1 : 0).ToList();

                    //kto bramke strzelił
                    match.goalList  = db.PlayerMatch.Where(s => s.Player.PlayerTeam.Any(c => c.TeamID == match.Match.TeamID)).Where(s => s.MatchID == match.Match.MatchID).Where(s => s.goal > 0);
                    match.goalList1 = db.PlayerMatch.Where(s => s.Player.PlayerTeam.Any(c => c.TeamID == match.Match.TeamID1)).Where(s => s.MatchID == match.Match.MatchID).Where(s => s.goal > 0);
                }
                else
                {
                    var player = db.Player.Where(s => s.PlayerTeam.Any(c => c.TeamID == match.Match.TeamID && c.TournamentID == ids)).OrderByDescending(o => o.number).ToList();
                    match.PlayerList = player;
                    var player1 = db.Player.Where(s => s.PlayerTeam.Any(c => c.TeamID == match.Match.TeamID1 && c.TournamentID == ids)).OrderByDescending(o => o.number).ToList();
                    match.PlayerList1 = player1;
                }
            }
            else
            {
                return(RedirectToAction("Index", "Matches", new { id = match.Match.TournamentID }));
            }
            if (match == null)
            {
                return(HttpNotFound());
            }

            return(View(match));
        }