コード例 #1
0
        public Passage ConnectRegions(Region firstRegion, Region secondRegion, int distance)
        {
            if (firstRegion == null || secondRegion == null)
            {
                return(null);
            }
            var passage = new Passage()
            {
                FirstRegionID  = firstRegion.ID,
                SecondRegionID = secondRegion.ID,
                Distance       = distance
            };

            //this will be not be called frequently. We will add some new checks for this.

            if (DoesPassageExist(firstRegion, secondRegion))
            {
                return(null); //this is acceptable.
            }
            regionRepository.AddPassage(passage);
            regionRepository.SaveChanges();

            Console.WriteLine($"Regions {firstRegion.Name} and {secondRegion.Name} connected!");

            return(passage);
        }