/// <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); }
/// <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); }