Beispiel #1
0
        //TODO - Refactor these into Repository classes if they will be used anywhere else
        private static Club FindCreateClubBySourceId(ISession session, PlayerClubDto clubDto)
        {
            var clubs = session.QueryOver<Club>().Where(p => p.SourceId == clubDto.ClubSourceId).List();

            if (clubs == null || clubs.Count > 1)
                return null;

            return clubs.Count == 1 ? clubs[0] : new Club(clubDto.ClubSourceId, clubDto.ClubCompactName);
        }
Beispiel #2
0
        private PlayerClubDto getPlayerClub(HtmlNode clubTrNode)
        {
            var playerClub = new PlayerClubDto();

            var clubTdNodes = clubTrNode.Descendants("td");
            if (clubTdNodes == null || clubTdNodes.Count() < 3)
                return playerClub;

            var clubNameTdNode = clubTdNodes.First();
            playerClub.ClubCompactName = clubNameTdNode != null ? clubNameTdNode.InnerText.Trim() : null;

            var clubSourceId = getClubSourceId(clubNameTdNode.Descendants("a").FirstOrDefault());
            //Note - This will throw an exception if the sourceId is null, that's fine by me
            playerClub.ClubSourceId = clubSourceId.Value;

            var playerJoinDateNode = clubTdNodes.ElementAt(1);
            DateTime joinDate;
            if (playerJoinDateNode != null && DateTime.TryParse(playerJoinDateNode.InnerText.Trim(), out joinDate))
            {
                playerClub.PlayerJoinDate = joinDate;
            }

            var playerLeftDateNode = clubTdNodes.ElementAt(2);
            DateTime leftDate;
            if (playerLeftDateNode != null && DateTime.TryParse(playerLeftDateNode.InnerText.Trim(), out leftDate))
            {
                playerClub.PlayerLeftDate = leftDate;
            }
            return playerClub;
        }
Beispiel #3
0
        private static bool PresentOrPastPremierPlayer(PlayerClubDto currentClubDto, IList<PlayerClubDto> formerClubDtos)
        {
            if (currentClubDto != null && _premiershipClubs.Contains(currentClubDto.ClubCompactName))
                return true;

            if (formerClubDtos.Count > 0 && formerClubDtos.Any(c => _premiershipClubs.Contains(c.ClubCompactName)))
                return true;

            return false;
        }
Beispiel #4
0
        private static void importPlayerRecord(ISession session, PlayerClubDto currentClubDto,
            IList<PlayerClubDto> formerClubDtos,
            string playerName, int sourceReference, int? squadNumber, int? age)
        {
            List<Club> formerClubs = new List<Club>();
            foreach (var formerClubDto in formerClubDtos)
            {
                var formerClub = FindCreateClubBySourceId(session, formerClubDto);
                session.SaveOrUpdate(formerClub);
                formerClubs.Add(formerClub);
            }

            Player player;
            if (currentClubDto != null)
            {
                Club currentClub = FindCreateClubBySourceId(session, currentClubDto);
                currentClub.Name = currentClubDto.ClubName;
                session.SaveOrUpdate(currentClub);
                player = FindPlayer(session, sourceReference) ??
                    new Player(sourceReference, playerName, currentClub);
                foreach (var club in formerClubs)
                {
                    club.AddFormerPlayer(player);
                }
            }
            else
            {
                player = FindPlayer(session, sourceReference) ??
                    new Player(sourceReference, playerName, formerClubs);
            }

            player.SquadNumber = squadNumber;
            player.Age = age;

            session.SaveOrUpdate(player);
        }