public EntityValidationResult EntityValidated(LogbookImage image, bool isNew)
        {
            var result = new EntityValidationResult();


            return(result);
        }
示例#2
0
        public EntityValidationResult ValidateTripWaypoint(TripWaypoint tw, bool isNew, Waypoint oldWaypoint = null)
        {
            EntityValidationResult evr = new EntityValidationResult();

            if (tw.WaypointName == null || tw.WaypointName.Length < 1)
            {
                evr.AddMessage("Waypoint name must be at least 1 character long");
            }

            if (tw.TimeStamp == null)
            {
                evr.AddMessage("Waypoint timestamp cannot be emppty");
            }
            else
            {
                var wptAdjustedTime = ((DateTime)tw.TimeStamp).AddHours(Global.Settings.HoursOffsetGMT);
                if (wptAdjustedTime <= tw.Trip.DateTimeDeparture || wptAdjustedTime >= tw.Trip.DateTimeArrival)
                {
                    evr.AddMessage("Waypoint timestamp must be within departure and arrival time of trip");
                }
            }

            if (tw.WaypointType == null || tw.WaypointType != "Set" && tw.WaypointType != "Haul")
            {
                evr.AddMessage("Waypoint type is not valid");
            }

            if (tw.SetNumber == 0)
            {
                evr.AddMessage("Set number is not valid");
            }

            if (!isNew && oldWaypoint != null && tw.Waypoint.Name != oldWaypoint.Name)
            {
                if (GetTripWaypoint(tw) != null)
                {
                    evr.AddMessage("Waypoint already in use");
                }
            }

            if (isNew && GetTripWaypoint(tw) != null)
            {
                evr.AddMessage("Waypoint already in use");
            }



            return(evr);
        }
示例#3
0
        public EntityValidationResult ValidateTrip(TripWaypoint tw, bool isNew, Waypoint oldWaypoint = null)
        {
            EntityValidationResult evr = new EntityValidationResult();

            if (tw.WaypointName == null || tw.WaypointName.Length < 1)
            {
                evr.AddMessage("Waypoint name must be at least 1 character long");
            }

            if (tw.TimeStamp <= tw.Trip.DateTimeDeparture || tw.TimeStamp >= tw.Trip.DateTimeArrival)
            {
                evr.AddMessage("Waypoint timestamp must be within departure and arrival time of trip");
            }

            if (tw.WaypointType == null || tw.WaypointType.Length < 3)
            {
                evr.AddMessage("Waypoint type is not valid");
            }

            if (tw.SetNumber == 0)
            {
                evr.AddMessage("Set number is not valid");
            }

            if (!isNew && tw.Waypoint.Name != oldWaypoint.Name)
            {
                if (GetTripWaypoint(tw) != null)
                {
                    evr.AddMessage("Waypoint already in use");
                }
            }

            if (isNew && GetTripWaypoint(tw) != null)
            {
                evr.AddMessage("Waypoint already in use");
            }



            return(evr);
        }
示例#4
0
        public EntityValidationResult ValidateTrip(Trip trip, bool isNew)
        {
            EntityValidationResult evr = new EntityValidationResult();

            if (trip.OperatorName == null || trip.OperatorName.Length < 3)
            {
                evr.AddMessage("Operator name must be at least 3 letters long");
            }

            if (trip.VesselName == null || trip.VesselName.Length < 3)
            {
                evr.AddMessage("Vessel name 3 letters long");
            }

            if (trip.Gear == null && trip.OtherGear == null)
            {
                evr.AddMessage("Gear or gear other name cannnot be both empty");
            }

            if (trip.DateTimeDeparture == null || trip.DateTimeDeparture > DateTime.Now)
            {
                evr.AddMessage("Date and time of departure cannot be empty and cannot be in the future");
            }
            else if (trip.DateTimeArrival == null || trip.DateTimeArrival > DateTime.Now)
            {
                evr.AddMessage("Date and time of arrival cannot be empty and cannot be in the future");
            }
            else if (trip.DateTimeDeparture >= trip.DateTimeArrival)
            {
                evr.AddMessage("Date and time of departure must be before date and time of arrival");
            }


            int?overlapID = null;

            foreach (var tripItem in TripCollection
                     .Where(t => t.TripID != trip.TripID)
                     .Where(t => t.DeviceID == trip.DeviceID))
            {
                if (trip.DateTimeDeparture >= tripItem.DateTimeDeparture && trip.DateTimeDeparture <= tripItem.DateTimeArrival)
                {
                    overlapID = tripItem.TripID;
                    break;
                }
                else if (trip.DateTimeArrival >= tripItem.DateTimeDeparture && trip.DateTimeArrival <= tripItem.DateTimeArrival)
                {
                    overlapID = tripItem.TripID;
                    break;
                }
                else if (trip.DateTimeDeparture <= tripItem.DateTimeDeparture && trip.DateTimeArrival >= tripItem.DateTimeArrival)
                {
                    overlapID = tripItem.TripID;
                    break;
                }
            }
            if (overlapID != null)
            {
                evr.AddMessage($"This trip overlaps with trip ID {overlapID}");
            }


            return(evr);
        }
示例#5
0
        public EntityValidationResult ValidateGPS(GPS gps, bool isNew,
                                                  string oldAssignedName = "", string oldCode = "", bool fromImport = false, bool fromArchive = false)
        {
            EntityValidationResult evr = new EntityValidationResult();

            if (isNew && (gps.DeviceName == null || gps.DeviceName.Length < 5))
            {
                evr.AddMessage("Device name cannot be empty and must be at least 5 letters long");
            }

            if (isNew && (gps.Code == null || gps.Code.Length > 6))
            {
                evr.AddMessage("Device code cannot be empty and must not exceed 6 letters long");
            }

            if (gps.Brand == null || gps.Brand.Length == 0)
            {
                evr.AddMessage("Brand  cannot be empty");
            }

            if (gps.Model == null || gps.Model.Length == 0)
            {
                evr.AddMessage("Model cannot be empty");
            }

            if (gps.Folder == null || gps.Folder.Length == 0)
            {
                evr.AddMessage("Folder cannot be empty");
            }


            else if (!fromArchive && !fromImport && !Directory.Exists($"{gps.Device.Disks[0].Caption}\\{gps.Folder}"))
            {
                evr.AddMessage("GPX folder does not exist");
            }



            if (!isNew && gps.DeviceName.Length > 0 &&
                oldAssignedName != gps.DeviceName &&
                GPSDeviceNameExist(gps.DeviceName))
            {
                evr.AddMessage("Device name already used");
            }

            if (!isNew && gps.Code.Length > 0 &&
                oldCode != gps.Code &&
                GPSCodeExist(gps.Code))
            {
                evr.AddMessage("Device code already used");
            }


            if (isNew && gps.Code != null && gps.Code.Length > 0 && GPSCodeExist(gps.Code))
            {
                evr.AddMessage("Device code already used");
            }

            if (isNew && gps.DeviceName != null && gps.DeviceName.Length > 0 && GPSDeviceNameExist(gps.DeviceName))
            {
                evr.AddMessage("Device name already used");
            }

            return(evr);
        }