Esempio n. 1
0
        public int GetFreeId()
        {
            //получим свободный id как максимальный плюс 1
            var cityDatastore = CityDatastore.GetInstance();
            int freeID        = cityDatastore.Cities.Keys.Max() + 1;

            return(freeID);
        }
Esempio n. 2
0
        public static CityDatastore GetInstance()
        {
            if (_cityDatastore == null)
            {
                _cityDatastore = new CityDatastore();
            }

            return(_cityDatastore);
        }
Esempio n. 3
0
        public CityGetModel UpdateCity(int id, CityGetModel City)
        {
            var cityDatastore = CityDatastore.GetInstance();

            CityGetModel updatedCity = cityDatastore.Cities[id];

            updatedCity.Name                    = City.Name;
            updatedCity.description             = City.description;
            updatedCity.NumberOfPintsOfInterest = City.NumberOfPintsOfInterest;

            return(updatedCity);
        }
Esempio n. 4
0
        public CityGetModel AddCity(CityCreateModel newCity)
        {
            var          cityDatastore = CityDatastore.GetInstance();
            CityGetModel cityGetModel  = new CityGetModel();
            int          freeId        = GetFreeId();

            cityGetModel.Id                      = freeId;
            cityGetModel.Name                    = newCity.Name;
            cityGetModel.description             = newCity.description;
            cityGetModel.NumberOfPintsOfInterest = newCity.NumberOfPintsOfInterest;

            cityDatastore.Cities.Add(freeId, cityGetModel);
            return(cityGetModel);
        }
Esempio n. 5
0
        public bool isPrezent(int idn)
        {
            CityDatastore cityDatastore = CityDatastore.GetInstance();

            return(cityDatastore.Cities.ContainsKey(idn));
        }
Esempio n. 6
0
        public CityGetModel GetCityById(int idn)
        {
            CityDatastore cityDatastore = CityDatastore.GetInstance();

            return(cityDatastore.Cities[idn]);
        }
Esempio n. 7
0
        public Dictionary <int, CityGetModel> GetAllCities()
        {
            CityDatastore cityDatastore = CityDatastore.GetInstance();

            return(cityDatastore.Cities);
        }
Esempio n. 8
0
        public bool DeleteCity(int id)
        {
            var cityDatastore = CityDatastore.GetInstance();

            return(cityDatastore.Cities.Remove(id));
        }