/// <summary>
        /// iterates throught the collection of members and sets them up for display to the end user.
        /// </summary>
        /// <param name="members"></param>
        /// <returns></returns>
        public static List<MemberDisplay> IterateMembersForDisplay(ICollection<DataModels.League.LeagueMember> members)
        {
            List<MemberDisplay> membersReturned = new List<MemberDisplay>();
            foreach (var mem in members)
            {
                try
                {
                    MemberDisplay memTemp = new MemberDisplay();
                    memTemp.IsProfileRemovedFromPublicView = mem.Member.IsProfileRemovedFromPublic;
                    memTemp.DerbyName = mem.Member.DerbyName;
                    memTemp.StartedSkating = mem.Member.YearStartedSkating;
                    memTemp.DOB = mem.Member.DateOfBirth.GetValueOrDefault();
                    if (mem.Member.ContactCard.Emails.Count > 0)
                        memTemp.Email = mem.Member.ContactCard.Emails.Where(x => x.IsDefault == true).FirstOrDefault().EmailAddress;
                    memTemp.Firstname = mem.Member.Firstname;
                    GenderEnum gen;
                    if (Enum.TryParse<GenderEnum>(mem.Member.Gender.ToString(), out gen))
                        memTemp.Gender = gen;
                    memTemp.LastName = mem.Member.Lastname;
                    memTemp.MemberId = mem.Member.MemberId;

                    memTemp.PlayerNumber = mem.Member.PlayerNumber;
                    memTemp.DayJob = mem.Member.DayJob;

                    if (mem.Member.ContactCard != null && mem.Member.ContactCard.Communications.Count > 0)
                    {
                        var com = mem.Member.ContactCard.Communications.Where(x => x.IsDefault == true).Where(x => x.CommunicationTypeEnum == (byte)CommunicationTypeEnum.PhoneNumber).FirstOrDefault();
                        if (com != null)
                        {
                            memTemp.PhoneNumber = com.Data;
                            memTemp.SMSVerificationNum = com.SMSVerificationCode;
                            memTemp.Carrier = (MobileServiceProvider)com.CarrierType;
                            memTemp.IsCarrierVerified = com.IsCarrierVerified;
                        }

                    }
                    if (mem.Member.ContactCard != null && mem.Member.ContactCard.Addresses.Count > 0)
                    {
                        foreach (var add in mem.Member.ContactCard.Addresses)
                        {
                            var address =new RDN.Portable.Classes.ContactCard.Address();
                            address.AddressId = add.AddressId;
                            address.Address1 = add.Address1;
                            address.Address2 = add.Address2;
                            address.CityRaw = add.CityRaw;
                            if (add.Country != null)
                                address.Country = add.Country.Code;
                            address.StateRaw = add.StateRaw;
                            address.Zip = add.Zip;
                            if (add.Coords != null)
                            {
                                address.Coords = new Portable.Classes.Location.GeoCoordinate();
                                address.Coords.Latitude = add.Coords.Latitude;
                                address.Coords.Longitude = add.Coords.Longitude;
                            }

                            memTemp.ContactCard.Addresses.Add(address);
                        }
                    }

                    if (mem.League != null)
                    {
                        RDN.Portable.Classes.League.Classes.League l = new RDN.Portable.Classes.League.Classes.League();
                        l.LeagueId = mem.League.LeagueId;
                        l.Name = mem.League.Name;
                        l.DepartureDate = mem.DepartureDate;
                        l.SkillsTestDate = mem.SkillsTestDate;
                        if (mem.Member.CurrentLeagueId == l.LeagueId)
                        {
                            memTemp.IsInactiveFromCurrentLeague = mem.IsInactiveForLeague;
                            if (mem.SkaterClass != null)
                                memTemp.LeagueClassificationOfSkatingLevel = mem.SkaterClass.ClassName;
                        }

                        l.LeagueOwnersEnum = (LeagueOwnersEnum)mem.LeagueOwnersEnums;
                        if (mem.Member.CurrentLeagueId == l.LeagueId)
                            memTemp.LeagueOwnersEnum = l.LeagueOwnersEnum;
                        l.IsInactiveInLeague = mem.IsInactiveForLeague;
                        if (mem.SkaterClass != null)
                        {
                            l.SkaterClass = mem.SkaterClass.ClassId;
                            //l.SkaterLevel = mem.SkaterClass.ClassName;
                        }
                        memTemp.Leagues.Add(l);
                    }


                    if (mem.Member.AspNetUserId != null && mem.Member.AspNetUserId != new Guid())
                    {
                        memTemp.UserId = mem.Member.AspNetUserId;
                        memTemp.IsConnected = true;
                    }
                    else
                    {
                        memTemp.IsConnected = false;
                        memTemp.VerificationCode = mem.Member.MemberId.ToString().Replace("-", "") + mem.Member.Gender.ToString();
                    }

                    foreach (var photo in mem.Member.Photos.OrderBy(x => x.Created))
                    {
                        memTemp.Photos.Add(new PhotoItem(photo.ImageUrl, photo.ImageUrlThumb, photo.IsPrimaryPhoto, mem.Member.DerbyName));
                    }

                    foreach (var numb in mem.Member.InsuranceNumbers)
                    {
                        if (numb.InsuranceType == Convert.ToInt32(InsuranceProviderEnum.Other))
                        {
                            memTemp.InsuranceNumOther = numb.InsuranceNumber;
                            memTemp.InsuranceNumOtherExpires = numb.Expires;
                        }
                        else if (numb.InsuranceType == Convert.ToInt32(InsuranceProviderEnum.USARS))
                        {
                            memTemp.InsuranceNumUsars = numb.InsuranceNumber;
                            memTemp.InsuranceNumUsarsExpires = numb.Expires;
                        }
                        else if (numb.InsuranceType == Convert.ToInt32(InsuranceProviderEnum.WFTDA))
                        {
                            memTemp.InsuranceNumWftda = numb.InsuranceNumber;
                            memTemp.InsuranceNumWftdaExpires = numb.Expires;
                        }
                        else if (numb.InsuranceType == Convert.ToInt32(InsuranceProviderEnum.CRDI))
                        {
                            memTemp.InsuranceNumCRDI = numb.InsuranceNumber;
                            memTemp.InsuranceNumCRDIExpires = numb.Expires;
                        }
                    }

                    MedicalInformationFactory.AttachMemberMedicalInformation(mem.Member, memTemp);
                    memTemp.Settings = MemberSettingsFactory.DisplayMemberSettings(mem.Member.Settings);
                    membersReturned.Add(memTemp);

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

            }
            return membersReturned;
        }
        public static List<RDN.Portable.Classes.Location.Location> GetLocationsOfCalendar(Guid calendarId)
        {
            List<RDN.Portable.Classes.Location.Location> newLocations = new List<Portable.Classes.Location.Location>();
            try
            {
                var dc = new ManagementContext();
                var locations = (from xx in dc.Calendar
                                 where xx.CalendarId == calendarId
                                 select new
                                 {
                                     xx.CalendarEvents,
                                     xx.Locations
                                 }).FirstOrDefault();

                foreach (var loc in locations.Locations.Where(x => x.IsRemoved == false))
                {
                    try
                    {
                        RDN.Portable.Classes.Location.Location l = new Portable.Classes.Location.Location();
                        l.LocationName = loc.LocationName;
                        l.LocationId = loc.LocationId;
                        if (loc.Contact != null && loc.Contact.Addresses.FirstOrDefault() != null)
                        {
                            var add = loc.Contact.Addresses.FirstOrDefault();
                            RDN.Portable.Classes.ContactCard.Address a = new RDN.Portable.Classes.ContactCard.Address();
                            a.Address1 = add.Address1;
                            a.Address2 = add.Address2;
                            a.AddressId = add.AddressId;
                            a.CityRaw = add.CityRaw;
                            if (add.Country != null)
                                a.Country = add.Country.Code;
                            a.IsDefault = add.IsDefault;
                            a.StateRaw = add.StateRaw;
                            a.Zip = add.Zip;
                            l.Contact.Addresses.Add(a);
                        }
                        if (newLocations.Where(x => x.LocationId == l.LocationId).FirstOrDefault() == null)
                            newLocations.Add(l);
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }
                foreach (var loc in locations.CalendarEvents)
                {
                    try
                    {
                        if (loc.Location != null)
                        {
                            RDN.Portable.Classes.Location.Location l = new Portable.Classes.Location.Location();
                            l.LocationName = loc.Location.LocationName;
                            l.LocationId = loc.Location.LocationId;
                            if (loc.Location.Contact != null && loc.Location.Contact.Addresses.FirstOrDefault() != null)
                            {
                                var add = loc.Location.Contact.Addresses.FirstOrDefault();
                                RDN.Portable.Classes.ContactCard.Address a = new RDN.Portable.Classes.ContactCard.Address();
                                a.Address1 = add.Address1;
                                a.Address2 = add.Address2;
                                a.AddressId = add.AddressId;
                                a.CityRaw = add.CityRaw;
                                if (add.Country != null)
                                    a.Country = add.Country.Code;
                                a.IsDefault = add.IsDefault;
                                a.StateRaw = add.StateRaw;
                                a.Zip = add.Zip;
                                l.Contact.Addresses.Add(a);
                            }
                            if (newLocations.Where(x => x.LocationId == l.LocationId).FirstOrDefault() == null)
                                newLocations.Add(l);
                        }
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return newLocations;
        }
 public static RDN.Portable.Classes.Location.Location DisplayLocation(DataModels.Location.Location loc)
 {
     RDN.Portable.Classes.Location.Location l = new RDN.Portable.Classes.Location.Location();
     try
     {
         if (loc != null)
         {
             l.LocationName = loc.LocationName;
             l.LocationId = loc.LocationId;
             if (loc.Contact != null && loc.Contact.Addresses.FirstOrDefault() != null)
             {
                 var add = loc.Contact.Addresses.FirstOrDefault();
                 RDN.Portable.Classes.ContactCard.Address a = new RDN.Portable.Classes.ContactCard.Address();
                 a.Address1 = add.Address1;
                 a.Address2 = add.Address2;
                 a.AddressId = add.AddressId;
                 a.CityRaw = add.CityRaw;
                 if (add.Country != null)
                     a.Country = add.Country.Code;
                 a.IsDefault = add.IsDefault;
                 a.StateRaw = add.StateRaw;
                 a.Zip = add.Zip;
                 l.Contact.Addresses.Add(a);
             }
         }
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return l;
 }
Example #4
0
        /// <summary>
        /// builds up the member object to display out to the world.
        /// </summary>
        /// <param name="memberId"></param>
        /// <returns></returns>
        public static MemberDisplay GetMemberDisplay(Guid memberId, bool isPublicProfile = false, bool pullGameData = true)
        {
            try
            {
                var dc = new ManagementContext();
                var member = dc.Members.Include("Notifications").Include("Settings").Include("Leagues").Include("Leagues.SkaterClass").Include("InsuranceNumbers").Include("ContactCard").Include("ContactCard.Emails").Include("ContactCard.Communications").Include("Photos").Include("Federations").Include("MedicalInformation").FirstOrDefault(x => x.MemberId.Equals(memberId));
                if (member == null)
                    return null;



                MemberDisplay mem = new MemberDisplay();

                mem.IsProfileRemovedFromPublicView = member.IsProfileRemovedFromPublic;
                if (member.IsProfileRemovedFromPublic && isPublicProfile)
                    return null;

                foreach (var photo in member.Photos.OrderBy(x => x.Created))
                {
                    mem.Photos.Add(new PhotoItem(photo.ImageUrl, photo.IsPrimaryPhoto, member.DerbyName));
                }
                if (member.YearStartedSkating != null && member.YearStartedSkating != new DateTime())
                    mem.StartedSkating = member.YearStartedSkating.Value;
                else
                    mem.StartedSkating = null;
                if (member.YearStoppedSkating != null && member.YearStoppedSkating != new DateTime())
                    mem.StoppedSkating = member.YearStoppedSkating.Value;
                else
                    mem.StoppedSkating = null;

                mem.CurrentLeagueId = member.CurrentLeagueId;
                mem.IsRetired = member.Retired;
                mem.Firstname = member.Firstname;
                mem.DerbyName = member.DerbyName;
                mem.DerbyNameUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/roller-derby-skater/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(member.DerbyName) + "/" + member.MemberId.ToString().Replace("-", "");
                mem.MemberId = memberId;
                mem.UserId = member.AspNetUserId;
                mem.DayJob = member.DayJob;
                var user = Membership.GetUser((object)member.AspNetUserId);
                if (user != null)
                    mem.UserName = user.UserName;
                mem.IsNotConnectedToDerby = member.IsNotConnectedToDerby;

                mem.Email = ExtractEmailFromContactCard(member);
                if (member.ContactCard.Addresses.Count > 0)
                {
                    foreach (var add in member.ContactCard.Addresses)
                    {
                        var address = new RDN.Portable.Classes.ContactCard.Address();
                        address.AddressId = add.AddressId;
                        address.Address1 = add.Address1;
                        address.Address2 = add.Address2;
                        address.CityRaw = add.CityRaw;
                        if (add.Country != null)
                            address.Country = add.Country.Code;
                        address.StateRaw = add.StateRaw;
                        address.Zip = add.Zip;
                        address.Type = (AddressTypeEnum)add.AddressType;

                        mem.ContactCard.Addresses.Add(address);
                    }
                }
                GenderEnum gen;
                if (Enum.TryParse<GenderEnum>(member.Gender.ToString(), out gen))
                    mem.Gender = gen;
                mem.LastName = member.Lastname;
                mem.Bio = member.Bio;
                mem.DefaultPositionType = (DefaultPositionEnum)Enum.Parse(typeof(DefaultPositionEnum), member.PositionType.ToString());
                mem.BioHtml = member.Bio;

                if (member.DateOfBirth.HasValue)
                    mem.DOB = member.DateOfBirth.Value;

                mem.WeightLbs = member.WeightInLbs;

                if (member.HeightInches != 0)
                {
                    mem.HeightFeet = (int)(member.HeightInches / 12);
                    mem.HeightInches = (int)(member.HeightInches % 12);
                }

                DisplayInsuranceNumbers(member.InsuranceNumbers, mem);
                DisplayMemberNotifications(member.Notifications, mem);

                mem.Settings = MemberSettingsFactory.DisplayMemberSettings(member.Settings);

                foreach (var memberContact in member.MemberContacts)
                {
                    try
                    {
                        RDN.Portable.Classes.Account.Classes.MemberContact contact = new RDN.Portable.Classes.Account.Classes.MemberContact();
                        contact.ContactId = memberContact.ContactId;
                        contact.Firstname = memberContact.Firstname;
                        contact.Lastname = memberContact.Lastname;
                        contact.ContactType = (MemberContactTypeEnum)Enum.Parse(typeof(MemberContactTypeEnum), memberContact.ContactTypeEnum.ToString());
                        if (memberContact.ContactCard != null)
                        {
                            if (memberContact.ContactCard.Emails.Count > 0)
                                contact.Email = memberContact.ContactCard.Emails.Where(x => x.IsDefault == true).FirstOrDefault().EmailAddress;
                            if (memberContact.ContactCard.Communications.Count > 0)
                            {
                                contact.PhoneNumber = memberContact.ContactCard.Communications.FirstOrDefault().Data;
                                contact.SMSVerificationNum = memberContact.ContactCard.Communications.FirstOrDefault().SMSVerificationCode;
                                contact.Carrier = (MobileServiceProvider)memberContact.ContactCard.Communications.FirstOrDefault().CarrierType;
                            }
                            if (memberContact.ContactCard.Addresses.Count > 0)
                            {
                                contact.Addresses = new List<Portable.Classes.ContactCard.Address>();

                                foreach (var add in memberContact.ContactCard.Addresses)
                                {
                                    var address = new RDN.Portable.Classes.ContactCard.Address();
                                    address.Address1 = add.Address1;
                                    address.Address2 = add.Address2;
                                    address.CityRaw = add.CityRaw;
                                    if (add.Country != null)
                                        address.Country = add.Country.Code;
                                    address.StateRaw = add.StateRaw;
                                    address.Zip = add.Zip;
                                    address.Type = (AddressTypeEnum)add.AddressType;
                                    contact.Addresses.Add(address);
                                }
                            }
                        }
                        mem.MemberContacts.Add(contact);
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }

                if (member.ContactCard.Communications.Count > 0)
                {
                    var com = member.ContactCard.Communications.Where(x => x.IsDefault == true).Where(x => x.CommunicationTypeEnum == (byte)CommunicationTypeEnum.PhoneNumber).FirstOrDefault();
                    if (com != null)
                    {
                        mem.PhoneNumber = com.Data;
                        mem.SMSVerificationNum = com.SMSVerificationCode;
                        mem.Carrier = (MobileServiceProvider)com.CarrierType;
                        mem.IsCarrierVerified = com.IsCarrierVerified;
                    }
                }
                mem.PlayerNumber = member.PlayerNumber;
                if (member.Leagues.Count > 0)
                {
                    foreach (var league in member.Leagues)
                    {
                        RDN.Portable.Classes.League.Classes.League l = new Portable.Classes.League.Classes.League();
                        l.LeagueId = league.League.LeagueId;
                        l.Name = league.League.Name;
                        l.IsInactiveInLeague = league.IsInactiveForLeague;
                        l.DepartureDate = league.DepartureDate;
                        l.MembershipDate = league.MembershipDate;
                        l.SkillsTestDate = league.SkillsTestDate;
                        l.HasLeftLeague = league.HasLeftLeague;
                        l.NotesAboutMember = league.Notes;
                        l.NameUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION_FOR_LEAGUES + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(l.Name) + "/" + l.LeagueId.ToString().Replace("-", "");
                        l.LeagueOwnersEnum = (LeagueOwnersEnum)league.LeagueOwnersEnums;
                        if (l.LeagueId == mem.CurrentLeagueId)
                        {
                            mem.LeagueOwnersEnum = l.LeagueOwnersEnum;
                            mem.DoesReceiveLeagueNotifications = !league.TurnOffEmailNotifications;
                        }
                        if (league.SkaterClass != null)
                            l.SkaterClass = league.SkaterClass.ClassId;
                        else
                            l.SkaterClass = 0;

                        mem.Leagues.Add(l);
                    }
                }

                MedicalInformationFactory.AttachMemberMedicalInformation(member, mem);

                foreach (var fed in member.Federations)
                {
                    FederationDisplay fedDisplay = new FederationDisplay();
                    fedDisplay.FederationId = fed.Federation.FederationId;
                    fedDisplay.FederationName = fed.Federation.Name;
                    fedDisplay.MADEClassRank = ((MADEClassRankEnum)Enum.ToObject(typeof(MADEClassRankEnum), fed.MADEClassRankForMember)).ToString();
                    fedDisplay.MemberType = ((MemberTypeFederationEnum)Enum.ToObject(typeof(MemberTypeFederationEnum), fed.MemberType)).ToString();
                    var ownersOfFed = fed.Federation.Owners.Where(x => x.Member == member).FirstOrDefault();
                    if (ownersOfFed == null)
                        fedDisplay.OwnerType = FederationOwnerEnum.None.ToString();
                    else
                        fedDisplay.OwnerType = ((FederationOwnerEnum)Enum.ToObject(typeof(FederationOwnerEnum), ownersOfFed.OwnerType)).ToString();

                    if (fed.MembershipDate != null && fed.MembershipDate != new DateTime())
                        fedDisplay.MembershipDate = fed.MembershipDate.Value;
                    else
                        fedDisplay.MembershipDate = DateTime.UtcNow;
                    fedDisplay.MembershipId = fed.FederationIdForMember;
                    mem.FederationsApartOf.Add(fedDisplay);
                }
                if (pullGameData)
                    GetGameStats(memberId, dc, mem);
                return mem;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;
        }