Exemplo n.º 1
0
        protected void gvMembers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            ClubMember cm = CurrentClub.Members.FirstOrDefault(pf => pf.UserName.CompareOrdinalIgnoreCase(e.Keys[0].ToString()) == 0);

            if (cm != null)
            {
                GridViewRow               gvr           = gvMembers.Rows[e.RowIndex];
                RadioButtonList           rbl           = (RadioButtonList)gvr.FindControl("rblRole");
                ClubMember.ClubMemberRole requestedRole = (ClubMember.ClubMemberRole)Enum.Parse(typeof(ClubMember.ClubMemberRole), rbl.SelectedValue);
                cm.IsMaintanenceOfficer = ((CheckBox)gvr.FindControl("ckMaintenanceOfficer")).Checked;
                cm.IsTreasurer          = ((CheckBox)gvr.FindControl("ckTreasurer")).Checked;
                cm.IsInsuranceOfficer   = ((CheckBox)gvr.FindControl("ckInsuranceOfficer")).Checked;
                cm.ClubOffice           = ((TextBox)gvr.FindControl("txtOffice")).Text.Trim();

                bool fResult = true;
                try
                {
                    if (requestedRole == ClubMember.ClubMemberRole.Owner) // that's fine, but we need to un-make any other creators
                    {
                        ClubMember cmOldOwner = CurrentClub.Members.FirstOrDefault(pf => pf.RoleInClub == ClubMember.ClubMemberRole.Owner);
                        if (cmOldOwner != null) //should never happen!
                        {
                            cmOldOwner.RoleInClub = ClubMember.ClubMemberRole.Admin;
                            if (!cmOldOwner.FCommitClubMembership())
                            {
                                throw new MyFlightbookException(cmOldOwner.LastError);
                            }
                        }
                    }
                    else if (cm.RoleInClub == ClubMember.ClubMemberRole.Owner)    // if we're not requesting creator role, but this person currently is creator, then we are demoting - that's a no-no
                    {
                        throw new MyFlightbookException(Resources.Club.errCantDemoteOwner);
                    }

                    cm.RoleInClub = requestedRole;
                    if (!cm.FCommitClubMembership())
                    {
                        throw new MyFlightbookException(cm.LastError);
                    }
                }
                catch (MyFlightbookException ex)
                {
                    lblManageMemberError.Text = ex.Message;
                    fResult = false;
                }

                if (fResult)
                {
                    refreshAdminMembers(-1);
                }
            }
        }
Exemplo n.º 2
0
    protected void gvMembers_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException("e");
        }
        ClubMember cm = CurrentClub.Members.FirstOrDefault(pf => pf.UserName.CompareTo(e.Keys[0].ToString()) == 0);

        if (cm != null)
        {
            RadioButtonList           rbl           = (RadioButtonList)gvMembers.Rows[e.RowIndex].FindControl("rblRole");
            ClubMember.ClubMemberRole requestedRole = (ClubMember.ClubMemberRole)Enum.Parse(typeof(ClubMember.ClubMemberRole), rbl.SelectedValue);

            bool fResult = true;
            try
            {
                if (requestedRole != cm.RoleInClub)                       // check to see if anything changed
                {
                    if (requestedRole == ClubMember.ClubMemberRole.Owner) // that's fine, but we need to un-make any other creators
                    {
                        ClubMember cmOldOwner = CurrentClub.Members.FirstOrDefault(pf => pf.RoleInClub == ClubMember.ClubMemberRole.Owner);
                        if (cmOldOwner != null) //should never happen!
                        {
                            cmOldOwner.RoleInClub = ClubMember.ClubMemberRole.Admin;
                            if (!cmOldOwner.FCommitClubMembership())
                            {
                                throw new MyFlightbookException(cmOldOwner.LastError);
                            }
                        }
                    }
                    else if (cm.RoleInClub == ClubMember.ClubMemberRole.Owner)    // if we're not requesting creator role, but this person currently is creator, then we are demoting - that's a no-no
                    {
                        throw new MyFlightbookException(Resources.Club.errCantDemoteOwner);
                    }

                    cm.RoleInClub = requestedRole;
                    if (!cm.FCommitClubMembership())
                    {
                        throw new MyFlightbookException(cm.LastError);
                    }
                }
            }
            catch (MyFlightbookException ex)
            {
                lblManageMemberError.Text = ex.Message;
                fResult = false;
            }

            if (fResult)
            {
                refreshAdminMembers(-1);
            }
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// Execute the request
        /// </summary>
        public void ExecuteRequest(CFIStudentMapRequest cmr)
        {
            if (cmr == null)
            {
                throw new ArgumentNullException(nameof(cmr));
            }
            Profile pf = Profile.GetUser(User);

            if (cmr.TargetUser.CompareOrdinalIgnoreCase(pf.Email) != 0 && !pf.IsVerifiedEmail(cmr.TargetUser))
            {
                throw new MyFlightbookValidationException(Resources.SignOff.errWrongAddress);
            }

            Profile pfRequestor = Profile.GetUser(cmr.RequestingUser);

            if (!pfRequestor.IsValid())
            {
                throw new MyFlightbookValidationException(Resources.SignOff.errUnknownRequestor);
            }

            switch (cmr.Requestedrole)
            {
            case CFIStudentMapRequest.RoleType.RoleCFI:
                // They are requesting that you (User) be a CFI, so they want to be the student.
                AddStudent(cmr.RequestingUser);
                break;

            case CFIStudentMapRequest.RoleType.RoleStudent:
                // They are requesting that you (User) be a student, so they want to be your CFI.
                AddInstructor(cmr.RequestingUser);
                break;

            case CFIStudentMapRequest.RoleType.RoleInviteJoinClub:
            case CFIStudentMapRequest.RoleType.RoleRequestJoinClub:
                if (cmr.ClubToJoin == null)
                {
                    throw new MyFlightbookException(Resources.Club.errNoClubInRequest);
                }
                ClubMember cm = new ClubMember(cmr.ClubToJoin.ID, cmr.Requestedrole == CFIStudentMapRequest.RoleType.RoleInviteJoinClub ? pf.UserName : pfRequestor.UserName, ClubMember.ClubMemberRole.Member);
                cm.FCommitClubMembership();
                break;

            default:
                throw new MyFlightbookValidationException(Resources.SignOff.errInvalidRequest);
            }
        }