public static Cities CityToDal(CitiesDTO city) { return(new Cities() { CityId = city.CityId, CityName = city.CityName, Area = city.Area }); }
public CitiesDTO AddCity(string name) { var city = new Cities { Name = name }; _context.Cities.Add(city); _context.SaveChanges(); var cityDto = new CitiesDTO { Name = city.Name }; return(cityDto); }
public IHttpActionResult PostCities(CitiesDTO city) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Cities.Add(new Cities() { Name = city.Name }); var cityName = db.Cities.Where(s => s.Name == city.Name).FirstOrDefault(); if (cityName != null) { return(BadRequest("Grad sa ovim imenom već postoji")); } db.SaveChanges(); return(Ok(city.Name + " uspješno spremljen")); }