Пример #1
0
        public static Portable.Classes.Location.Location CreateNewLocation(LocationOwnerType ownerType, string name, string address1, string address2, string city, int country, string state, string zip, string website, Guid idOfOwner)
        {
            Portable.Classes.Location.Location l = new Portable.Classes.Location.Location();
            string log = string.Empty;
            try
            {
                var dc = new ManagementContext();
                DataModels.Location.Location location = new DataModels.Location.Location();
                if (ownerType == LocationOwnerType.calendar)
                {
                    var cal = dc.Calendar.Where(x => x.CalendarId == idOfOwner).FirstOrDefault();
                    cal.Locations.Add(location);
                }
                else if (ownerType == LocationOwnerType.shop)
                {
                    var shop = dc.Merchants.Where(x => x.PrivateManagerId == idOfOwner).FirstOrDefault();
                    shop.Locations.Add(location);
                }
                location.LocationName = name;
                location.Contact = new DataModels.ContactCard.ContactCard();
                Address a = new Address();
                a.Address1 = address1;
                a.Address2 = address2;
                a.CityRaw = city;
                a.Country = dc.Countries.Where(x => x.CountryId == country).FirstOrDefault();
                a.StateRaw = state;
                a.ContactCard = location.Contact;
                var coords = OpenStreetMap.FindLatLongOfAddress(a.Address1, a.Address2, a.Zip, a.CityRaw, a.StateRaw, a.Country != null ? a.Country.Name : string.Empty);
                a.Coords = new System.Device.Location.GeoCoordinate();
                if (coords != null)
                {
                    log += "not" + coords.Latitude + " " + coords.Longitude;
                    a.Coords.Latitude = coords.Latitude;
                    a.Coords.Longitude = coords.Longitude;
                }
                else
                {
                    a.Coords.Latitude = 0.0;
                    a.Coords.Longitude = 0.0;
                }
                a.Coords.Altitude = 0.0;
                a.Coords.Course = 0.0;
                a.Coords.HorizontalAccuracy = 1.0;
                a.Coords.Speed = 0.0;
                a.Coords.VerticalAccuracy = 1.0;

                location.Contact.Addresses.Add(a);
                if (!String.IsNullOrEmpty(website))
                {
                    string comType = CommunicationTypeEnum.Website.ToString();
                    Communication web = new Communication();
                    web.Data = website;
                    web.CommunicationTypeEnum = (byte)CommunicationTypeEnum.Website;
                    location.Contact.Communications.Add(web);
                }
                dc.Locations.Add(location);
                int c = dc.SaveChanges();

                l.LocationId = location.LocationId;
                l.LocationName = name;
                Portable.Classes.ContactCard.Address address = new Portable.Classes.ContactCard.Address();
                address.Address1 = address1;
                address.Address2 = address2;
                address.CityRaw = city;
                if (a.Country != null)
                    address.Country = a.Country.Name;
                address.StateRaw = a.StateRaw;
                address.Zip = a.Zip;
                l.Contact.Addresses.Add(address);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: name + " " + address1 + " " + address2 + " " + city + " " + country + " " + state + " " + zip + " " + website + " " + idOfOwner);
            }
            return l;

        }
Пример #2
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;
        }