public int GetFreeId() { //получим свободный id как максимальный плюс 1 var cityDatastore = CityDatastore.GetInstance(); int freeID = cityDatastore.Cities.Keys.Max() + 1; return(freeID); }
public static CityDatastore GetInstance() { if (_cityDatastore == null) { _cityDatastore = new CityDatastore(); } return(_cityDatastore); }
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); }
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); }
public bool isPrezent(int idn) { CityDatastore cityDatastore = CityDatastore.GetInstance(); return(cityDatastore.Cities.ContainsKey(idn)); }
public CityGetModel GetCityById(int idn) { CityDatastore cityDatastore = CityDatastore.GetInstance(); return(cityDatastore.Cities[idn]); }
public Dictionary <int, CityGetModel> GetAllCities() { CityDatastore cityDatastore = CityDatastore.GetInstance(); return(cityDatastore.Cities); }
public bool DeleteCity(int id) { var cityDatastore = CityDatastore.GetInstance(); return(cityDatastore.Cities.Remove(id)); }