/// <summary> /// Commits the edits, returns the id of the resulting row, -1 if it failed. /// </summary> /// <returns>Non-negative flight ID, -1 for failure</returns> protected int CommitChanges() { int idResult = -1; if (!Page.IsValid) { return(idResult); } LogbookEntry le = InitLogbookEntryFromForm(); FlightWillBeSaved?.Invoke(this, new LogbookEventArgs(le)); if (le.IsValid()) { // if a new flight and hobbs > 0, save it for the next flight if (le.IsNewFlight && le.HobbsEnd > 0) { SetLastHobbs(le.HobbsEnd); } le.FlightData = mfbFlightInfo1.Telemetry; try { if (le.FCommit(le.HasFlightData)) { AircraftUtility.SaveLastTail(le.AircraftID); ProcessImages(le.FlightID); if (FlightID == LogbookEntry.idFlightNew) // new flight - save the date { Session[keyLastEntryDate] = le.Date; } idResult = le.FlightID; // this must be >= 0 if the commit succeeded // Badge computation may be wrong MyFlightbook.Profile.GetUser(le.User).SetAchievementStatus(MyFlightbook.Achievements.Achievement.ComputeStatus.NeedsComputing); } else { lblError.Text = HttpUtility.HtmlEncode(le.ErrorString); } } catch (MyFlightbookException ex) { lblError.Text = !String.IsNullOrEmpty(le.ErrorString) ? le.ErrorString : (ex.InnerException == null ? ex.Message : ex.InnerException.Message); } } else { lblError.Text = HttpUtility.HtmlEncode(le.ErrorString); } return(idResult); }
protected void CopyToInstructor(LogbookEntry le) { // Now make it look like the CFI's: their username, swap DUAL for CFI time, ensure that PIC time is present. le.FlightID = LogbookEntry.idFlightNew; string szStudentName = MyFlightbook.Profile.GetUser(le.User).UserFullName; List <CustomFlightProperty> lstProps = new List <CustomFlightProperty>(le.CustomProperties); lstProps.ForEach(cfp => cfp.FlightID = le.FlightID); // Add the student's name as a property lstProps.RemoveAll(cfp => cfp.PropTypeID == (int)CustomPropertyType.KnownProperties.IDPropStudentName); lstProps.Add(new CustomFlightProperty(new CustomPropertyType(CustomPropertyType.KnownProperties.IDPropStudentName)) { FlightID = le.FlightID, TextValue = szStudentName }); le.Comment = String.IsNullOrEmpty(le.Comment) ? txtComments.Text : String.Format(CultureInfo.CurrentCulture, Resources.SignOff.StudentNameTemplate, le.Comment, txtComments.Text); le.User = CFIProfile.UserName; // Swap username, of course, but do so AFTER adjusting the comment above (where we had the user's name) le.PIC = le.CFI = Flight.Dual; // Assume you were PIC for the time you were giving instruction. le.Dual = 0.0M; // Swap ground instruction given/ground-instruction received CustomFlightProperty cfpGIReceived = lstProps.FirstOrDefault(cfp => cfp.PropTypeID == (int)CustomPropertyType.KnownProperties.IDPropGroundInstructionReceived); if (cfpGIReceived != null) { CustomFlightProperty cfpGIGiven = lstProps.FirstOrDefault(cfp => cfp.PropTypeID == (int)CustomPropertyType.KnownProperties.IDPropGroundInstructionGiven); if (cfpGIGiven == null) { cfpGIGiven = new CustomFlightProperty(new CustomPropertyType(CustomPropertyType.KnownProperties.IDPropGroundInstructionGiven)); } cfpGIGiven.DecValue = cfpGIReceived.DecValue; cfpGIGiven.FlightID = le.FlightID; cfpGIReceived.DeleteProperty(); lstProps.Remove(cfpGIReceived); lstProps.Add(cfpGIGiven); } le.CustomProperties = lstProps.ToArray(); // Add this aircraft to the user's profile if needed UserAircraft ua = new UserAircraft(CFIProfile.UserName); Aircraft ac = new Aircraft(le.AircraftID); if (!ua.CheckAircraftForUser(ac)) { ua.FAddAircraftForUser(ac); } bool result = le.FCommit(true); if (!result || le.LastError != LogbookEntry.ErrorCode.None) { util.NotifyAdminEvent("Error copying flight to instructor's logbook", String.Format(CultureInfo.CurrentCulture, "Flight: {0}, CFI: {1}, Student: {2}, ErrorCode: {3}, Error: {4}", le.ToString(), le.User, szStudentName, le.LastError, le.ErrorString), ProfileRoles.maskSiteAdminOnly); } }
private void RedirectToFacebook(Boolean fShareFirst) { LogbookEntry le = mfbMiniFacebook.FlightEntry; if (le != null) { if (fShareFirst) { le.fIsPublic = true; le.FCommit(); } Response.Redirect(mfbMiniFacebook.FBRedirURL.OriginalString); } }
protected void lnkDeletedata_Click(object sender, EventArgs e) { if (FlightID >= 0) { LogbookEntry le = new LogbookEntry(); if (le.FLoadFromDB(FlightID, Page.User.Identity.Name)) { le.FlightData = null; le.FCommit(true); DeleteData(); } } else { DeleteData(); } }
/// <summary> /// Commits the edits, returns the id of the resulting row, -1 if it failed. /// </summary> /// <returns>Non-negative flight ID, -1 for failure</returns> protected int CommitChanges() { int idResult = -1; if (!Page.IsValid) { return(idResult); } LogbookEntry le = InitLogbookEntryFromForm(); if (le.IsValid()) { // if a new flight and hobbs > 0, save it for the next flight if (le.IsNewFlight && le.HobbsEnd > 0) { Response.Cookies.Add(new HttpCookie(keyCookieLastEndingHobbs, le.HobbsEnd.ToString(CultureInfo.InvariantCulture))); } le.FlightData = mfbFlightInfo1.Telemetry; try { if (le.FCommit(le.HasFlightData)) { Aircraft.SaveLastTail(le.AircraftID); ProcessImages(le.FlightID); if (FlightID == LogbookEntry.idFlightNew) // new flight - save the date { Session[keyLastEntryDate] = le.Date; } idResult = le.FlightID; // this must be >= 0 if the commit succeeded if (ckFacebook.Checked) { mfbFacebook1.PostFlight(le); } else if (FlightID == LogbookEntry.idFlightNew) { mfbFacebook1.FDefaultFacebookCheckboxState = false; // if this was a new flight and the user didn't post on facebook, then don't default next time. } if (ckUpdateTwitter.Checked) { mfbTwitter.PostFlight(le); } else if (FlightID == LogbookEntry.idFlightNew) { mfbTwitter.FDefaultTwitterCheckboxState = false; // if this was a new flight and user didn't tweet, then don't default next time; if editing a flight, don't change the default state } // Badge computation may be wrong MyFlightbook.Profile.GetUser(le.User).SetAchievementStatus(MyFlightbook.Achievements.Achievement.ComputeStatus.NeedsComputing); } else { lblError.Text = le.ErrorString; } } catch (MyFlightbookException ex) { lblError.Text = !String.IsNullOrEmpty(le.ErrorString) ? le.ErrorString : (ex.InnerException == null ? ex.Message : ex.InnerException.Message); } } else { lblError.Text = le.ErrorString; } return(idResult); }