protected void SetUpStudents() { if (Request.IsMobileDevice()) { mfbIlOfflineEndorsements.Columns = 1; } mfuOfflineEndorsements.Class = MyFlightbook.Image.MFBImageInfo.ImageClass.OfflineEndorsement; mfbIlOfflineEndorsements.Key = Page.User.Identity.Name; mfbIlOfflineEndorsements.Refresh(); byte[] rgbDefaultScribble = CFIStudentMap.DefaultScribbleForInstructor(m_pf); mvDefaultSig.SetActiveView(vwCurrentSig); if (rgbDefaultScribble == null || rgbDefaultScribble.Length == 0) { lnkEditDefaultSig.Text = Resources.LocalizedText.StudentSigningDefaultScribbleAdd; imgCurrSig.Src = string.Empty; } else { imgCurrSig.Src = ScribbleImage.DataLinkForByteArray(rgbDefaultScribble); } Profile pf = Profile.GetUser(Page.User.Identity.Name); pnlCertificate.Visible = String.IsNullOrEmpty(pf.Certificate); txtCertificate.Text = pf.Certificate; mfbTypeInDateCFIExpiration.Date = pf.CertificateExpiration; mfbScribbleSignature.WatermarkRef = ResolveClientUrl("~/images/rubberstamp.png"); }
protected string GetUserName(out string szError) { szError = string.Empty; string szUser = Page.User.Identity.Name; // default value string szStudent = util.GetStringParam(Request, "u"); if (!String.IsNullOrEmpty(szStudent)) { // See if the current user is authorized to view print view of the specified user CFIStudentMap sm = new CFIStudentMap(Page.User.Identity.Name); InstructorStudent student = CFIStudentMap.GetInstructorStudent(sm.Students, szStudent); if (student == null) { szError = Resources.SignOff.ViewStudentNoSuchStudent; } else if (!student.CanViewLogbook) { szError = Resources.SignOff.ViewStudentLogbookUnauthorized; } else { szUser = szStudent; // all good - can view. } } return(szUser); }
protected void SetUpInstructorList() { CFIStudentMap sm = new CFIStudentMap(User.Identity.Name); cmbInstructors.DataSource = sm.Instructors; cmbInstructors.DataBind(); }
protected void btnSaveDefaultSig_Click(object sender, EventArgs e) { byte[] rgbSig = mfbScribbleSignature.Base64Data(); CFIStudentMap.SetDefaultScribbleForInstructor(m_pf, rgbSig); imgCurrSig.Src = ScribbleImage.DataLinkForByteArray(rgbSig); imgCurrSig.Visible = (rgbSig.Length != 0); lnkEditDefaultSig.Text = (rgbSig.Length == 0) ? Resources.LocalizedText.StudentSigningDefaultScribbleAdd : Resources.LocalizedText.StudentSigningDefaultScribbleEdit; mvDefaultSig.SetActiveView(vwCurrentSig); }
protected void Page_Load(object sender, EventArgs e) { Master.SelectedTab = tabID.tabTraining; if (!IsPostBack) { hdnStudent.Value = Page.User.Identity.Name; //default string szStudent = util.GetStringParam(Request, "student"); CFIStudentMap sm = new CFIStudentMap(Page.User.Identity.Name); InstructorStudent student = CFIStudentMap.GetInstructorStudent(sm.Students, szStudent); if (student == null) { lblErr.Text = Resources.SignOff.ViewStudentNoSuchStudent; } else { if (!student.CanViewLogbook) { lblErr.Text = Master.Title = Resources.SignOff.ViewStudentLogbookUnauthorized; } else { // If we're here, we are authorized lblHeader.Text = String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.SignOff.ViewStudentLogbookHeader, student.UserFullName); hdnStudent.Value = student.UserName; Restriction = new FlightQuery(student.UserName); if (mfbLogbook1.CanResignValidFlights = student.CanAddLogbook) { mfbEditFlight.FlightUser = student.UserName; mfbEditFlight.SetUpNewOrEdit(LogbookEntry.idFlightNew); } else { apcNewFlight.Visible = false; } if (!String.IsNullOrEmpty(hdnStudent.Value)) { UpdateForUser(hdnStudent.Value); } mfbSearchForm.Username = printOptions.UserName = student.UserName; ResolvePrintLink(); } } pnlLogbook.Visible = (lblErr.Text.Length == 0); } if (pnlLogbook.Visible && mfbChartTotals.Visible) { mfbChartTotals.HistogramManager = LogbookEntryDisplay.GetHistogramManager(mfbLogbook1.Data, hdnStudent.Value); // do this every time, since charttotals doesn't persist its data. } }
private LogbookEntryDisplay LoadFlight(int idFlight) { // Check to see if the requested flight belongs to the current user, or if they're authorized. // It's an extra database hit (or more, if viewing a student flight), but will let us figure out next/previous string szFlightOwner = LogbookEntry.OwnerForFlight(idFlight); if (String.IsNullOrEmpty(szFlightOwner)) { throw new MyFlightbookException(Resources.LogbookEntry.errNoSuchFlight); } bool fIsAdmin = (util.GetIntParam(Request, "a", 0) != 0 && MyFlightbook.Profile.GetUser(Page.User.Identity.Name).CanSupport); // Check that you own the flight, or are admin. If not either of these, check to see if you are authorized if (String.Compare(szFlightOwner, Page.User.Identity.Name, StringComparison.OrdinalIgnoreCase) != 0 && !fIsAdmin) { // check for authorized by student CFIStudentMap sm = new CFIStudentMap(Page.User.Identity.Name); InstructorStudent student = sm.GetInstructorStudent(sm.Students, szFlightOwner); if (student == null || !student.CanViewLogbook) { throw new MyFlightbookException(Resources.SignOff.ViewStudentLogbookUnauthorized); } // At this point, we're viewing a student's flight. Change the return link. mvReturn.SetActiveView(vwReturnStudent); lnkReturnStudent.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "~/Member/StudentLogbook.aspx?student={0}", szFlightOwner); lnkReturnStudent.Text = String.Format(CultureInfo.CurrentCulture, Resources.Profile.ReturnToStudent, MyFlightbook.Profile.GetUser(szFlightOwner).UserFullName); popmenu.Visible = false; } // If we're here, we're authorized LogbookEntryDisplay led = new LogbookEntryDisplay(idFlight, szFlightOwner, LogbookEntry.LoadTelemetryOption.LoadAll); if (!led.HasFlightData) { led.FlightData = string.Empty; } if (String.IsNullOrEmpty(led.FlightData)) { apcChart.Visible = apcDownload.Visible = apcRaw.Visible = false; } lblFlightDate.Text = led.Date.ToShortDateString(); lblFlightAircraft.Text = led.TailNumDisplay ?? string.Empty; lblCatClass.Text = String.Format(CultureInfo.CurrentCulture, "({0})", led.CatClassDisplay); lblCatClass.CssClass = led.IsOverridden ? "ExceptionData" : string.Empty; litDesc.Text = led.CommentWithReplacedApproaches; lblRoute.Text = led.Route.ToUpper(CultureInfo.CurrentCulture); Page.Title = String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.FlightDetailsTitle, led.Date); return(led); }
/// <summary> /// Loads the specified flight into m_le, cached to avoid excess DB thrashing. /// </summary> /// <param name="idFlight">ID of the flight to load</param> protected void LoadLogbookEntry(int idFlight) { string szCacheKey = KeyCacheFlight(idFlight); Title = (string)GetLocalResourceObject("PageResource1.Title"); m_le = null; if (!IsPostBack || Session[szCacheKey] == null) { m_le = new LogbookEntry(); bool fIsAdmin = (util.GetIntParam(Request, "a", 0) != 0 && MyFlightbook.Profile.GetUser(Page.User.Identity.Name).CanSupport); if (m_le.FLoadFromDB(idFlight, User.Identity.Name, LogbookEntry.LoadTelemetryOption.LoadAll, true)) { if (!m_le.HasFlightData) { throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, Resources.FlightData.errNoDataForFlight, idFlight)); } // check to see if you own the flight. You own it if: // a) Admin // b) username=Page identity, or // c) authorized by student. if (!fIsAdmin && String.Compare(m_le.User, User.Identity.Name, StringComparison.Ordinal) != 0) { // check for authorized by student CFIStudentMap sm = new CFIStudentMap(Page.User.Identity.Name); InstructorStudent student = sm.GetInstructorStudent(sm.Students, m_le.User); if (student == null || !student.CanViewLogbook) { throw new MyFlightbookException(Resources.SignOff.ViewStudentLogbookUnauthorized); } } Session[szCacheKey] = m_le; } else { throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, Resources.FlightData.errCantLoadFlight, idFlight.ToString(CultureInfo.InvariantCulture), m_le.ErrorString)); } } else { m_le = (LogbookEntry)Session[szCacheKey]; } }
protected void Page_Load(object sender, EventArgs e) { Master.SelectedTab = tabID.tabTraining; Master.Layout = MasterPage.LayoutMode.Accordion; if (!IsPostBack) { string szStudent = util.GetStringParam(Request, "student"); CFIStudentMap sm = new CFIStudentMap(Page.User.Identity.Name); InstructorStudent student = sm.GetInstructorStudent(sm.Students, szStudent); if (student == null) { lblErr.Text = Resources.SignOff.ViewStudentNoSuchStudent; } else { if (!student.CanViewLogbook) { lblErr.Text = Master.Title = Resources.SignOff.ViewStudentLogbookUnauthorized; } else { // If we're here, we are authorized lblHeader.Text = String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.SignOff.ViewStudentLogbookHeader, student.UserFullName); hdnStudent.Value = student.UserName; Restriction = new FlightQuery(student.UserName); if (!String.IsNullOrEmpty(hdnStudent.Value)) { UpdateForUser(hdnStudent.Value); } } } pnlLogbook.Visible = (lblErr.Text.Length == 0); } if (pnlLogbook.Visible && mfbChartTotals.Visible) { mfbChartTotals.SourceData = mfbLogbook1.Data; // do this every time, since charttotals doesn't persist its data. } }
protected void Page_Load(object sender, EventArgs e) { this.Master.Title = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.TitleTraining, Branding.CurrentBrand.AppName); Master.SelectedTab = tabID.tabTraining; if (!IsPostBack) { Profile pf = MyFlightbook.Profile.GetUser(Page.User.Identity.Name); mfbEditEndorsement1.StudentType = Endorsement.StudentTypes.External; mfbEditEndorsement1.TargetUser = pf; cmbTemplates.DataSource = EndorsementType.LoadTemplates(); cmbTemplates.DataValueField = "id"; cmbTemplates.DataTextField = "FullTitle"; cmbTemplates.DataBind(); hdnLastTemplate.Value = cmbTemplates.SelectedValue; lblDisclaimerResponse.Text = Branding.ReBrand(Resources.SignOff.SignDisclaimerAgreement1); lblDisclaimerResponse2.Text = Branding.ReBrand(Resources.SignOff.SignDisclaimerAgreement2); CFIStudentMap sm = new CFIStudentMap(Page.User.Identity.Name); if (sm.Instructors.Count() == 0) { mfbEditEndorsement1.Mode = EndorsementMode.StudentPullAdHoc; mvAddEndorsement.SetActiveView(vwAcceptTerms); } else { cmbInstructors.DataSource = sm.Instructors; cmbInstructors.DataBind(); mvAddEndorsement.SetActiveView(vwPickInstructor); } mfbEditEndorsement1.StudentType = Endorsement.StudentTypes.Member; mfbEditEndorsement1.TargetUser = pf; } // need to reconstitute the form from the template every time to ensure postback works. mfbEditEndorsement1.EndorsementID = Convert.ToInt32(hdnLastTemplate.Value, CultureInfo.InvariantCulture); }
protected void Page_Load(object sender, EventArgs e) { m_pf = MyFlightbook.Profile.GetUser(User.Identity.Name); if (!Request.IsSecureConnection && !Request.IsLocal) { Response.Redirect(Request.Url.AbsoluteUri.Replace("http://", "https://")); } lblName.Text = String.Format(CultureInfo.CurrentCulture, Resources.Profile.TrainingHeader, m_pf.UserFullName); this.Master.Title = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.TitleTraining, Branding.CurrentBrand.AppName); // sidebar doesn't store it's state, so just set the currenttab each time. tabID sidebarTab = tabID.tabUnknown; string szPrefPath = String.IsNullOrWhiteSpace(Request.PathInfo) ? string.Empty : Request.PathInfo.Substring(1); string[] rgPrefPath = szPrefPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (rgPrefPath.Length > 0 && !String.IsNullOrEmpty(rgPrefPath[0]) && Enum.TryParse <tabID>(rgPrefPath[0], out tabID tabid)) { sidebarTab = tabid; } if (sidebarTab == tabID.tabUnknown) { sidebarTab = tabID.instInstructors; } this.Master.SelectedTab = sidebarTab; switch (sidebarTab) { case tabID.instEndorsements: mvProfile.SetActiveView(vwEndorsements); break; case tabID.instSignFlights: mvProfile.SetActiveView(vwSignFlights); break; case tabID.instStudents: mvProfile.SetActiveView(vwStudents); break; case tabID.instInstructors: mvProfile.SetActiveView(vwInstructors); break; } if (!IsPostBack) { switch (sidebarTab) { case tabID.instEndorsements: if (Request.IsMobileDevice()) { mfbIlEndorsements.Columns = 1; } mfbIlEndorsements.Key = User.Identity.Name; mfbIlEndorsements.Refresh(); mfbEndorsementList1.Student = Page.User.Identity.Name; mfbEndorsementList1.RefreshEndorsements(); if (!Request.IsMobileDeviceOrTablet()) { mfbMultiFileUpload1.Mode = Controls_mfbMultiFileUpload.UploadMode.Ajax; } lnkPrintFriendly.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "{0}?naked=1&print=1", Request.Url.AbsolutePath); if (util.GetIntParam(Request, "print", 0) != 0) { lnkPrintFriendly.Visible = mfbIlEndorsements.Visible = mfbMultiFileUpload1.Visible = false; List <MyFlightbook.Image.MFBImageInfo> lstInlineImages = new List <MyFlightbook.Image.MFBImageInfo>(mfbIlEndorsements.Images.ImageArray); lstInlineImages.RemoveAll(mfbii => mfbii.ImageType != MyFlightbook.Image.MFBImageInfo.ImageFileType.JPEG); rptEndorsementImages.DataSource = lstInlineImages; rptEndorsementImages.DataBind(); } break; case tabID.instSignFlights: RefreshFlightsToBeSigned(); break; case tabID.instStudents: SetUpStudents(); break; } } // Need to do these on every page load to recreate links, etc. switch (sidebarTab) { case tabID.instSignFlights: case tabID.instStudents: case tabID.instInstructors: case tabID.instEndorsements: this.Master.ShowSponsoredAd = false; m_sm = new CFIStudentMap(User.Identity.Name); RefreshStudentsAndInstructors(); break; } }
protected void Page_Load(object sender, EventArgs e) { Master.SelectedTab = tabID.tabUnknown; string szUser = String.Empty; if (!IsPostBack) { lblErr.Text = String.Empty; string szAuthToken = util.GetStringParam(Request, "auth"); if (!String.IsNullOrEmpty(szAuthToken)) { using (MFBWebService ws = new MFBWebService()) szUser = ws.GetEncryptedUser(szAuthToken); } bool fIsLocalOrSecure = MFBWebService.CheckSecurity(Request); // If no valid auth token, fall back to the authenticated name. if (String.IsNullOrEmpty(szUser) && Page.User.Identity.IsAuthenticated && fIsLocalOrSecure) { szUser = Page.User.Identity.Name; } // Require a secure connection for other than debugging. if (!fIsLocalOrSecure && !Request.IsSecureConnection) { szUser = string.Empty; } try { if (String.IsNullOrEmpty(szUser)) { throw new MyFlightbookException(Resources.SignOff.errSignNotAuthorized); } int idFlight = util.GetIntParam(Request, "idFlight", LogbookEntry.idFlightNew); if (idFlight == LogbookEntry.idFlightNew) { throw new MyFlightbookException(Resources.SignOff.errSignNotAuthorized); } LogbookEntry le = new LogbookEntry(); if (!le.FLoadFromDB(idFlight, szUser)) { throw new MyFlightbookException(Resources.SignOff.errSignNotAuthorized); } mfbSignFlight.Flight = le; CFIStudentMap sm = new CFIStudentMap(szUser); if (sm.Instructors.Count() == 0) { mfbSignFlight.SigningMode = Controls_mfbSignFlight.SignMode.AdHoc; mfbSignFlight.CFIProfile = null; mvSignFlight.SetActiveView(vwAcceptTerms); } else { cmbInstructors.DataSource = sm.Instructors; cmbInstructors.DataBind(); mvSignFlight.SetActiveView(vwPickInstructor); } lblHeader.Text = String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.SignOff.SignFlightHeader, MyFlightbook.Profile.GetUser(le.User).UserFullName); lblDisclaimerResponse.Text = Branding.ReBrand(Resources.SignOff.SignDisclaimerAgreement1); lblDisclaimerResponse2.Text = Branding.ReBrand(Resources.SignOff.SignDisclaimerAgreement2); } catch (MyFlightbookException ex) { lblErr.Text = ex.Message; } } }
protected void Page_Load(object sender, EventArgs e) { Master.SelectedTab = tabID.tabUnknown; if (!IsPostBack) { lblErr.Text = String.Empty; string szAuthToken = util.GetStringParam(Request, "auth"); if (!String.IsNullOrEmpty(szAuthToken)) { Username = MFBWebService.GetEncryptedUser(szAuthToken); } bool fIsLocalOrSecure = MFBWebService.CheckSecurity(Request); // If no valid auth token, fall back to the authenticated name. if (String.IsNullOrEmpty(Username) && Page.User.Identity.IsAuthenticated && fIsLocalOrSecure) { Username = Page.User.Identity.Name; } // Require a secure connection for other than debugging. if (!fIsLocalOrSecure && !Request.IsSecureConnection) { Username = string.Empty; } try { if (String.IsNullOrEmpty(Username)) { throw new MyFlightbookException(Resources.SignOff.errSignNotAuthorized); } int idFlight = util.GetIntParam(Request, "idFlight", LogbookEntry.idFlightNew); if (idFlight == LogbookEntry.idFlightNew) { throw new MyFlightbookException(Resources.SignOff.errSignNotAuthorized); } LogbookEntry le = new LogbookEntry(); if (!le.FLoadFromDB(idFlight, Username)) { throw new MyFlightbookException(Resources.SignOff.errSignNotAuthorized); } mfbSignFlight.Flight = le; CFIStudentMap sm = new CFIStudentMap(Username); if (Username == null) { throw new MyFlightbookValidationException("No username for previously signed flights"); } Dictionary <string, LogbookEntry> d = PreviouslySignedAdhocFlights; // If no instructors, and no previously signed flights, assume ad-hoc and go straight to accept terms. if (!sm.Instructors.Any() && d.Keys.Count == 0) { mfbSignFlight.SigningMode = Controls_mfbSignFlight.SignMode.AdHoc; mfbSignFlight.CFIProfile = null; mvSignFlight.SetActiveView(vwAcceptTerms); } else { rptInstructors.DataSource = sm.Instructors; rptInstructors.DataBind(); List <string> lstKeys = new List <string>(d.Keys); lstKeys.Sort(); List <LogbookEntry> lstPrevInstructors = new List <LogbookEntry>(); foreach (string sz in lstKeys) { lstPrevInstructors.Add(d[sz]); } rptPriorInstructors.DataSource = lstPrevInstructors; rptPriorInstructors.DataBind(); mvSignFlight.SetActiveView(vwPickInstructor); } lblHeader.Text = String.Format(CultureInfo.CurrentCulture, Resources.SignOff.SignFlightHeader, MyFlightbook.Profile.GetUser(le.User).UserFullName); lblDisclaimerResponse.Text = Branding.ReBrand(Resources.SignOff.SignDisclaimerAgreement1); lblDisclaimerResponse2.Text = Branding.ReBrand(Resources.SignOff.SignDisclaimerAgreement2); } catch (MyFlightbookException ex) { lblErr.Text = ex.Message; } } }
protected void Page_Load(object sender, EventArgs e) { Master.SelectedTab = tabID.tabTraining; Master.Title = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.TitleProfile, Branding.CurrentBrand.AppName); string szReq = util.GetStringParam(Request, "req"); try { if (szReq.Length == 0) { throw new MyFlightbookValidationException(Resources.LocalizedText.AddRelationshipErrInvalidRequest); } m_smr = new CFIStudentMapRequest(); m_smr.DecryptRequest(szReq); Profile pfRequestor = Profile.GetUser(m_smr.RequestingUser); if (!pfRequestor.IsValid()) { throw new MyFlightbookValidationException(Resources.LocalizedText.AddRelationshipErrInvalidUser); } Profile pfCurrent = Profile.GetUser(User.Identity.Name); if (pfCurrent.Email.CompareCurrentCultureIgnoreCase(m_smr.TargetUser) != 0 && !pfCurrent.IsVerifiedEmail(m_smr.TargetUser)) { throw new MyFlightbookValidationException(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.AddRelationshipErrNotTargetUser, m_smr.TargetUser, pfCurrent.Email)); } m_sm = new CFIStudentMap(User.Identity.Name); switch (m_smr.Requestedrole) { case CFIStudentMapRequest.RoleType.RoleStudent: lblRequestDesc.Text = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.AddRelationshipRequestStudent, Branding.CurrentBrand.AppName, HttpUtility.HtmlEncode(pfRequestor.UserFullName)); if (m_sm.IsStudentOf(m_smr.RequestingUser)) { throw new MyFlightbookValidationException(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.AddRelationshipErrAlreadyStudent, pfRequestor.UserFullName)); } break; case CFIStudentMapRequest.RoleType.RoleCFI: lblRequestDesc.Text = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.AddRelationshipRequestInstructor, Branding.CurrentBrand.AppName, HttpUtility.HtmlEncode(pfRequestor.UserFullName)); if (m_sm.IsInstructorOf(m_smr.RequestingUser)) { throw new MyFlightbookValidationException(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.AddRelationshipErrAlreadyInstructor, pfRequestor.UserFullName)); } break; case CFIStudentMapRequest.RoleType.RoleInviteJoinClub: if (m_smr.ClubToJoin == null) { throw new MyFlightbookValidationException(Resources.Club.errNoClubInRequest); } if (m_smr.ClubToJoin.HasMember(pfCurrent.UserName)) { throw new MyFlightbookValidationException(String.Format(CultureInfo.CurrentCulture, Resources.Club.errAlreadyMember, m_smr.ClubToJoin.Name)); } lblRequestDesc.Text = String.Format(CultureInfo.CurrentCulture, Resources.Club.AddMemberFromInvitation, m_smr.ClubToJoin.Name); break; case CFIStudentMapRequest.RoleType.RoleRequestJoinClub: if (m_smr.ClubToJoin == null) { throw new MyFlightbookValidationException(Resources.Club.errNoClubInRequest); } if (m_smr.ClubToJoin.HasMember(pfRequestor.UserName)) { throw new MyFlightbookValidationException(String.Format(CultureInfo.CurrentCulture, Resources.Club.errAlreadyAddedMember, pfRequestor.UserFullName, m_smr.ClubToJoin.Name)); } lblRequestDesc.Text = String.Format(CultureInfo.CurrentCulture, Resources.Club.AddMemberFromRequest, HttpUtility.HtmlEncode(pfRequestor.UserFullName), m_smr.ClubToJoin.Name); break; } } catch (MyFlightbookValidationException ex) { pnlReviewRequest.Visible = false; lblError.Text = ex.Message; pnlConfirm.Visible = false; } }
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)); }