Example #1
0
        public string MoveTram(int moveTram, int moveTrack, int moveSector, bool hasAccepted = false)
        {
            moveSector -= 1;

            if (!AllTrams.ContainsKey(moveTram))
            {
                return("Deze tram bestaat niet.");
            }
            var tram = AllTrams[moveTram];

            if (!hasAccepted && tram.Status != TramStatus.Idle)
            {
                return("NOT IDLE");
            }
            if (!AllTracks.ContainsKey(moveTrack))
            {
                return("Dit spoor betaat niet.");
            }
            var track = AllTracks[moveTrack];

            if (track.Sectors.Count < moveSector + 1)
            {
                return($"Spoor {track.Number} heeft zo veel secoren niet");
            }
            var sector = track.Sectors[moveSector];

            switch (sector.Status)
            {
            case SectorStatus.Locked:
                return("Deze sector is afgesloten.");

            case SectorStatus.Occupied:
                return("Deze sector is bezet.");

            case SectorStatus.Open:
            {
                var beheerSector = BeheerSector.ToBeheerSector(sector);
                if (beheerSector != null && beheerSector.SetOccupyingTram(tram))
                {
                    _repo.WipeSectorByTramId(tram.Number);
                }
                _repo.EditSector(beheerSector);
                Update();
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(null);
        }
Example #2
0
        public string AddSector(int trackNumber, decimal latitude, decimal longitude)
        {
            if (!AllTracks.ContainsKey(trackNumber))
            {
                return("Dit spoor bestaat niet.");
            }
            var track = AllTracks[trackNumber];

            track.AddSector(new Sector(track.Sectors.Count + 1, track.Number, SectorStatus.Open, null, latitude,
                                       longitude));
            _repo.AddSector(track.Sectors[track.Sectors.Count - 1], track);
            Update();
            return(null);
        }
Example #3
0
        public string DeleteTrack(int trackNumber)
        {
            if (!AllTracks.ContainsKey(trackNumber))
            {
                return("Dit spoor bestaat niet.");
            }
            var track = AllTracks[trackNumber];

            if (track.Sectors.Any(x => x.OccupyingTram != null))
            {
                return("Er staat een tram op dit spoor. haal het eerst weg.");
            }

            _repo.DeleteTrack(track);
            Update();
            return(null);
        }
Example #4
0
        public string DeleteSector(int trackNumber)
        {
            if (!AllTracks.ContainsKey(trackNumber))
            {
                return("Dit spoor bestaat niet.");
            }
            var track  = AllTracks[trackNumber];
            var sector = track.Sectors.Last();

            if (sector == null)
            {
                return("Dit spoor heeft geen sectoren.");
            }
            if (sector.OccupyingTram != null)
            {
                return("Er staat een tram op deze sector. Haal deze eerst weg.");
            }

            track.DeleteSector();
            _repo.DeleteSectorFromTrack(track, sector);
            Update();
            return(null);
        }