Example #1
0
        /// <summary>
        /// gets all the logos in the DB.
        /// </summary>
        /// <returns></returns>
        public List<RDN.Portable.Classes.Team.TeamLogo> GetAllLogos(TeamDisplay team)
        {
            try
            {
                if (team.LeagueLogos == null || team.LeagueLogos.Count == 0)
                {
                    var dc = new ManagementContext();
                    if (team.ScoreboardLogos == null || team.ScoreboardLogos.Count == 0)
                        team.ScoreboardLogos = GetAllScoreboardLogos(team);

                    var leagues = dc.Leagues.Where(x => x.Logo != null).AsParallel().ToList();
                    foreach (var league in leagues)
                    {
                        RDN.Portable.Classes.Team.TeamLogo logo = new RDN.Portable.Classes.Team.TeamLogo();
                        logo.ImageUrl = league.Logo.ImageUrl;
                        logo.TeamName = league.Name;
                        logo.TeamLogoId = league.Logo.LeaguePhotoId;
                        team.LeagueLogos.Add(logo);
                    }
                    team.LeagueLogos = team.LeagueLogos.OrderBy(x => x.TeamName).ToList();
                }
                return team.LeagueLogos;
            }
            catch (Exception e)
            {
                Library.Classes.Error.ErrorDatabaseManager.AddException(e, e.GetType(), ErrorGroupEnum.Database);
            }
            return null;
        }
Example #2
0
        public List<RDN.Portable.Classes.Team.TeamLogo> GetAllScoreboardLogos(TeamDisplay team)
        {
            try
            {
                if (team.ScoreboardLogos == null)
                {
                    var dc = new ManagementContext();
                    var logos = dc.TeamLogos.AsParallel().OrderBy(x => x.TeamName).ToList();
                    for (int i = 0; i < logos.Count; i++)
                    {
                        team.ScoreboardLogos.Add(new RDN.Portable.Classes.Team.TeamLogo()
                        {
                            Height = logos[i].Height.ToString(),
                            ImageUrl = logos[i].ImageUrl,
                            ImageUrlThumb = logos[i].ImageUrlThumb,
                            SaveLocation = logos[i].SaveLocation,
                            TeamLogoId = logos[i].TeamLogoId,
                            TeamName = logos[i].TeamName,
                            Width = logos[i].Width.ToString()

                        });
                    }
                }

                return team.ScoreboardLogos;
            }
            catch (Exception e)
            {
                Library.Classes.Error.ErrorDatabaseManager.AddException(e, e.GetType(), ErrorGroupEnum.Database);
            }
            return null;
        }
        private static ApiCache GetCache(System.Web.Caching.Cache cache)
        {
            try
            {
                ApiCache dataObject = (ApiCache)cache["ApiCache"];
                if (dataObject == null)
                {

                    dataObject = (ApiCache)cache["ApiCache"];

                    if (dataObject == null)
                    {
                        dataObject = new ApiCache();
                        TeamFactory lo = new TeamFactory();
                        dataObject.Countries = new List<CountryClass>();
                        TeamDisplay team = new TeamDisplay();
                        var logos = lo.GetAllLogos(team);
                        foreach (var l in logos)
                            l.SaveLocation = null;

                        dataObject.Logos = logos;
                        var scoreboardLogos = team.ScoreboardLogos;
                        foreach (var l in scoreboardLogos)
                            l.SaveLocation = null;

                        dataObject.ScoreboardLogos = scoreboardLogos;
                        cache["ApiCache"] = dataObject;

                    }
                }
                return dataObject;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;
        }
Example #4
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;
        }
