protected void btnAddStudent_Click(object sender, EventArgs e)
 {
     if (!Page.IsValid)
     {
         return;
     }
     try
     {
         Profile pf = Profile.GetUser(Page.User.Identity.Name);
         if (String.IsNullOrEmpty(pf.Certificate) && !String.IsNullOrEmpty(txtCertificate.Text))
         {
             pf.Certificate           = txtCertificate.Text.LimitTo(30);
             pf.CertificateExpiration = mfbTypeInDateCFIExpiration.Date;
             pf.FCommit();
         }
         CFIStudentMapRequest smr = m_sm.GetRequest(CFIStudentMapRequest.RoleType.RoleStudent, txtStudentEmail.Text);
         smr.Send();
         lblAddStudentSuccess.Text     = String.Format(CultureInfo.CurrentCulture, Resources.Profile.EditProfileRequestHasBeenSent, HttpUtility.HtmlEncode(txtStudentEmail.Text));
         lblAddStudentSuccess.CssClass = "success";
         txtStudentEmail.Text          = "";
     }
     catch (MyFlightbookException ex)
     {
         lblAddStudentSuccess.Text     = ex.Message;
         lblAddStudentSuccess.CssClass = "error";
     }
 }
示例#2
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);
            }
        }
 protected void btnAddInstructor_Click(object sender, EventArgs e)
 {
     if (!Page.IsValid)
     {
         return;
     }
     try
     {
         CFIStudentMapRequest smr = m_sm.GetRequest(CFIStudentMapRequest.RoleType.RoleCFI, txtInstructorEmail.Text);
         smr.Send();
         lblAddInstructorSuccess.Text     = String.Format(CultureInfo.CurrentCulture, Resources.Profile.EditProfileRequestHasBeenSent, HttpUtility.HtmlEncode(txtInstructorEmail.Text));
         lblAddInstructorSuccess.CssClass = "success";
         txtInstructorEmail.Text          = "";
     }
     catch (MyFlightbookException ex)
     {
         lblAddInstructorSuccess.Text     = ex.Message;
         lblAddInstructorSuccess.CssClass = "error";
     }
 }
        protected void wzRequestSigs_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            IEnumerable <LogbookEntry> lstFlights = SelectedFlights;

            string szCFIUsername = String.Empty;
            string szCFIEmail    = String.Empty;

            MyFlightbook.Profile pfCFI = null;


            bool fIsNewCFI = String.IsNullOrEmpty(cmbInstructors.SelectedValue);

            // Check In case the named email is already an instructor.
            CFIStudentMap sm = new CFIStudentMap(User.Identity.Name);

            if (fIsNewCFI && sm.IsStudentOf(txtCFIEmail.Text))
            {
                fIsNewCFI = false;
                foreach (InstructorStudent inst in sm.Instructors)
                {
                    if (String.Compare(inst.Email, txtCFIEmail.Text, StringComparison.CurrentCultureIgnoreCase) == 0)
                    {
                        pfCFI = inst;
                        break;
                    }
                }
            }
            else
            {
                pfCFI = MyFlightbook.Profile.GetUser(cmbInstructors.SelectedValue);
            }

            if (fIsNewCFI)
            {
                szCFIEmail = txtCFIEmail.Text;
            }
            else
            {
                szCFIUsername = pfCFI.UserName;
            }

            // check if we already know the email

            foreach (LogbookEntry le in lstFlights)
            {
                le.RequestSignature(szCFIUsername, szCFIEmail);
            }

            // Now send the email
            if (fIsNewCFI)
            {
                CFIStudentMapRequest smr = sm.GetRequest(CFIStudentMapRequest.RoleType.RoleCFI, szCFIEmail);
                smr.Send();
            }
            else
            {
                Profile pf = MyFlightbook.Profile.GetUser(User.Identity.Name);
                using (MailMessage msg = new MailMessage())
                {
                    msg.From = new MailAddress(Branding.CurrentBrand.EmailAddress, String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.SignOff.EmailSenderAddress, Branding.CurrentBrand.AppName, pf.UserFullName));
                    msg.ReplyToList.Add(new MailAddress(pf.Email, pf.UserFullName));
                    msg.To.Add(new MailAddress(pfCFI.Email, pfCFI.UserFullName));
                    msg.Subject = String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.SignOff.SignRequestSubject, pf.UserFullName, Branding.CurrentBrand.AppName);

                    string szURL = String.Format(System.Globalization.CultureInfo.InvariantCulture, "https://{0}{1}/{2}", Request.Url.Host, ResolveUrl("~/Member/Training.aspx"), tabID.instStudents.ToString());

                    msg.Body = Branding.ReBrand(Resources.SignOff.SignInvitationExisting).Replace("<% SignPendingFlightsLink %>", szURL).Replace("<% Requestor %>", pf.UserFullName);
                    util.SendMessage(msg);
                }
            }

            Response.Redirect(String.Format(System.Globalization.CultureInfo.InvariantCulture, "~/Member/Training.aspx/{0}", tabID.instSignFlights));
        }