private StadiumDto GetStadiumDto(AngleSharp.Dom.IElement clubPage)
        {
            var stadiumDto = new StadiumDto
            {
                Name = clubPage.QuerySelector(".stadiumName").TextContent,

                // TODO Stadium Info, Stadium image
            };
            return stadiumDto;
        }
        private StadiumDto CreateStadiumDto(Stadium stadium)
        {
            var stadiumDto = new StadiumDto()
            {
                Id       = stadium.Id,
                Name     = stadium.Name,
                Capacity = stadium.Capacity
            };

            return(stadiumDto);
        }
        public IActionResult Get(int id)
        {
            var stadium = _stadiumService.FindById(id);
            if(stadium == null)
            {
                return this.HttpNotFound($"Stadium ({id}) not exists", DocumentationLinks.Stadiums);
            }

            var stadiumDto = new StadiumDto(stadium);
            return new JsonResult(stadiumDto);
        }
示例#4
0
        public async Task <StadiumDto> LinkStadium(int teamId, int stadiumId)
        {
            var stadium = _context.Stadiums
                          .SingleOrDefault(x => x.Id == stadiumId);

            if (stadium == null)
            {
                throw new Exception($"Unable to find stadium with ID {stadiumId}.");
            }

            var team = _context.Teams
                       .SingleOrDefault(x => x.Id == teamId);

            if (team == null)
            {
                throw new Exception($"Unable to find team with ID {teamId}.");
            }

            var currentTeams = _context.TeamStadiums
                               .OrderByDescending(x => x.FromDate)
                               .Where(x => x.StadiumId == stadiumId && !x.ToDate.HasValue)
                               .ToList();

            if (currentTeams.Any())
            {
                foreach (var currentTeam in currentTeams)
                {
                    currentTeam.ToDate = DateTime.Today;
                }
            }

            if (!team.CanPlayInStadium(stadium, out var reason))
            {
                throw new Exception(reason);
            }

            var teamStadium = new TeamStadium
            {
                StadiumId = stadium.Id,
                TeamId    = team.Id,
                FromDate  = DateTime.Today
            };

            _context.TeamStadiums.Add(teamStadium);
            await _context.SaveChangesAsync();

            var dto = new StadiumDto();

            dto.Populate(stadium);
            return(dto);
        }
        public IActionResult GetUserStadium(int id)
        {
            var user = _userService.FindById(id);
            if(user == null)
            {
                return this.HttpNotFound($"User ({id}) not exists", DocumentationLinks.Stadiums);
            }

            var team = _teamService.FindById(user.TeamId);
            if(team == null)
            {
                return this.HttpNotFound($"Team for user ({id}) not exists", DocumentationLinks.Stadiums);
            }

            var stadium = _stadiumService.FindById(team.StadiumId);
            if(stadium == null)
            {
                return this.HttpNotFound($"Stadium for user ({id}) not exists", DocumentationLinks.Stadiums);
            }

            var stadiumDto = new StadiumDto(stadium);
            return new JsonResult(stadiumDto);
        }