public void DeleteFlight(FlightBase flight) { Requires.NotNull(flight); Requires.PropertyNotNegative(flight, "FlightId"); using (var context = DataContext.Instance()) { var rep = context.GetRepository <FlightBase>(); rep.Delete(flight); } }
public void UpdateFlight(FlightBase flight, int userId) { Requires.NotNull(flight); Requires.PropertyNotNegative(flight, "FlightId"); flight.LastModifiedByUserID = userId; flight.LastModifiedOnDate = DateTime.Now; using (var context = DataContext.Instance()) { var rep = context.GetRepository <FlightBase>(); rep.Update(flight); } }
public int AddFlight(ref FlightBase flight, int userId) { Requires.NotNull(flight); Requires.PropertyNotNegative(flight, "PortalId"); flight.CreatedByUserID = userId; flight.CreatedOnDate = DateTime.Now; flight.LastModifiedByUserID = userId; flight.LastModifiedOnDate = DateTime.Now; using (var context = DataContext.Instance()) { var rep = context.GetRepository <FlightBase>(); rep.Insert(flight); } return(flight.FlightId); }
public ActionResult Delete(FlightBase flight) { var existingFlight = FlightRepository.Instance.GetFlight(PortalSettings.PortalId, flight.FlightId); if (existingFlight != null) { if (existingFlight.UserId != User.UserID) { if (!BalisesModuleContext.Security.IsVerifier) { throw new System.Exception("You don't have access to edit this"); } } FlightRepository.Instance.DeleteFlight(PortalSettings.PortalId, flight.FlightId); } return(ReturnRoute(existingFlight.UserId, View("Index", "Home"))); }
public ActionResult Edit(FlightBase flight) { var existingFlight = FlightRepository.Instance.GetFlight(PortalSettings.PortalId, flight.FlightId); if (existingFlight == null) { var newFlight = new FlightBase() { PortalId = PortalSettings.PortalId, UserId = User.UserID, TakeoffDescription = flight.TakeoffDescription, TakeoffTime = flight.TakeoffTime, LandingDescription = flight.LandingDescription, LandingTime = flight.LandingTime, Summary = flight.Summary, TakeoffAltitude = flight.TakeoffAltitude, LandingAltitude = flight.LandingAltitude, Category = flight.Category }; newFlight.ReadTakeoffCoordinates(flight.TakeoffCoords); newFlight.ReadLandingCoordinates(flight.LandingCoords); var newId = FlightRepository.Instance.AddFlight(ref newFlight, User.UserID); FlightBeaconRepository.Instance.ProcessFlightBeacons(newId, newFlight.TakeoffTime, Newtonsoft.Json.JsonConvert.DeserializeObject <List <PathBeacon> >(flight.BeaconList)); newFlight.RecalculateTotals(); newFlight.CheckLandingBeacon(BalisesModuleContext.Settings.BeaconPassDistanceMeters); FlightRepository.Instance.UpdateFlight(newFlight, User.UserID); var retValues = new Dictionary <string, string>(); retValues.Add("FlightId", newId.ToString()); retValues.Add("ret", ControllerContext.HttpContext.Request.Params["ret"]); return(RedirectToAction("View", "Flight", retValues)); } else { if (existingFlight.UserId != User.UserID) { if (!BalisesModuleContext.Security.IsVerifier) { throw new System.Exception("You don't have access to edit this"); } } if (existingFlight.Status > 3) { throw new System.Exception("This flight is locked"); } if (existingFlight.TakeoffCoords != flight.TakeoffCoords) { existingFlight.ReadTakeoffCoordinates(flight.TakeoffCoords); } existingFlight.TakeoffAltitude = flight.TakeoffAltitude; existingFlight.TakeoffDescription = flight.TakeoffDescription; existingFlight.TakeoffTime = flight.TakeoffTime; if (existingFlight.LandingCoords != flight.LandingCoords) { existingFlight.ReadLandingCoordinates(flight.LandingCoords); } existingFlight.LandingAltitude = flight.LandingAltitude; existingFlight.LandingDescription = flight.LandingDescription; existingFlight.LandingTime = flight.LandingTime; existingFlight.Summary = flight.Summary; existingFlight.Category = flight.Category; existingFlight.RecalculateTotals(); existingFlight.CheckLandingBeacon(BalisesModuleContext.Settings.BeaconPassDistanceMeters); FlightRepository.Instance.UpdateFlight(existingFlight.GetFlightBase(), User.UserID); if (existingFlight.EntryMethod == 0) { FlightBeaconRepository.Instance.ProcessFlightBeacons(existingFlight.FlightId, existingFlight.TakeoffTime, Newtonsoft.Json.JsonConvert.DeserializeObject <List <PathBeacon> >(flight.BeaconList)); } if (!string.IsNullOrEmpty(existingFlight.TakeoffDescription)) { SitesRepository.Instance.SetNewSite(existingFlight.TakeoffLatitude, existingFlight.TakeoffLongitude, existingFlight.TakeoffDescription, BalisesModuleContext.Settings.BeaconPassDistanceMeters); } if (!string.IsNullOrEmpty(existingFlight.LandingDescription)) { SitesRepository.Instance.SetNewSite(existingFlight.LandingLatitude, existingFlight.LandingLongitude, existingFlight.LandingDescription, BalisesModuleContext.Settings.BeaconPassDistanceMeters); } var retValues = new Dictionary <string, string>(); retValues.Add("FlightId", flight.FlightId.ToString()); if (!string.IsNullOrEmpty(ControllerContext.HttpContext.Request.Params["ret"])) { retValues.Add("ret", ControllerContext.HttpContext.Request.Params["ret"]); } return(RedirectToAction("View", "Flight", retValues)); } }
/// <summary>Creates service definition that can be registered with a server</summary> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static grpc::ServerServiceDefinition BindService(FlightBase serviceImpl) { return(grpc::ServerServiceDefinition.CreateBuilder() .AddMethod(__Method_BindFlight, serviceImpl.BindFlight).Build()); }
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary> /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static void BindService(grpc::ServiceBinderBase serviceBinder, FlightBase serviceImpl) { serviceBinder.AddMethod(__Method_BindFlight, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::ServerFoS.BindFlightRequest, global::ServerFoS.BindFlightResponse>(serviceImpl.BindFlight)); }
public static Flight AddFlightToUser(int portalId, int userId, string igcText, int beaconPassDistanceMeters) { var path = new BalisesPath(portalId, userId, new IgcFile(igcText), beaconPassDistanceMeters); var flight = FlightRepository.Instance.FindFlight(portalId, userId, path.Igc.DetectedStart); if (flight == null) { var f = new FlightBase() { EntryMethod = 1, TakeoffTime = path.Igc.DetectedStart, DurationMins = (int)path.Igc.FlightTime.TotalMinutes, Distance = path.OfficialDistance, MaxHeight = path.Igc.MaxAltitude, MaxVario = path.Igc.MaxVario, MaxSpeed = path.Igc.MaxSpeed, AverageSpeed = path.Igc.AverageSpeed, LandingCoords = path.Igc.Landing.ToSwissCoordinates(), LandingDescription = path.Landing.Description, LandingLatitude = path.Igc.Landing.Latitude, LandingLongitude = path.Igc.Landing.Longitude, LandingAltitude = path.Igc.Landing.Altitude, LandingTime = path.Igc.DetectedLandingTime, LandingBeaconId = (path.Landing.Code.Contains("ATT") ? path.Landing.BeaconId : -1), PortalId = portalId, UserId = userId, TakeoffCoords = path.Igc.Takeoff.ToSwissCoordinates(), TakeoffDescription = path.TakeOff.Description, TakeoffLatitude = path.Igc.Takeoff.Latitude, TakeoffLongitude = path.Igc.Takeoff.Longitude, TakeoffAltitude = path.Igc.Takeoff.Altitude, Summary = path.Igc.Report(), Status = (path.PassedBeacons.Count == 0 ? 3 : 0), ValidatedOnDate = new System.DateTime(1900, 1, 1), Category = (path.Igc.GliderType.ToUpper() == "PARA" ? 0 : 1), TotalPoints = 0 }; f.RecalculateTotals(path.PassedBeacons); FlightRepository.Instance.AddFlight(ref f, userId); foreach (var pt in path.PassedBeacons) { var fb = new FlightBeaconBase() { FlightId = f.FlightId, BeaconId = pt.BeaconId, PassedDistance = pt.PassedDistance, PassOrder = pt.PassOrder }; FlightBeaconRepository.Instance.AddFlightBeacon(fb); } var fullPath = string.Format("{0}\\Albatros\\Balises\\{1}", PortalSettings.Current.HomeDirectoryMapPath, userId); if (!System.IO.Directory.Exists(fullPath)) { System.IO.Directory.CreateDirectory(fullPath); } fullPath += "\\" + string.Format("path-{0}.igc", f.FlightId); using (var s = new System.IO.StreamWriter(fullPath)) { s.Write(igcText); } flight = FlightRepository.Instance.GetFlight(portalId, f.FlightId); } return(flight); }