/// <summary>
        /// approves the league and attaches owners and members to the league.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool ApproveLeague(string id)
        {
            int result = 0;
            try
            {
                Guid leagueId;
                var guidConversion = Guid.TryParse(id, out leagueId);
                if (!guidConversion)
                    return false;

                var dc = new ManagementContext();
                var pendingLeague = dc.LeaguePendings.Include("Creator").Include("Federation").Include("Country").FirstOrDefault(x => x.LeagueId.Equals(leagueId));
                if (pendingLeague == null)
                    return false;

                var contactCard = new DataModels.ContactCard.ContactCard();
                var add = new Address
                {
                    Country = pendingLeague.Country,
                    StateRaw = pendingLeague.StateRaw,
                    CityRaw = pendingLeague.CityRaw,
                    TimeZone = pendingLeague.TimeZone
                };

                var coords = OpenStreetMap.FindLatLongOfAddress(string.Empty, string.Empty, string.Empty, add.CityRaw, add.StateRaw, add.Country != null ? add.Country.Name : string.Empty);
                if (coords != null)
                {
                    add.Coords = new System.Device.Location.GeoCoordinate();
                    add.Coords.Latitude = coords.Latitude;
                    add.Coords.Longitude = coords.Longitude;
                    add.Coords.Altitude = 0;
                    add.Coords.Course = 0;
                    add.Coords.HorizontalAccuracy = 1;
                    add.Coords.Speed = 0;
                    add.Coords.VerticalAccuracy = 1;
                }
                else
                {
                    add.Coords = new System.Device.Location.GeoCoordinate();
                    add.Coords.Latitude = 0.0;
                    add.Coords.Longitude = 0.0;
                    add.Coords.Altitude = 0;
                    add.Coords.Course = 0;
                    add.Coords.HorizontalAccuracy = 1;
                    add.Coords.Speed = 0;
                    add.Coords.VerticalAccuracy = 1;
                }
                contactCard.Addresses.Add(add);

                contactCard.Emails.Add(new RDN.Library.DataModels.ContactCard.Email
                {
                    EmailAddress = pendingLeague.ContactEmail,
                    IsDefault = true
                });


                if (!String.IsNullOrEmpty(pendingLeague.ContactTelephone))
                {
                    var communication = new DataModels.ContactCard.Communication();
                    communication.Data = pendingLeague.ContactTelephone;
                    communication.IsDefault = true;
                    //int comType = Convert.ToInt32(CommunicationTypeEnum.PhoneNumber);
                    //communication.CommunicationType = dc.CommunicationType.Where(x => x.CommunicationTypeId == comType).FirstOrDefault();
                    communication.CommunicationTypeEnum = (byte)CommunicationTypeEnum.PhoneNumber;
                    contactCard.Communications.Add(communication);
                }

                var league = new DataModels.League.League
                {
                    ContactCard = contactCard,
                    Name = pendingLeague.LeagueName,
                    LoweredName = pendingLeague.LeagueName.ToLower(),
                    SubscriptionPeriodEnds = DateTime.UtcNow.AddDays(InvoiceSubscription.NUMBER_OF_DAYS_FOR_TRIAL_SUBSCRIPTION),
                    LeagueJoinCode = Guid.NewGuid(),
                    SubscriptionWillAutoRenew = false

                };


                //we clear it by hitting a URL setup to clear the cache.
                LeagueMember me = new LeagueMember();
                me.League = league;
                me.Member = pendingLeague.Creator;
                me.MembershipDate = DateTime.UtcNow;
                me.LeagueOwnersEnums = (int)LeagueOwnersEnum.Owner;
                league.Members.Add(me);

                if (pendingLeague.Federation != null)
                {
                    FederationLeague l = new FederationLeague();
                    l.Federation = pendingLeague.Federation;
                    l.League = league;
                    l.MembershipDate = DateTime.UtcNow;
                    league.Federations.Add(l);
                }

                //league.Members.Add(pendingLeague.Creator);
                dc.Leagues.Add(league);
                result = dc.SaveChanges();
                pendingLeague.Creator.CurrentLeagueId = league.LeagueId;
                result = dc.SaveChanges();

                //    var result = 1;
                if (result == 0)
                    return false;

                Forum.Forum.CreateNewForum(league.LeagueId, ForumOwnerTypeEnum.league, league.Name + "'s Forum");

                var defaultEmail = pendingLeague.Creator.ContactCard.Emails.FirstOrDefault(x => x.IsDefault.Equals(true));
                if (defaultEmail != null)
                {
                    var emailData = new Dictionary<string, string>();
                    emailData.Add("name", pendingLeague.Creator.Firstname);
                    emailData.Add("derbyname", pendingLeague.Creator.DerbyName);
                    emailData.Add("leaguename", pendingLeague.LeagueName);
                    EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, defaultEmail.EmailAddress, EmailServer.EmailServer.DEFAULT_SUBJECT + " Your league has been approved", emailData, EmailServer.EmailServerLayoutsEnum.LeagueApproved);
                }

                try
                {
                    WebClient client = new WebClient();
                    client.DownloadStringAsync(new Uri(ServerConfig.URL_TO_CLEAR_MEMBER_CACHE + pendingLeague.Creator.MemberId.ToString()));
                    WebClient client1 = new WebClient();
                    client1.DownloadStringAsync(new Uri(ServerConfig.URL_TO_CLEAR_MEMBER_CACHE_API + pendingLeague.Creator.MemberId.ToString()));
                }
                catch (Exception exception)
                {
                    ErrorDatabaseManager.AddException(exception, exception.GetType());
                }
                dc.LeaguePendings.Remove(pendingLeague);
                result = dc.SaveChanges();

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return result != 0;
        }
        public static Guid GetLeagueAndJoinWithJoinCode(Guid joinCode)
        {
            try
            {
                var dc = new ManagementContext();

                var league = dc.Leagues.Where(x => x.LeagueJoinCode == joinCode).FirstOrDefault();
                if (league == null)
                    return new Guid();

                var memId = RDN.Library.Classes.Account.User.GetMemberId();
                var mem = dc.Members.Where(x => x.MemberId == memId).FirstOrDefault();
                var oldMem = league.Members.Where(x => x.Member.MemberId == memId).FirstOrDefault();
                mem.IsNotConnectedToDerby = false;
                //if they are rejoining the league...
                if (oldMem != null)
                {
                    oldMem.Member = oldMem.Member;
                    oldMem.League = oldMem.League;
                    oldMem.HasLeftLeague = false;
                    mem.CurrentLeagueId = oldMem.League.LeagueId;
                }
                else //if they are new to the league.
                {
                    LeagueMember m = new LeagueMember();
                    m.League = league;
                    m.Member = mem;
                    m.MembershipDate = DateTime.UtcNow;
                    mem.CurrentLeagueId = league.LeagueId;
                    mem.Leagues.Add(m);
                    league.Members.Add(m);
                    dc.LeagueMembers.Add(m);
                }
                dc.SaveChanges();


                var owners = LeagueFactory.GetLeagueOwners(league.LeagueId);
                var o = owners.Where(x => x.LeagueOwnersEnum.HasFlag(LeagueOwnersEnum.Owner)).ToList();
                //notify the owners a new member just joined their league.
                o = o.DistinctBy(x => x.Email).ToList();
                foreach (var owner in o)
                {
                    try
                    {
                        var emailData = new Dictionary<string, string> { { "body", mem.DerbyName + " just connected to your league with the join code. They have been updated in your list of members." } };

                        EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, owner.Email, EmailServer.EmailServer.DEFAULT_SUBJECT + " " + mem.DerbyName + " joined your league", emailData, layout: EmailServer.EmailServerLayoutsEnum.Blank);
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }

                return league.LeagueId;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return new Guid();
        }
        public static bool ApprovePendingMember(string idRaw, Guid leagueId, string ip)
        {
            Guid id;
            var result = Guid.TryParse(idRaw, out id);
            if (!result) return false;

            var dc = new ManagementContext();
            var league = dc.Leagues.FirstOrDefault(x => x.LeagueId.Equals(leagueId));
            if (league == null) return false;

            var pendingMember = league.PendingMembers.FirstOrDefault(x => x.Member.MemberId.Equals(id));
            if (pendingMember == null) return false;

            // Get the member object seperatly since we are about to delete the pending member object
            var member = dc.Members.FirstOrDefault(x => x.MemberId.Equals(id));
            if (member == null) return false;
            LeagueMember m = new LeagueMember();
            m.Member = member;
            m.League = league;
            m.MembershipDate = DateTime.UtcNow;
            member.Leagues.Add(m);

            var leagueName = league.Name;

            dc.LeagueMemberPendings.Remove(pendingMember);

            result = dc.SaveChanges() > 0;

            User.AddMemberLog(id, "Leagion request accepted", string.Format("The league ' {0} ' with id: {1}, accepted the request to join the league.", leagueName, leagueId), MemberLogEnum.SystemStatusChanged, ip);

            return result;
        }
Beispiel #4
0
        private static DataModels.Member.Member CreateMemberAccount(ref ManagementContext dc, ref DataModels.League.League league, Guid userId, string firstname, string derbyName, int gender, int positionType, string lastName, string playerNumber, string email, string phoneNumber)
        {
            // Creates the member record (also adds the user to the league specified if one was found)
            Member member = new DataModels.Member.Member();
            try
            {
                member.MemberId = Guid.NewGuid();
                member.AspNetUserId = userId;
                member.Firstname = firstname;
                member.Lastname = lastName;
                member.PlayerNumber = playerNumber;
                member.DerbyName = derbyName;
                member.Gender = gender;
                member.PositionType = positionType;
                member.ContactCard = new DataModels.ContactCard.ContactCard();
                member.IsVerified = false;

                if (league != null)
                {
                    LeagueMember lm = new LeagueMember();
                    lm.Member = member;
                    lm.League = league;
                    lm.MembershipDate = DateTime.UtcNow;
                    member.Leagues.Add(lm);
                    member.League = league;
                    member.CurrentLeagueId = league.LeagueId;
                }

                if (!String.IsNullOrEmpty(email))
                {
                    member.ContactCard.Emails.Add(new RDN.Library.DataModels.ContactCard.Email { EmailAddress = email, IsDefault = true });

                }
                if (!String.IsNullOrEmpty(phoneNumber))
                {
                    int phoneType = Convert.ToInt32(CommunicationTypeEnum.PhoneNumber);
                    member.ContactCard.Communications.Add(new Communication
                    {
                        Data = phoneNumber,
                        IsDefault = true,
                        //CommunicationType = dc.CommunicationType.Where(x => x.CommunicationTypeId == phoneType).FirstOrDefault()
                        CommunicationTypeEnum = (byte)CommunicationTypeEnum.PhoneNumber
                    });
                }

                member = dc.Members.Add(member);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return member;
        }
Beispiel #5
0
        /// <summary>
        /// only updates certain things, so if we need to update more things of the member display, you need to add
        /// it to this method.  In the interest of time right now, thats how its working.
        /// </summary>
        /// <param name="member"></param>
        public static MemberDisplay UpdateMemberDisplayForFederation(MemberDisplay mem)
        {
            try
            {
                var dc = new ManagementContext();
                var member = dc.Members.Include("ContactCard").Include("ContactCard.Emails").Include("ContactCard.Communications").Include("Federations").FirstOrDefault(x => x.MemberId.Equals(mem.MemberId));
                if (member == null)
                    return mem;

                foreach (var league in mem.Leagues)
                {
                    if (league.LeagueMovedId != new Guid())
                    {
                        var le = dc.LeagueMembers.Where(x => x.Member.MemberId == mem.MemberId && x.League.LeagueId == league.LeagueId).FirstOrDefault();
                        if (le != null)
                            le.League = dc.Leagues.Where(x => x.LeagueId == league.LeagueMovedId).FirstOrDefault();
                        else
                        {
                            LeagueMember lm = new LeagueMember();
                            lm.League = dc.Leagues.Where(x => x.LeagueId == league.LeagueMovedId).FirstOrDefault();
                            lm.Member = dc.Members.Where(x => x.MemberId == mem.MemberId).FirstOrDefault();
                            dc.LeagueMembers.Add(lm);
                        }
                    }
                }

                member.DerbyName = mem.DerbyName;
                member.PlayerNumber = mem.PlayerNumber;
                member.Firstname = mem.Firstname;
                member.Lastname = mem.LastName;
                if (mem.StoppedSkating != new DateTime())
                    member.YearStoppedSkating = mem.StoppedSkating;
                if (mem.StartedSkating != new DateTime())
                    member.YearStartedSkating = mem.StartedSkating;

                UpdatePhoneNumberForMember(mem, dc, member);
                UpdateEmailForMember(mem, member);

                //updates the federation ownership and class rank for the federation
                foreach (var feds in mem.FederationsApartOf)
                {
                    try
                    {
                        var fed = member.Federations.Where(x => x.Federation.FederationId == feds.FederationId).FirstOrDefault();
                        fed.MADEClassRankForMember = Convert.ToInt32((MADEClassRankEnum)Enum.Parse(typeof(MADEClassRankEnum), feds.MADEClassRank));
                        fed.MemberType = Convert.ToInt32((MemberTypeFederationEnum)Enum.Parse(typeof(MemberTypeFederationEnum), feds.MemberType));
                        if (feds.MembershipDate != new DateTime())
                            fed.MembershipDate = feds.MembershipDate;
                        fed.FederationIdForMember = feds.MembershipId;
                        var fedOwner = member.FederationOwnership.Where(x => x.Federation.FederationId == feds.FederationId).FirstOrDefault();
                        if (fedOwner == null)
                        {
                            fedOwner = new FederationOwnership();
                            fedOwner.Federation = dc.Federations.Where(x => x.FederationId == feds.FederationId).FirstOrDefault();
                            fedOwner.IsVerified = true;
                            fedOwner.Member = member;
                            fedOwner.OwnerType = Convert.ToInt32((FederationOwnerEnum)Enum.Parse(typeof(FederationOwnerEnum), feds.OwnerType));
                            dc.FederationOwners.Add(fedOwner);
                        }
                        else
                        {
                            fedOwner.OwnerType = Convert.ToInt32((FederationOwnerEnum)Enum.Parse(typeof(FederationOwnerEnum), feds.OwnerType));
                        }

                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }
                int c = dc.SaveChanges();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return mem;
        }
Beispiel #6
0
 public static bool AddMemberToLeague(Guid memberId, Guid leagueId)
 {
     try
     {
         var dc = new ManagementContext();
         var mem = dc.Members.Where(x => x.MemberId == memberId).FirstOrDefault();
         if (mem != null)
         {
             mem.CurrentLeagueId = leagueId;
             mem.IsNotConnectedToDerby = false;
             var le = dc.Leagues.Where(x => x.LeagueId == leagueId).FirstOrDefault();
             LeagueMember l = new LeagueMember();
             l.League = le;
             l.Member = mem;
             l.LeagueOwnersEnums = (int)LeagueOwnersEnum.Owner;
             l.MembershipDate = DateTime.UtcNow;
             mem.Leagues.Add(l);
             var u = dc.SaveChanges();
             if (u == 0)
                 throw new Exception("Member Didn't Get Added " + memberId + " " + leagueId);
             return true;
         }
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return false;
 }