コード例 #1
0
        public bool Import(string binaryPath, string filePath, string type)
        {
            try
            {
                IAccommodationImport     requestedImplementation = GetImplementation(binaryPath, type);
                AccommodationImportModel imported = requestedImplementation.CreateObjectModel(filePath);
                TouristSpotImportModel   tsm      = imported.TouristSpot;
                TouristSpot ts = tsm.ToEntity();
                if (regionLogic.Get(tsm.RegionName).Name == tsm.RegionName)
                {
                    if (!this.touristSpotLogic.AlreadyExistsByName(tsm.Name))
                    {
                        this.touristSpotLogic.Add(ts);
                        this.regionLogic.AddTouristSpotToRegion(tsm.RegionName, tsm.Name);
                    }
                }
                if (!this.accommodationLogic.AlreadyExistsByName(imported.Name) && this.touristSpotLogic.AlreadyExistsByName(tsm.Name))
                {
                    Accommodation acc = imported.ToEntity();
                    acc.TouristSpot = this.touristSpotLogic.GetByName(ts.Name);
                    this.accommodationLogic.Add(acc, this.touristSpotLogic.GetByName(ts.Name).Name);
                    return(true);
                }

                return(false);
            }
            catch (JsonReaderException)
            {
                throw new FileIsNotJsonException();
            }
        }
コード例 #2
0
        public AccommodationImportModel CreateObjectModel(string path)
        {
            AccommodationImportModel acc = JsonConvert.DeserializeObject <AccommodationImportModel>(File.ReadAllText(path));

            return(acc);
        }