Example #5
0
        public static RDN.Portable.Classes.League.Classes.League DisplayLeague(DataModels.League.League league, bool isPublic = false, bool isRemovedFromLeague = false)
        {
            try
            {
                RDN.Portable.Classes.League.Classes.League leagueTemp = new Portable.Classes.League.Classes.League();
                leagueTemp.LeagueId = league.LeagueId;
                leagueTemp.Name = league.Name;
                //leagues don't put the http in their profile.
                if (!String.IsNullOrEmpty(league.WebSite) && !league.WebSite.Contains("http://"))
                    leagueTemp.Website = "http://" + league.WebSite;
                else
                    leagueTemp.Website = league.WebSite;
                if (!String.IsNullOrEmpty(league.Twitter) && !league.Twitter.Contains("http://"))
                    leagueTemp.Twitter = "http://" + league.Twitter;
                else
                    leagueTemp.Twitter = league.Twitter;
                if (!String.IsNullOrEmpty(league.Instagram) && !league.Instagram.Contains("http://"))
                    leagueTemp.Instagram = "http://" + league.Instagram;
                else
                    leagueTemp.Instagram = league.Instagram;
                if (!String.IsNullOrEmpty(league.Facebook) && !league.Facebook.Contains("http://"))
                    leagueTemp.Facebook = "http://" + league.Facebook;
                else
                    leagueTemp.Facebook = league.Facebook;
                leagueTemp.RuleSetsPlayedEnum = (RuleSetsUsedEnum)league.RuleSetsPlayedEnum;
                leagueTemp.ShopUrl = StoreGateway.GetShopUrl(league.LeagueId);

                leagueTemp.SubscriptionPeriodEnds = league.SubscriptionPeriodEnds.GetValueOrDefault();
                leagueTemp.Groups = LeagueGroupFactory.DisplayGroups(league.Groups.Where(x => x.IsGroupRemoved == false).ToList());
                if (league.Founded.HasValue)
                    leagueTemp.Founded = league.Founded.Value;
                //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.LeagueJoinCode;

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

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

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

                leagueTemp.InternalWelcomeMessage = league.InternalWelcomeMessage;

                //sets culture as united states english
                if (league.CultureLCID == 0)
                    leagueTemp.CultureSelected = 1033;
                else
                    leagueTemp.CultureSelected = league.CultureLCID;

                if (league.LastModified > new DateTime(2013, 11, 23) || league.Created > new DateTime(2013, 11, 23))
                {
                    leagueTemp.InternalWelcomeMessageHtml = leagueTemp.InternalWelcomeMessage;
                }
                else if (league.Created < new DateTime(2013, 11, 23))
                {
                    RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown();
                    markdown.AutoHyperlink = true;
                    markdown.AutoNewLines = true;
                    markdown.LinkEmails = true;
                    if (!String.IsNullOrEmpty(leagueTemp.InternalWelcomeMessage))
                    {
                        leagueTemp.InternalWelcomeMessageHtml = markdown.Transform(HtmlSanitize.FilterHtmlToWhitelist(leagueTemp.InternalWelcomeMessage));
                        leagueTemp.InternalWelcomeMessageHtml = leagueTemp.InternalWelcomeMessageHtml.Replace("</p>", "</p><br/>");
                    }
                }

                List<LeagueMember> members = new List<LeagueMember>();
                if (isPublic)
                    members = league.Members.Where(x => x.HasLeftLeague == isRemovedFromLeague && x.Member.IsProfileRemovedFromPublic == false).ToList();
                else
                    members = league.Members.Where(x => x.HasLeftLeague == isRemovedFromLeague).ToList();

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

                try
                {
                    foreach (var color in league.Colors)
                    {
                        if (color != null)
                        {
                            var c = Color.FromArgb(color.Color.ColorIdCSharp);
                            var hex = ColorTranslator.ToHtml(c);
                            ColorDisplay d = new ColorDisplay();
                            d.ColorId = color.ColorId;
                            d.CSharpColor = color.Color.ColorIdCSharp;
                            d.HexColor = hex;
                            d.NameOfColor = color.Color.ColorName;
                            leagueTemp.ColorTempSelected += d.HexColor + ";";
                            leagueTemp.ColorsSelected += d.HexColor + ";";
                            leagueTemp.Colors.Add(d);
                        }

                    }
                }
                catch (Exception exception)
                {
                    ErrorDatabaseManager.AddException(exception, exception.GetType());
                }


                foreach (var team in league.Teams)
                {
                    TeamDisplay teamTemp = new TeamDisplay();
                    teamTemp.TeamName = team.Name;
                    teamTemp.TeamId = team.TeamId;
                    teamTemp.Description = team.Description;
                    leagueTemp.Teams.Add(teamTemp);
                }
                foreach (var con in league.Contacts)
                {
                    try
                    {
                        ContactDisplayBasic c = new ContactDisplayBasic();
                        c.ContactId = con.Contact.ContactId;
                        c.FirstName = con.Contact.Firstname;
                        c.LastName = con.Contact.Lastname;
                        c.ContactTypeForOrg = (ContactTypeForOrganizationEnum)con.ContactTypeEnum;
                        c.ContactTypeSelected = c.ContactTypeForOrg.ToString();
                        if (con.Contact.ContactCard.Addresses.FirstOrDefault() != null)
                        {
                            c.ContactCard = new Portable.Classes.ContactCard.ContactCard();
                            Portable.Classes.ContactCard.Address add = new Portable.Classes.ContactCard.Address();

                            add.Address1 = con.Contact.ContactCard.Addresses.FirstOrDefault().Address1;
                            add.Address2 = con.Contact.ContactCard.Addresses.FirstOrDefault().Address2;
                            add.CityRaw = con.Contact.ContactCard.Addresses.FirstOrDefault().CityRaw;
                            add.Zip = con.Contact.ContactCard.Addresses.FirstOrDefault().Zip;
                            add.StateRaw = con.Contact.ContactCard.Addresses.FirstOrDefault().StateRaw;
                            if (con.Contact.ContactCard.Addresses.FirstOrDefault().Country != null)
                                add.Country = con.Contact.ContactCard.Addresses.FirstOrDefault().Country.Name;
                            c.Address1 = con.Contact.ContactCard.Addresses.FirstOrDefault().Address1;
                            c.Address2 = con.Contact.ContactCard.Addresses.FirstOrDefault().Address2;
                            c.CityRaw = con.Contact.ContactCard.Addresses.FirstOrDefault().CityRaw;
                            c.Zip = con.Contact.ContactCard.Addresses.FirstOrDefault().Zip;
                            c.StateRaw = con.Contact.ContactCard.Addresses.FirstOrDefault().StateRaw;
                            if (con.Contact.ContactCard.Addresses.FirstOrDefault().Country != null)
                            {
                                c.CountryId = con.Contact.ContactCard.Addresses.FirstOrDefault().Country.CountryId;
                                c.CountryName = con.Contact.ContactCard.Addresses.FirstOrDefault().Country.Name;
                            }
                            c.ContactCard.Addresses.Add(add);
                        }
                        if (con.Contact.ContactCard.Emails.FirstOrDefault() != null)
                            c.Email = con.Contact.ContactCard.Emails.FirstOrDefault().EmailAddress;

                        var phone = con.Contact.ContactCard.Communications.OrderByDescending(x => x.Created).FirstOrDefault();
                        if (phone != null)
                            c.PhoneNumber = phone.Data;
                        c.CompanyName = con.Contact.CompanyName;
                        c.Notes = con.Notes;
                        c.Link = con.Contact.Link;
                        leagueTemp.Contacts.Add(c);
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }


                foreach (var federation in league.Federations)
                {
                    FederationDisplay fed = new FederationDisplay();
                    fed.FederationId = federation.Federation.FederationId;
                    fed.FederationName = federation.Federation.Name;
                    fed.MembershipId = federation.InternalLeagueIdForFederation;

                    leagueTemp.Federations.Add(fed);
                }

                return leagueTemp;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;
        }