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")); } }
public void Continent_Manager_Test() { ContinentManager temp = new ContinentManager(new UnitOfWork(new DataContext("test"))); temp.RemoveAll(); Continent con = new Continent("test-continent"); Assert.AreEqual(0, con.ID); temp.Add(con); temp.Add(new Continent("test-continent1")); List <Continent> continents = temp.GetAll(); Continent continent1 = temp.Get(continents[0].ID); Continent continent2 = temp.Get(continents[1].ID); Assert.AreEqual(2, continents.Count); Assert.AreEqual("test-continent", continent1.Name); Assert.AreEqual("test-continent1", continent2.Name); temp.Remove(continent1.ID); continents = temp.GetAll(); continent1 = temp.Get(continents[0].ID); Assert.AreEqual(1, continents.Count); Assert.AreEqual("test-continent1", continent1.Name); continent1.SetName("test"); temp.Update(continent1); continents = temp.GetAll(); continent1 = temp.Get(continents[0].ID); Assert.AreEqual("test", continent1.Name); temp.RemoveAll(); }