public ActionResult <SampleContinent> AddContinent([FromBody] SampleContinent sampleContinent) { try { Continent continent = new Continent(sampleContinent.Name); if (ContinentManager.ContinentExists(continent)) { ContinentManager.Add(continent); return(CreatedAtAction(nameof(GetContinent), new { id = continent.ID }, continent)); } else { return(BadRequest("Continent already exists!")); } } catch (Exception ex) { return(BadRequest("ERROR : " + ex)); } }
public ActionResult <SampleContinent> Put(int id, [FromBody] SampleContinent sampleContinent) { try { var continent = ContinentManager.GetContinentById(id); if (ContinentManager.ContinentExists(new Continent(continent.Name))) { continent.SetName(continent.Name); ContinentManager.UpdateContinent(continent); return(CreatedAtAction(nameof(GetContinent), new { id = continent.ID }, continent)); } else { return(BadRequest("Continent error")); } } catch (Exception ex) { return(NotFound("Continent not found!")); } }
public ActionResult <SampleContinent> Put(int id, [FromBody] SampleContinent con) { try { var temp = ContinentManager.Get(id); if (ContinentManager.IfExist(new Continent(con.Name))) { logger.LogInformation("ContinentController : Put => " + DateTime.Now); temp.SetName(con.Name); ContinentManager.Update(temp); return(CreatedAtAction(nameof(Get), new { id = temp.ID }, temp)); } else { return(BadRequest("Continent already Exists")); } } catch (Exception e) { return(NotFound("Continent doesn't exist")); } }