public ActionResult Post(int id, int country_id, [FromBody] SampleCity con) { try { var tempCon = ContinentManager.Get(id); var tempCou = CountryManager.Get(country_id); if (tempCon.Name == tempCou.Continent.Name) { var temp = new City(con.name, con.Population, tempCou, con.Capital); if (CityManager.CalculatePopulationCheck(temp)) { CityManager.Add(temp); logger.LogInformation("CityController : Post => " + DateTime.Now); return(CreatedAtAction(nameof(Get), new { id = tempCon.ID, country_id = tempCou.ID, city_id = temp.ID }, temp)); } else { return(BadRequest("Too much population for Country")); } } else { return(NotFound("Country not found in Continent")); } }catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult PostCity(int id, int countryId, [FromBody] SampleCity city) { try { var continent = ContinentManager.GetContinentById(id); var country = CountryManager.GetCountry(countryId); if (continent.Name == country.Continent.Name) { var tmpCity = new City(city.Name, city.Population, country, city.Capital); CityManager.Add(tmpCity); return(CreatedAtAction(nameof(GetCity), new { id = continent.ID, countryId = country.ID, cityId = tmpCity.ID }, tmpCity)); } else { return(BadRequest("Country not found in Continent!")); } } catch (Exception ex) { throw new Exception("ERROR City Controller in the Post request (" + ex + ")"); } }
public ActionResult <SampleCity> Put(int id, int country_id, int city_id, [FromBody] SampleCity con) { try { var tempCon = ContinentManager.Get(id); var tempCou = CountryManager.Get(country_id); var getNewCountry = CountryManager.Get(Int32.Parse(con.Country)); if (tempCon.Name == tempCou.Continent.Name) { var temp = CityManager.Get(city_id); if (temp == null) { return(NotFound("City not found in Country")); } else { if (getNewCountry != null) { CityManager.Update(temp, con.name, con.Population, con.Capital, getNewCountry); logger.LogInformation("CityController : Put => " + DateTime.Now); return(Ok()); } else { return(NotFound("Country input not found")); } } } else { return(NotFound("Country not found in Continent")); } } catch (Exception e) { return(BadRequest(e.Message)); } }