Esempio n. 1
0
 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"));
 }
Esempio n. 2
0
        public FlightBase GetFlightBase()
        {
            FlightBase res = new FlightBase();

            res.FlightId             = FlightId;
            res.PortalId             = PortalId;
            res.UserId               = UserId;
            res.Category             = Category;
            res.TakeoffDescription   = TakeoffDescription;
            res.TakeoffTime          = TakeoffTime;
            res.TakeoffCoords        = TakeoffCoords;
            res.TakeoffLatitude      = TakeoffLatitude;
            res.TakeoffLongitude     = TakeoffLongitude;
            res.TakeoffAltitude      = TakeoffAltitude;
            res.LandingDescription   = LandingDescription;
            res.LandingTime          = LandingTime;
            res.LandingCoords        = LandingCoords;
            res.LandingLatitude      = LandingLatitude;
            res.LandingLongitude     = LandingLongitude;
            res.LandingAltitude      = LandingAltitude;
            res.LandingBeaconId      = LandingBeaconId;
            res.MaxHeight            = MaxHeight;
            res.MaxVario             = MaxVario;
            res.MaxSpeed             = MaxSpeed;
            res.AverageSpeed         = AverageSpeed;
            res.DurationMins         = DurationMins;
            res.Distance             = Distance;
            res.Status               = Status;
            res.TotalPoints          = TotalPoints;
            res.EntryMethod          = EntryMethod;
            res.Summary              = Summary;
            res.ValidatedByUserID    = ValidatedByUserID;
            res.ValidatedOnDate      = ValidatedOnDate;
            res.CreatedByUserID      = CreatedByUserID;
            res.CreatedOnDate        = CreatedOnDate;
            res.LastModifiedByUserID = LastModifiedByUserID;
            res.LastModifiedOnDate   = LastModifiedOnDate;
            return(res);
        }
