public ActionResult <SampleCountry> Put(int id, int CountryID, [FromBody] SampleCountry sampleCountry) { try { var continent = ContinentManager.GetContinentById(id); var country = CountryManager.GetCountry(CountryID); if (sampleCountry.Continent == null || sampleCountry.Continent == "") { sampleCountry.Continent = id.ToString(); } if (continent.Name == country.Continent.Name) { CountryManager.Update(country, sampleCountry.Name, sampleCountry.Population, sampleCountry.Surface, ContinentManager.GetContinentById(Int32.Parse(sampleCountry.Continent))); return(Ok()); } else { return(NotFound("Country Not found in Continent!")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult <SampleCountry> Put(int id, int con_id, [FromBody] SampleCountry con) { try { var tempCon = ContinentManager.Get(id); var temp = CountryManager.Get(con_id); if (con.Continent == null || con.Continent == "") { con.Continent = id.ToString(); } if (tempCon.Name == temp.Continent.Name) { logger.LogInformation("CountryController : Put => " + DateTime.Now); CountryManager.Update(temp, con.Name, con.Population, con.Surface, ContinentManager.Get(Int32.Parse(con.Continent))); return(Ok()); } else { return(NotFound("Country not found in Continent")); } } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <SampleCountry> Post(int id, [FromBody] SampleCountry sampleCountry) { try { CountryManager = new CountryManager(new UnitOfWork(new DataContext())); var country = new Country(sampleCountry.Name, ContinentManager.GetContinentById(id), sampleCountry.Population, sampleCountry.Surface); CountryManager.Add(country); return(CreatedAtAction(nameof(getCountry), new { id = country.Continent.ID, countryID = country.ID }, country)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult <SampleCountry> Post(int id, [FromBody] SampleCountry country) { try { CountryManager = new CountryManager(new UnitOfWork(new DataContext("test"))); var temp = new Country(country.Name, country.Population, country.Surface, ContinentManager.Get(id)); CountryManager.Add(temp); logger.LogInformation("CountryController : Post => " + DateTime.Now); return(CreatedAtAction(nameof(Get), new { id = temp.Continent.ID, con_id = temp.ID }, temp)); } catch (Exception e) { return(BadRequest(e.Message)); } }