/// <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 AircraftUpdated(object sender, EventArgs e) { AircraftUtility.SaveLastTail(MfbEditAircraft1.AircraftID); Response.Redirect(!String.IsNullOrEmpty(hdnReturnURL.Value) ? hdnReturnURL.Value : "Aircraft.aspx"); }