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

            return(freeID);
        }
Example #2
0
        public static CityDatastore GetInstance()
        {
            if (_cityDatastore == null)
            {
                _cityDatastore = new CityDatastore();
            }

            return(_cityDatastore);
        }
Example #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);
        }
Example #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);
        }
Example #5
0
        public bool isPrezent(int idn)
        {
            CityDatastore cityDatastore = CityDatastore.GetInstance();

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

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

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

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