protected void lnkSelect_Command(object sender, CommandEventArgs e)
        {
            int targetLoginID = Int32.Parse(e.CommandArgument.ToString());

            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                var primaryIdentity   = db.Logins.FirstOrDefault(p => p.Id == PrimaryLoginID).Identity;
                var secondaryIdentity = db.Logins.FirstOrDefault(p => p.Id == targetLoginID).Identity;

                DataAccess.Identity.MergeIdentities(db, new DataAccess.Identity[] { primaryIdentity, secondaryIdentity });

                db.SubmitChanges();
            }

            Response.Redirect("~/Users/ManageLinks.aspx?loginID=" + PrimaryLoginID + "&searchText=" + Server.UrlEncode(Request.Params["searchText"]), true);
        }
        protected void lnkSelect_Command(object sender, CommandEventArgs e)
        {
            int targetLoginID = Int32.Parse(e.CommandArgument.ToString());

            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                var primaryIdentity = db.Logins.FirstOrDefault(p => p.Id == PrimaryLoginID).Identity;
                var secondaryIdentity = db.Logins.FirstOrDefault(p => p.Id == targetLoginID).Identity;

                DataAccess.Identity.MergeIdentities(db, new DataAccess.Identity[] { primaryIdentity, secondaryIdentity });

                db.SubmitChanges();
            }

            Response.Redirect("~/Users/ManageLinks.aspx?loginID=" + PrimaryLoginID + "&searchText=" + Server.UrlEncode(Request.Params["searchText"]), true);
        }
        private void RemoveCallsignFromGroup(string callsign, int groupID)
        {
            Business.GroupRole currentUserGroupRole = GetCurrentUserGroupRole(groupID);

            if (currentUserGroupRole != Business.GroupRole.AssistantSquadLeader && currentUserGroupRole != Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.ZoneLead)
            {
                throw new Exception("Access denied.");
            }

            Business.GroupRole callsignGroupRole = GetGroupRoleForCallsign(callsign, groupID);

            if (callsignGroupRole == Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.ZoneLead)
            {
                throw new Exception("Only squad leaders can perform this action.");
            }

            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                var alias = DataAccess.Alias.GetAliasByCallsign(db, callsign);
                var callsignAssignmentsToGroup = db.Group_Alias_GroupRoles.Where(p => p.GroupId == groupID && p.Alias.Id == alias.Id);

                db.Group_Alias_GroupRoles.DeleteAllOnSubmit(callsignAssignmentsToGroup);

                var group = db.Groups.FirstOrDefault(p => p.Id == groupID);
                if (group == null)
                {
                    throw new Exception("invalid group: " + groupID);
                }

                // If the group name is the Moderators group, then add the Moderator role to the group member.
                if (group.Name.Equals("Moderators", StringComparison.InvariantCultureIgnoreCase) == true)
                {
                    var moderatorRole = db.Roles.FirstOrDefault(p => p.Name == "Moderator");
                    db.Login_Roles.DeleteAllOnSubmit(db.Login_Roles.Where(p => p.LoginId == alias.LoginId && p.RoleId == moderatorRole.Id));
                }

                //  If the group is ACS, then unbank the original hider.
                if (group.Tag.Equals("acs", StringComparison.InvariantCultureIgnoreCase) == true)
                {
                    UnbankAlias(db, alias);
                }

                db.SubmitChanges();
            }

            Response.Redirect("~/Squads/Default.aspx?groupID=" + groupID, true);
        }
        protected void lnkRemovePermanentUnlink_Command(object sender, CommandEventArgs e)
        {
            int loginID = Int32.Parse(e.CommandArgument.ToString());

            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                var permanentUnlink = db.Login_UnlinkedLogins
                    .FirstOrDefault(p => (p.LoginId1 == PrimaryLoginID && p.LoginId2 == loginID) || (p.LoginId1 == loginID && p.LoginId2 == PrimaryLoginID));

                if (permanentUnlink != null)
                {
                    db.Login_UnlinkedLogins.DeleteOnSubmit(permanentUnlink);
                    db.SubmitChanges();
                }
            }

            BindData();
        }
        protected void lnkRemovePermanentUnlink_Command(object sender, CommandEventArgs e)
        {
            int loginID = Int32.Parse(e.CommandArgument.ToString());

            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                var permanentUnlink = db.Login_UnlinkedLogins
                                      .FirstOrDefault(p => (p.LoginId1 == PrimaryLoginID && p.LoginId2 == loginID) || (p.LoginId1 == loginID && p.LoginId2 == PrimaryLoginID));

                if (permanentUnlink != null)
                {
                    db.Login_UnlinkedLogins.DeleteOnSubmit(permanentUnlink);
                    db.SubmitChanges();
                }
            }

            BindData();
        }
        protected void lnkPermanentUnlink_Click(object sender, CommandEventArgs e)
        {
            int unlinkLoginID = Int32.Parse(e.CommandArgument.ToString());

            UnlinkLogins(PrimaryLoginID, unlinkLoginID);

            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                DataAccess.Login_UnlinkedLogin unlinkRecord = new Allegiance.CommunitySecuritySystem.DataAccess.Login_UnlinkedLogin()
                {
                    LoginId1 = PrimaryLoginID,
                    LoginId2 = unlinkLoginID
                };

                db.Login_UnlinkedLogins.InsertOnSubmit(unlinkRecord);

                db.SubmitChanges();
            }

            BindData();
        }
        protected void lnkPermanentUnlink_Click(object sender, CommandEventArgs e)
        {
            int unlinkLoginID = Int32.Parse(e.CommandArgument.ToString());

            UnlinkLogins(PrimaryLoginID, unlinkLoginID);

            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                DataAccess.Login_UnlinkedLogin unlinkRecord = new Allegiance.CommunitySecuritySystem.DataAccess.Login_UnlinkedLogin()
                {
                    LoginId1 = PrimaryLoginID,
                    LoginId2 = unlinkLoginID
                };

                db.Login_UnlinkedLogins.InsertOnSubmit(unlinkRecord);

                db.SubmitChanges();
            }

            BindData();
        }
        private void RemoveCallsignFromGroup(string callsign, int groupID)
        {
            Business.GroupRole currentUserGroupRole = GetCurrentUserGroupRole(groupID);

            if (currentUserGroupRole != Business.GroupRole.AssistantSquadLeader && currentUserGroupRole != Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.ZoneLead)
                throw new Exception("Access denied.");

            Business.GroupRole callsignGroupRole = GetGroupRoleForCallsign(callsign, groupID);

            if (callsignGroupRole == Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.ZoneLead)
                throw new Exception("Only squad leaders can perform this action.");

            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                var alias = DataAccess.Alias.GetAliasByCallsign(db, callsign);
                var callsignAssignmentsToGroup = db.Group_Alias_GroupRoles.Where(p => p.GroupId == groupID && p.Alias.Id == alias.Id);

                db.Group_Alias_GroupRoles.DeleteAllOnSubmit(callsignAssignmentsToGroup);

                var group = db.Groups.FirstOrDefault(p => p.Id == groupID);
                if (group == null)
                    throw new Exception("invalid group: " + groupID);

                // If the group name is the Moderators group, then add the Moderator role to the group member.
                if (group.Name.Equals("Moderators", StringComparison.InvariantCultureIgnoreCase) == true)
                {
                    var moderatorRole = db.Roles.FirstOrDefault(p => p.Name == "Moderator");
                    db.Login_Roles.DeleteAllOnSubmit(db.Login_Roles.Where(p => p.LoginId == alias.LoginId && p.RoleId == moderatorRole.Id));
                }

                //  If the group is ACS, then unbank the original hider.
                if (group.Tag.Equals("acs", StringComparison.InvariantCultureIgnoreCase) == true)
                    UnbankAlias(db, alias);

                db.SubmitChanges();
            }

            Response.Redirect("~/Squads/Default.aspx?groupID=" + groupID, true);
        }