Exemplo n.º 1
0
        internal static ClubInfoViewModel GetClub(int clubId, int?seasonId)
        {
            using (var db = new DataEntities())
            {
                var club = db.Clubs.Include(x => x.ClubTeams)
                           .Include(x => x.ClubTeams.Select(t => t.Team.TeamsDetails))
                           .Include(x => x.ClubTeams.Select(f => f.Team.TeamsPlayers)).FirstOrDefault(x => x.ClubId == clubId);
                if (club == null)
                {
                    return(new ClubInfoViewModel());
                }

                var result = new ClubInfoViewModel
                {
                    Main = new Main
                    {
                        Players   = club.ClubTeams.Sum(x => x.Team.TeamsPlayers.Count),
                        Officials = JRepo.CountOfficialsInClub(clubId)
                    },
                    Info = new Info
                    {
                        ClubName       = club.Name,
                        Address        = club.Address,
                        Description    = club.Description,
                        Email          = club.Email,
                        TermsCondition = club.TermsCondition,
                        Phone          = club.ContactPhone,
                        AboutClub      = club.IndexAbout,
                        Logo           = club.Logo,
                        Image          = club.PrimaryImage,
                        Index          = club.IndexImage
                    },
                    Officials = JRepo.GetClubOfficials(clubId).Select(x => new Officials
                    {
                        JobName  = x.JobName,
                        UserName = x.FullName
                    }).ToArray(),
                    Tournaments = db.Leagues.Include(x => x.Age).Include(x => x.Gender).Where(x => x.ClubId == clubId && x.IsArchive == false).Select(x => new Tournaments
                    {
                        Name   = x.Name,
                        Ages   = x.Age.Title,
                        Gender = x.Gender.Title
                    }).ToArray()
                };

                if (seasonId.HasValue)
                {
                    result.Teams = (from clubTeam in club.ClubTeams
                                    let teamDetails = clubTeam.Team.TeamsDetails.FirstOrDefault(x => x.SeasonId == seasonId)
                                                      select new Teams()
                    {
                        Id = clubTeam.TeamId,
                        Team = teamDetails != null ? teamDetails.TeamName : clubTeam.Team.Title
                    }).ToArray();
                }
                else
                {
                    result.Teams = club.ClubTeams.Select(x => new Teams
                    {
                        Id   = x.TeamId,
                        Team = x.Team.Title
                    }).ToArray();
                }

                return(result);
            }
        }