Exemplo n.º 1
0
        public static RDN.Portable.Classes.League.Classes.League GetLeagueForFederation(Guid federationId, Guid leagueId)
        {
            try
            {
                var dc = new ManagementContext();
                var league = dc.FederationLeagues.Include("Federation").Include("League").Include("League.Owners").Include("League.Teams").Include("League.Members").Include("League.ContactCard").Where(x => x.League.LeagueId == leagueId && x.Federation.FederationId == federationId).FirstOrDefault();

                RDN.Portable.Classes.League.Classes.League leagueTemp = new RDN.Portable.Classes.League.Classes.League();
                leagueTemp.LeagueId = league.League.LeagueId;
                leagueTemp.Name = league.League.Name;
                leagueTemp.Website = league.League.WebSite;
                //we use the contact card Id as the join code for "making contact with the league" 
                //instead of creating a new id 
                //and when I don't want to release to use the public LeagueId as the join key.
                leagueTemp.JoinCode = league.League.LeagueJoinCode;
                leagueTemp.SubscriptionPeriodEnds = league.League.SubscriptionPeriodEnds.GetValueOrDefault();

                if (league.League.Founded.HasValue)
                    leagueTemp.Founded = league.League.Founded.Value;
                if (league.League.ContactCard.Addresses.FirstOrDefault() != null)
                {
                    leagueTemp.TimeZone = league.League.ContactCard.Addresses.FirstOrDefault().TimeZone;
                    leagueTemp.Address = league.League.ContactCard.Addresses.FirstOrDefault().Address1;
                    leagueTemp.City = league.League.ContactCard.Addresses.FirstOrDefault().CityRaw;
                    leagueTemp.State = league.League.ContactCard.Addresses.FirstOrDefault().StateRaw;
                    if (league.League.ContactCard.Addresses.FirstOrDefault().Country != null)
                    {
                        leagueTemp.Country = league.League.ContactCard.Addresses.FirstOrDefault().Country.Name;
                        leagueTemp.CountryId = league.League.ContactCard.Addresses.FirstOrDefault().Country.CountryId;
                    }
                }
                if (league.League.ContactCard.Emails.FirstOrDefault() != null)
                    leagueTemp.Email = league.League.ContactCard.Emails.Where(x => x.IsDefault == true).FirstOrDefault().EmailAddress;
                //int numberType = Convert.ToInt32(CommunicationTypeEnum.PhoneNumber);
                var phone = league.League.ContactCard.Communications.Where(x => x.CommunicationTypeEnum == (byte)CommunicationTypeEnum.PhoneNumber).FirstOrDefault();
                if (phone != null)
                    leagueTemp.PhoneNumber = phone.Data;

                if (league.League.Logo != null)
                    leagueTemp.Logo = new PhotoItem(league.League.Logo.ImageUrl, league.League.Logo.IsPrimaryPhoto, league.League.Logo.AlternativeText);

                if (league.League.InternalWelcomePicture != null)
                    leagueTemp.InternalWelcomeImage = new PhotoItem(league.League.InternalWelcomePicture.ImageUrl, league.League.InternalWelcomePicture.IsPrimaryPhoto, league.League.InternalWelcomePicture.AlternativeText);

                leagueTemp.InternalWelcomeMessage = league.League.InternalWelcomeMessage;

                var members = league.League.Members.ToList();

                leagueTemp.LeagueMembers.AddRange(MemberDisplayFactory.IterateMembersForDisplay(members).OrderBy(x => x.DerbyName));

                foreach (var team in league.League.Teams)
                {
                    TeamDisplay teamTemp = new TeamDisplay();
                    teamTemp.TeamName = team.Name;
                    teamTemp.TeamId = team.TeamId;
                    teamTemp.Description = team.Description;
                    leagueTemp.Teams.Add(teamTemp);
                }

                //foreach (var owner in league.League.Owners)
                //{
                //    MemberDisplay mem = new MemberDisplay();
                //    mem.DerbyName = owner.Member.DerbyName;
                //    mem.MemberId = owner.Member.MemberId;
                //    leagueTemp.Owners.Add(mem);
                //}

                FederationDisplay fed = new FederationDisplay();
                fed.FederationId = league.Federation.FederationId;
                fed.FederationName = league.Federation.Name;
                fed.MembershipId = league.InternalLeagueIdForFederation;
                leagueTemp.Federations.Add(fed);
                leagueTemp.InternalFederationIdForLeague = league.InternalLeagueIdForFederation;
                leagueTemp.FederationIdForLeague = league.Federation.FederationId;
                return leagueTemp;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// searches for the league with the name that has no owners..
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static List<RDN.Portable.Classes.League.Classes.League> SearchForLeagueName(string name)
        {
            List<RDN.Portable.Classes.League.Classes.League> leagues = new List<RDN.Portable.Classes.League.Classes.League>();
            try
            {
                var dc = new ManagementContext();
                var list = dc.Leagues.Where(x => x.Name.ToLower().Contains(name.ToLower())).ToList();
                foreach (var league in list)
                {
                    RDN.Portable.Classes.League.Classes.League basic = new RDN.Portable.Classes.League.Classes.League();
                    basic.LeagueId = league.LeagueId;
                    basic.Name = league.Name;
                    if (league.ContactCard != null && league.ContactCard.Addresses.FirstOrDefault() != null)
                    {
                        basic.City = league.ContactCard.Addresses.FirstOrDefault().CityRaw;
                        basic.State = league.ContactCard.Addresses.FirstOrDefault().StateRaw;
                        if (league.ContactCard.Addresses.FirstOrDefault().Country != null)
                        {
                            basic.Country = league.ContactCard.Addresses.FirstOrDefault().Country.Name;
                            basic.CountryId = league.ContactCard.Addresses.FirstOrDefault().Country.CountryId;
                        }
                    }
                    if (league.Members.Where(x => x.LeagueOwnersEnums > 0).Count() == 0)
                        leagues.Add(basic);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: name);
            }
            return leagues;

        }
Exemplo n.º 3
0
        /// <summary>
        /// gets all the leagues in the federation.
        /// </summary>
        /// <param name="federationId"></param>
        /// <returns></returns>
        public static List<RDN.Portable.Classes.League.Classes.League> GetLeaguesInFederation(Guid federationId, int recordsToSkip, int numberOfRecordsToPull)
        {
            var output = new List<RDN.Portable.Classes.League.Classes.League>();

            var dc = new ManagementContext();
            // Get the leagues that matches the partial name, include all contactcard information in the query
            var leagues = dc.FederationLeagues.Include("League.ContactCard").Where(x => x.Federation.FederationId == federationId).OrderBy(x => x.Created).Skip(recordsToSkip).Take(numberOfRecordsToPull).ToList();

            foreach (var league in leagues)
            {
                // Create a league object to be returned
                //TODO: Remove logo path
                var leagueObj = new RDN.Portable.Classes.League.Classes.League { LeagueId = league.League.LeagueId, Name = league.League.Name }; //, LogoPath = league.LogoPath
                leagueObj.InternalFederationIdForLeague = league.InternalLeagueIdForFederation;
                // If contact information is found, add it
                if (league.League.ContactCard != null)
                {
                    var addresses = league.League.ContactCard.Addresses;
                    if (addresses != null && addresses.Count > 0)
                    {
                        if (addresses.Count > 0)
                        {
                            var address = addresses.FirstOrDefault(x => x.IsDefault);
                            if (address == null)
                                address = addresses.First();
                            leagueObj.State = address.StateRaw;
                            if (address.Country != null)
                                leagueObj.Country = address.Country.Name;
                        }
                        else
                        {
                            var address = addresses.First();
                            leagueObj.State = address.StateRaw;
                            leagueObj.Country = address.Country.Name;
                        }
                    }
                }
                output.Add(leagueObj);
            }
            return output;
        }
Exemplo n.º 4
0
        public static List<RDN.Portable.Classes.League.Classes.League> GetAllPublicLeagues(int recordsToSkip, int numberOfRecordsToPull)
        {
            var output = new List<RDN.Portable.Classes.League.Classes.League>();

            var dc = new ManagementContext();
            // Get the leagues that matches the partial name, include all contactcard information in the query
            var leagues = dc.Leagues.Include("ContactCard").Where(x => x.IsLeaguePublic == false).OrderBy(x => x.Name).Skip(recordsToSkip).Take(numberOfRecordsToPull).ToList();

            foreach (var league in leagues)
            {
                // Create a league object to be returned
                //TODO: Remove logo path
                var leagueObj = new RDN.Portable.Classes.League.Classes.League { LeagueId = league.LeagueId, Name = league.Name }; //, LogoPath = league.LogoPath

                // If contact information is found, add it
                if (league.ContactCard != null)
                {
                    var addresses = league.ContactCard.Addresses;
                    if (addresses != null && addresses.Count > 0)
                    {
                        if (addresses.Count > 0)
                        {
                            var address = addresses.FirstOrDefault(x => x.IsDefault);
                            if (address == null)
                                address = addresses.First();
                            leagueObj.State = address.StateRaw;
                            if (address.Country != null)
                                leagueObj.Country = address.Country.Name;
                        }
                        else
                        {
                            var address = addresses.First();
                            leagueObj.State = address.StateRaw;
                            leagueObj.Country = address.Country.Name;
                        }
                    }
                }

                if (league.Logo != null)
                    leagueObj.Logo = new PhotoItem(league.Logo.ImageUrl, league.Logo.IsPrimaryPhoto, league.Logo.AlternativeText);
                output.Add(leagueObj);
            }
            return output.OrderBy(x => x.Name).ToList();
        }
Exemplo n.º 5
0
        public static RDN.Portable.Classes.League.Classes.League GetLeaguePublicDerbyRoster(Guid leagueId)
        {
            var dc = new ManagementContext();
            var league = dc.LeaguesForDerbyRoster.Include("Skaters").Where(x => x.TeamId == leagueId).FirstOrDefault();

            RDN.Portable.Classes.League.Classes.League leagueTemp = new RDN.Portable.Classes.League.Classes.League();
            leagueTemp.LeagueId = league.TeamId;
            leagueTemp.Name = league.Name;
            leagueTemp.Country = league.Country;
            leagueTemp.State = league.State;
            leagueTemp.Website = league.WebSite;

            foreach (var skater in league.Skaters)
            {
                MemberDisplay member = new MemberDisplay();
                member.DerbyName = skater.Name;
                member.PlayerNumber = skater.Number;
                member.MemberId = skater.ProfileId;
                leagueTemp.LeagueMembers.Add(member);
            }

            return leagueTemp;
        }