Esempio n. 1
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;
        }
 private static ColorDisplay DisplayStoreItemColor(DataModels.Store.StoreItemColor color)
 {
     try
     {
         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;
             return d;
         }
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return null;
 }