Esempio n. 3
0
 public FlightBase GetFlightBase()
 {
     FlightBase res = new FlightBase();
      res.FlightId = FlightId;
      res.PortalId = PortalId;
      res.UserId = UserId;
      res.Category = Category;
      res.TakeoffDescription = TakeoffDescription;
      res.TakeoffTime = TakeoffTime;
      res.TakeoffCoords = TakeoffCoords;
      res.TakeoffLatitude = TakeoffLatitude;
      res.TakeoffLongitude = TakeoffLongitude;
      res.TakeoffAltitude = TakeoffAltitude;
      res.LandingDescription = LandingDescription;
      res.LandingTime = LandingTime;
      res.LandingCoords = LandingCoords;
      res.LandingLatitude = LandingLatitude;
      res.LandingLongitude = LandingLongitude;
      res.LandingAltitude = LandingAltitude;
      res.LandingBeaconId = LandingBeaconId;
      res.MaxHeight = MaxHeight;
      res.MaxVario = MaxVario;
      res.MaxSpeed = MaxSpeed;
      res.AverageSpeed = AverageSpeed;
      res.DurationMins = DurationMins;
      res.Distance = Distance;
      res.Status = Status;
      res.TotalPoints = TotalPoints;
      res.EntryMethod = EntryMethod;
      res.Summary = Summary;
      res.ValidatedByUserID = ValidatedByUserID;
      res.ValidatedOnDate = ValidatedOnDate;
       res.CreatedByUserID = CreatedByUserID;
       res.CreatedOnDate = CreatedOnDate;
       res.LastModifiedByUserID = LastModifiedByUserID;
       res.LastModifiedOnDate = LastModifiedOnDate;
     return res;
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
        public void ReadFlightBase(FlightBase flight)
        {
            if (flight.FlightId > -1)
                FlightId = flight.FlightId;

            if (flight.PortalId > -1)
                PortalId = flight.PortalId;

            if (flight.UserId > -1)
                UserId = flight.UserId;

            if (flight.Category > -1)
                Category = flight.Category;

            if (!String.IsNullOrEmpty(flight.TakeoffDescription))
                TakeoffDescription = flight.TakeoffDescription;

            TakeoffTime = flight.TakeoffTime;

            if (!String.IsNullOrEmpty(flight.TakeoffCoords))
                TakeoffCoords = flight.TakeoffCoords;

            TakeoffLatitude = flight.TakeoffLatitude;

            TakeoffLongitude = flight.TakeoffLongitude;

            if (flight.TakeoffAltitude > -1)
                TakeoffAltitude = flight.TakeoffAltitude;

            if (!String.IsNullOrEmpty(flight.LandingDescription))
                LandingDescription = flight.LandingDescription;

            LandingTime = flight.LandingTime;

            if (!String.IsNullOrEmpty(flight.LandingCoords))
                LandingCoords = flight.LandingCoords;

            LandingLatitude = flight.LandingLatitude;

            LandingLongitude = flight.LandingLongitude;

            if (flight.LandingAltitude > -1)
                LandingAltitude = flight.LandingAltitude;

            if (flight.LandingBeaconId > -1)
                LandingBeaconId = flight.LandingBeaconId;

            if (flight.MaxHeight > -1)
                MaxHeight = flight.MaxHeight;

            if (flight.MaxVario != null)
            MaxVario = flight.MaxVario;

            if (flight.MaxSpeed != null)
            MaxSpeed = flight.MaxSpeed;

            if (flight.AverageSpeed != null)
            AverageSpeed = flight.AverageSpeed;

            if (flight.DurationMins > -1)
                DurationMins = flight.DurationMins;

            if (flight.Distance > -1)
                Distance = flight.Distance;

            if (flight.Status > -1)
                Status = flight.Status;

            if (flight.TotalPoints > -1)
                TotalPoints = flight.TotalPoints;

            if (flight.EntryMethod > -1)
                EntryMethod = flight.EntryMethod;

            if (!String.IsNullOrEmpty(flight.Summary))
                Summary = flight.Summary;

            if (flight.ValidatedByUserID > -1)
                ValidatedByUserID = flight.ValidatedByUserID;

            if (flight.ValidatedOnDate != null)
            ValidatedOnDate = flight.ValidatedOnDate;
        }
Esempio n. 6
0
        public void ReadFlightBase(FlightBase flight)
        {
            if (flight.FlightId > -1)
            {
                FlightId = flight.FlightId;
            }

            if (flight.PortalId > -1)
            {
                PortalId = flight.PortalId;
            }

            if (flight.UserId > -1)
            {
                UserId = flight.UserId;
            }

            if (flight.Category > -1)
            {
                Category = flight.Category;
            }

            if (!String.IsNullOrEmpty(flight.TakeoffDescription))
            {
                TakeoffDescription = flight.TakeoffDescription;
            }

            TakeoffTime = flight.TakeoffTime;

            if (!String.IsNullOrEmpty(flight.TakeoffCoords))
            {
                TakeoffCoords = flight.TakeoffCoords;
            }

            TakeoffLatitude = flight.TakeoffLatitude;

            TakeoffLongitude = flight.TakeoffLongitude;

            if (flight.TakeoffAltitude > -1)
            {
                TakeoffAltitude = flight.TakeoffAltitude;
            }

            if (!String.IsNullOrEmpty(flight.LandingDescription))
            {
                LandingDescription = flight.LandingDescription;
            }

            LandingTime = flight.LandingTime;

            if (!String.IsNullOrEmpty(flight.LandingCoords))
            {
                LandingCoords = flight.LandingCoords;
            }

            LandingLatitude = flight.LandingLatitude;

            LandingLongitude = flight.LandingLongitude;

            if (flight.LandingAltitude > -1)
            {
                LandingAltitude = flight.LandingAltitude;
            }

            if (flight.LandingBeaconId > -1)
            {
                LandingBeaconId = flight.LandingBeaconId;
            }

            if (flight.MaxHeight > -1)
            {
                MaxHeight = flight.MaxHeight;
            }

            if (flight.MaxVario != null)
            {
                MaxVario = flight.MaxVario;
            }

            if (flight.MaxSpeed != null)
            {
                MaxSpeed = flight.MaxSpeed;
            }

            if (flight.AverageSpeed != null)
            {
                AverageSpeed = flight.AverageSpeed;
            }

            if (flight.DurationMins > -1)
            {
                DurationMins = flight.DurationMins;
            }

            if (flight.Distance > -1)
            {
                Distance = flight.Distance;
            }

            if (flight.Status > -1)
            {
                Status = flight.Status;
            }

            if (flight.TotalPoints > -1)
            {
                TotalPoints = flight.TotalPoints;
            }

            if (flight.EntryMethod > -1)
            {
                EntryMethod = flight.EntryMethod;
            }

            if (!String.IsNullOrEmpty(flight.Summary))
            {
                Summary = flight.Summary;
            }

            if (flight.ValidatedByUserID > -1)
            {
                ValidatedByUserID = flight.ValidatedByUserID;
            }

            if (flight.ValidatedOnDate != null)
            {
                ValidatedOnDate = flight.ValidatedOnDate;
            }
        }
Esempio n. 7
0
 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);
     }
 }