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 Delete(int id)
 {
     try
     {
         var temp = ContinentManager.Get(id);
         if (temp != null)
         {
             if (CountryManager.GetByContinentName(temp).Count == 0)
             {
                 logger.LogInformation("ContinentController : Delete => " + DateTime.Now);
                 ContinentManager.Remove(id);
                 return(NoContent());
             }
             else
             {
                 return(BadRequest("Continent still has Countries"));
             }
         }
         else
         {
             return(NotFound("Continent not found"));
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
Пример #3
0
 public ActionResult <SampleCity> DeleteCity(int id, int countryId, int cityId)
 {
     try
     {
         var continent = ContinentManager.GetContinentById(id);
         var country   = CountryManager.GetCountry(countryId);
         if (continent.Name == country.Continent.Name)
         {
             var city = CityManager.GetCityById(cityId);
             if (city == null)
             {
                 return(NotFound("City does not exist in this Country!"));
             }
             else
             {
                 CityManager.RemoveCityById(cityId);
                 return(NoContent());
             }
         }
         else
         {
             return(NotFound("Country does not exist in this Continent!"));
         }
     }
     catch (Exception ex)
     {
         throw new Exception("ERROR City Controller in the Delete request (" + ex + ")");
     }
 }
        public ActionResult Delete(int id, int con_id)
        {
            try
            {
                var tempCon = ContinentManager.Get(id);
                var temp    = CountryManager.Get(con_id);

                if (tempCon.Name == temp.Continent.Name)
                {
                    if (temp.Cities.Count == 0 || temp.Cities == null)
                    {
                        logger.LogInformation("CountryController : Delete => " + DateTime.Now);
                        CountryManager.Remove(con_id);
                        return(NoContent());
                    }
                    else
                    {
                        return(BadRequest("Country still has Cities"));
                    }
                }
                else
                {
                    return(NotFound("Country not found in Continent"));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #5
0
        public ContinentManagerTests()
        {
            DataContextTests ctx = new DataContextTests(keepExistingDB: false);

            continentManager = new ContinentManager(new UnitOfWork(ctx));
            countryManager   = new CountryManager(new UnitOfWork(ctx));
        }
Пример #6
0
 public ActionResult <SampleCity> GetCity(int id, int countryId, int cityId)
 {
     try
     {
         var continent = ContinentManager.GetContinentById(id);
         var country   = CountryManager.GetCountry(countryId);
         if (continent.Name == country.Continent.Name)
         {
             var city = CityManager.GetCityById(cityId);
             if (city == null)
             {
                 return(NotFound("City does not exist in this County!"));
             }
             else
             {
                 return(new SampleCity {
                     ID = city.ID, Name = city.Name, Capital = city.IsCapital, Country = $"http://localhost:5001/api/Continent/{id}/Country/{countryId}", Population = city.Population
                 });
             }
         }
         else
         {
             return(NotFound("Country not found in Continent!"));
         }
     }
     catch (Exception ex)
     {
         throw new Exception("ERROR City Controller in the Get request (" + ex + ")");
     }
 }
 public ActionResult <SampleCountry> Get(int id, int con_id)
 {
     try
     {
         var tempCon = ContinentManager.Get(id);
         var temp    = CountryManager.Get(con_id);
         if (tempCon.Name == temp.Continent.Name)
         {
             logger.LogInformation("CountryController : Get => " + DateTime.Now);
             return(new SampleCountry
             {
                 ID = temp.ID,
                 Name = temp.Name,
                 Continent = $"https://localhost:5001/api/Continent/" + temp.Continent.ID,
                 Population = temp.Population,
                 Surface = temp.Surface,
                 Cities = temp.Cities.Select(k => $"https://localhost:5001/api/Continent/{temp.Continent.ID}/Country/{temp.ID}/City/" + k.ID.ToString()).ToList(),
                 Rivers = temp.Rivers.Select(x => $"https://localhost:5001/api/River/" + x.ID.ToString()).ToList()
             });
         }
         else
         {
             return(NotFound("Country not found in Continent"));
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #8
0
 public RiverController(ILogger <RiverController> logger)
 {
     this.logger      = logger;
     ContinentManager = new ContinentManager(new UnitOfWork(new DataContext("test")));
     CountryManager   = new CountryManager(new UnitOfWork(new DataContext("test")));
     RiverManager     = new RiverManager(new UnitOfWork(new DataContext("test")));
 }
Пример #9
0
 public ActionResult <SampleCity> Delete(int id, int country_id, int city_id)
 {
     try
     {
         var tempCon = ContinentManager.Get(id);
         var tempCou = CountryManager.Get(country_id);
         if (tempCon.Name == tempCou.Continent.Name)
         {
             var temp = CityManager.Get(city_id);
             if (temp == null)
             {
                 return(NotFound("City not found in Country"));
             }
             else
             {
                 logger.LogInformation("CityController : Delete => " + DateTime.Now);
                 CityManager.Remove(city_id);
                 return(NoContent());
             }
         }
         else
         {
             return(NotFound("Country not found in Continent"));
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #10
0
        public void CountryManagerTest()
        {
            CityManager      cityManager      = new CityManager(new UnitOfWork(new DataContext()));
            CountryManager   countryManager   = new CountryManager(new UnitOfWork(new DataContext()));
            ContinentManager continentManager = new ContinentManager(new UnitOfWork(new DataContext()));

            //Verwijder alles in tabels
            cityManager.RemoveAll();
            countryManager.RemoveAllCountries();
            continentManager.RemoveAll();

            //Aanmaak Continent
            continentManager.Add(new Continent("TestContinent"));
            List <Continent> continents = continentManager.GetAllContinents();
            Continent        continent  = continents[0];

            Assert.AreEqual(1, continents.Count);

            //Toevoegen van Country
            countryManager.Add(new Country("TestCountry", continent, 100, 10));

            List <Country> countries = countryManager.GetAllCountries();
            Country        country   = countries[0];

            Assert.AreEqual(1, countries.Count);
            Assert.AreEqual("TestCountry", country.Name);

            //Verwijder alles in tabels
            cityManager.RemoveAll();
            countryManager.RemoveAllCountries();
            continentManager.RemoveAll();
        }
Пример #11
0
 public ActionResult <SampleCity> Get(int id, int country_id, int city_id)
 {
     try
     {
         var tempCon = ContinentManager.Get(id);
         var tempCou = CountryManager.Get(country_id);
         if (tempCon.Name == tempCou.Continent.Name)
         {
             var temp = CityManager.Get(city_id);
             if (temp == null)
             {
                 return(NotFound("City not found in Country"));
             }
             else
             {
                 logger.LogInformation("CityController : Get => " + DateTime.Now);
                 return(new SampleCity {
                     ID = temp.ID, name = temp.Name, Capital = temp.IsCapital, Country = $"https://localhost:5001/api/Continent/{id}/Country/{country_id}", Population = temp.Population
                 });
             }
         }
         else
         {
             return(NotFound("Country not found in Continent"));
         }
     }catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #12
0
 public CityController(ILogger <CityController> logger)
 {
     this.logger      = logger;
     ContinentManager = new ContinentManager(new UnitOfWork(new DataContext("test")));
     CountryManager   = new CountryManager(new UnitOfWork(new DataContext("test")));
     CityManager      = new CityManager(new UnitOfWork(new DataContext("test")));
 }
Пример #13
0
 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));
     }
 }
Пример #14
0
 public ActionResult Delete(int id)
 {
     try
     {
         var continent = ContinentManager.GetContinentById(id);
         if (continent != null)
         {
             if (CountryManager.GetContinentWithName(continent).Count == 0)
             {
                 ContinentManager.RemoveContinent(id);
                 return(NoContent());
             }
             else
             {
                 return(BadRequest("Continent still has countries!"));
             }
         }
         else
         {
             return(NotFound("Continent not found!"));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
Пример #15
0
 public override Task OnUpdate(DateTime now)
 {
     return(Task.WhenAll(new List <Task>
     {
         FieldManager.OnUpdate(now),
         ContinentManager.OnUpdate(now)
     }));
 }
Пример #16
0
        public override async Task OnTick(DateTime now)
        {
            await base.OnTick(now);

            await FieldManager.OnTick(now);

            await ContinentManager.OnTick(now);
        }
Пример #17
0
 public ContinentController(IConfiguration iconfiguration, ContinentManager continentManager,
                            CountryManager countryManager, ILoggerFactory loggerFactory)
 {
     hostUrl = iconfiguration.GetValue <string>("profiles:GeoService.Api:applicationUrl");
     this.continentManager = continentManager;
     this.countryManager   = countryManager;
     logger = loggerFactory.AddFile("ControllerLogs.txt").CreateLogger("Continent");
 }
Пример #18
0
        public static Country CountryInMapper(ContinentManager continentManager, CountryInApi countryIn)
        {
            Country country = new Country();

            country.Name       = countryIn.Name;
            country.Population = countryIn.Population;
            country.Surface    = countryIn.Surface;
            country.Continent  = continentManager.Find(countryIn.ContinentId);
            return(country);
        }
Пример #19
0
        public void Country_Manager_Test()
        {
            CountryManager   tempCountry   = new CountryManager(new UnitOfWork(new DataContext("test")));
            ContinentManager tempContinent = new ContinentManager(new UnitOfWork(new DataContext("test")));

            tempCountry.RemoveAll();
            tempContinent.RemoveAll();

            tempContinent.Add(new Continent("test-Continent"));
            tempContinent.Add(new Continent("test-Continent1"));
            List <Continent> continents = tempContinent.GetAll();

            Assert.AreEqual(2, continents.Count);
            Assert.AreEqual("test-Continent", continents[0].Name);

            tempCountry.Add(new Country("test", 500, 200, continents[0]));
            tempCountry.Add(new Country("test-Country1", 50, 20, continents[0]));

            List <Country> countries = tempCountry.GetAll();
            Country        country1  = tempCountry.Get(countries[0].ID);
            Country        country2  = tempCountry.Get(countries[1].ID);

            Assert.AreEqual(2, countries.Count);
            Assert.AreEqual("test", country1.Name);
            Assert.AreEqual("test-Country1", country2.Name);

            Assert.AreEqual(500, country1.Population);
            Assert.AreEqual(50, country2.Population);

            Assert.AreEqual(200, country1.Surface);
            Assert.AreEqual(20, country2.Surface);

            tempCountry.Update(country1, "test-Country", 2000, 10, continents[1]);
            countries = tempCountry.GetAll();
            country1  = tempCountry.Get(countries[0].ID);
            country2  = tempCountry.Get(countries[1].ID);

            Assert.AreEqual(2, countries.Count);
            Assert.AreEqual("test-Country", country1.Name);
            Assert.AreEqual("test-Country1", country2.Name);

            Assert.AreEqual(2000, country1.Population);
            Assert.AreEqual(50, country2.Population);

            Assert.AreEqual(10, country1.Surface);
            Assert.AreEqual(20, country2.Surface);

            tempCountry.Remove(country1.ID);

            countries = tempCountry.GetAll();
            Assert.AreEqual(1, countries.Count);

            tempCountry.RemoveAll();
            tempContinent.RemoveAll();
        }
Пример #20
0
 public ActionResult <SampleContinent> GetContinent(int id)
 {
     try
     {
         var continent   = ContinentManager.GetContinentById(id);
         var countryList = CountryManager.GetContinentWithName(continent).Select(x => $"http://localhost:3000/api/Continent/{continent.ID}/Country/" + x.ID.ToString()).ToList();
         return(new SampleContinent {
             ID = continent.ID.ToString(), Name = continent.Name, Population = continent.Population, Countries = countryList
         });
     }
     catch (Exception ex)
     {
         return(NotFound("Continent not found!"));
     }
 }
Пример #21
0
        private static void Main(string[] args)
        {
            ContinentManager continentManager = new ContinentManager(new UnitOfWork());
            CountryManager   countryManager   = new CountryManager(new UnitOfWork());

            Continent continent1       = new Continent("Antartica");
            Continent continent2       = new Continent("Europe");
            Continent continent1WithId = continentManager.AddContinent(continent1);
            Continent continent2WithId = continentManager.AddContinent(continent2);
            Country   country1         = new Country("Tuvalu", 11792, 30, continent1WithId);
            Country   country2         = new Country("Nauru", 10824, 20, continent1WithId);

            countryManager.AddCountry(country1);
            countryManager.AddCountry(country2);
        }
 public ActionResult <SampleContinent> Get(int id)
 {
     try
     {
         var temp     = ContinentManager.Get(id);
         var tempList = CountryManager.GetByContinentName(temp).Select(s => $"https://localhost:5001/api/Continent/{temp.ID}/Country/" + s.ID.ToString()).ToList();
         logger.LogInformation("ContinentController : Get => " + DateTime.Now);
         return(new SampleContinent {
             ID = temp.ID.ToString(), Name = temp.Name, Population = temp.Population, Countries = tempList
         });
     }
     catch (Exception e)
     {
         return(NotFound("Continent doesn't exist"));
     }
 }
Пример #23
0
 public ActionResult <List <SampleContinent> > GetAllContinents()
 {
     try
     {
         return(ContinentManager.GetAllContinents().Select(x => new SampleContinent
         {
             ID = $"http://localhost:3000/api/Continent/{x.ID}",
             Name = x.Name,
             Population = x.Population,
             Countries = CountryManager.GetContinentWithName(x).Select(y => $"http://localhost:3000/api/Continent/{x.ID}/Country/" + y.ID.ToString()).ToList()
         }).ToList());
     }
     catch
     {
         Response.StatusCode = 400;
         return(null);
     }
 }
 public ActionResult <List <SampleContinent> > GetAll()
 {
     try
     {
         logger.LogInformation("ContinentController : GetAll => " + DateTime.Now);
         return(ContinentManager.GetAll().Select(s => new SampleContinent
         {
             ID = $"https://localhost:5001/api/Continent/{s.ID}",
             Name = s.Name,
             Population = s.Population,
             Countries = CountryManager.GetByContinentName(s).Select(k => $"https://localhost:5001/api/Continent/{s.ID}/Country/" + k.ID.ToString()).ToList()
         }).ToList());
     }
     catch
     {
         Response.StatusCode = 400;
         return(null);
     }
 }
Пример #25
0
    private void SetUpContinents()
    {
        //Store information about the main continent before we do anything
        ContinentManager contMan = continentsMain.GetComponent <ContinentManager>();

        contMan.InstantiateMainContinent(connectionManager, gameManager, lineDraw, continentsMain.transform.Find("Player").gameObject, peopleManager.updateRate);

        //Store information about the respawn details for the continents
        BoxCollider2D curCollider = continentsMain.transform.GetComponent <BoxCollider2D>(); //Get the box collider

        _continentWidth = curCollider.size.x * continentsMain.transform.localScale.x;

        _continentRespawnPosX = continentsMain.transform.position.x + _continentWidth;

        //We generate copies of the current continent map and move the main version side
        _continents1 = Instantiate(continentsMain, worldMapParent);
        _continents2 = Instantiate(continentsMain, worldMapParent);
        //ContinentsForward is a false continent ahead of our current continent to maintain lines
        _continentsForward = Instantiate(continentsMain, worldMapParent);

        connectionManager.currentPlayer = _continents1.GetComponent <ContinentManager>().player;

        //Change the position of the second set of continents and set the first continent as our main
        _continents2.transform.position = SpawnPosition(continentsMain.transform.position, _continentWidth);
        curContinent = _continents1;
        _curCont1    = true;

        //Change the position of the forward continent for previewing purposes
        _continentsForward.transform.position = ForwardSpawnPosition(continentsMain.transform.position, _continentWidth);

        //Move the main continent out of the way
        Vector3 holdPos = continentsMain.transform.position;

        holdPos.y += 50; //Offset out of the way by 50.
        continentsMain.transform.position = holdPos;

        //Send references of our active players to PeopleManager
        peopleManager.player1 = _continents1.transform.Find("Player").gameObject;
        peopleManager.player2 = _continents2.transform.Find("Player").gameObject;
        //Set Player1 as the active player
        peopleManager.player1Active = true;
    }
Пример #26
0
 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> AddContinent([FromBody] Sample_Models.SampleContinent con)
 {
     try
     {
         Continent temp = new Continent(con.Name);
         if (ContinentManager.IfExist(temp))
         {
             ContinentManager.Add(temp);
             logger.LogInformation("ContinentController : Add => " + DateTime.Now);
             return(CreatedAtAction(nameof(Get), new { id = temp.ID }, temp));
         }
         else
         {
             return(BadRequest("Continent already exist"));
         }
     }
     catch (Exception e)
     {
         return(BadRequest("Something went wrong : " + e));
     }
 }
 public ActionResult <List <SampleCountry> > GetAll(int id)
 {
     try
     {
         var temp = ContinentManager.Get(id);
         logger.LogInformation("CountryController : GetAll => " + DateTime.Now);
         return(CountryManager.GetByContinentName(temp).Select(s => new SampleCountry
         {
             ID = s.ID,
             Name = s.Name,
             Population = s.Population,
             Continent = $"https://localhost:5001/api/Continent/" + temp.ID,
             Surface = s.Surface,
             Cities = s.Cities.Select(k => $"https://localhost:5001/api/Continent/{temp.ID}/Country/{s.ID}/City/" + k.ID.ToString()).ToList(),
             Rivers = s.Rivers.Select(x => $"https://localhost:5001/api/River/" + x.ID.ToString()).ToList()
         }).ToList());
     }catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #29
0
        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!"));
            }
        }
Пример #30
0
 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 + ")");
     }
 }