Пример #1
0
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Player player = _repository.GetPlayerByID(id);

            PlayerMatchRepository _playerMatchRepository = new PlayerMatchRepository();
            List <PlayerMatch>    playerMatches          = _playerMatchRepository.GetPlayerMatchesByPlayerId(player.ID).ToList();

            if (player == null)
            {
                return(HttpNotFound());
            }

            if (playerMatches == null)
            {
                return(View(player));
            }
            foreach (var playerMatch in playerMatches)
            {
                if (playerMatch.NumberOfGoals == 0 && playerMatch.NumberOfReds == 0 && playerMatch.NumberOfYellows == 0)
                {
                    continue;
                }
                else
                {
                    ViewBag.ErrorMessage = "Deleting this player affected the result of some matches. You cannot delete this player";
                    return(View("Error"));
                }
            }

            return(View(player));
        }
        /**
         * Contructor to get all matches from xml file and save them to allMatches List
         **/
        public MatchRepository()
        {
            _playerMatchRes = new PlayerMatchRepository();
            _allMatches     = new List <Match>();

            var Matches = from Match in GlobalVariables.XmlData.Descendants("match")
                          select new Match(Match.Element("id").Value, (DateTime)Match.Element("time"), Match.Element("name").Value,
                                           "0-0", Match.Element("leagueName").Value);

            _allMatches.AddRange(Matches.ToList <Match>());
            foreach (var match in _allMatches)
            {
                int real  = 0;
                int guest = 0;
                IEnumerable <PlayerMatch.PlayerMatch> listPlayerMatch = _playerMatchRes.GetPlayerMatchesByMatchId(match.ID);
                foreach (var playerMatch in listPlayerMatch)
                {
                    if (playerMatch.NumberOfGoals > 0)
                    {
                        if (playerMatch.PlayerID != "-1")
                        {
                            real = real + playerMatch.NumberOfGoals;
                        }
                        else
                        {
                            guest = guest + playerMatch.NumberOfGoals;
                        }
                    }
                }
                string[] words = match.Name.Split('-');
                if (words[0].Contains("Real Madrid"))
                {
                    match.Score = real + " - " + guest;
                }
                else
                {
                    match.Score = guest + " - " + real;
                }
            }
        }