Exemple #1
0
 public ActionResult Post([FromBody] SampleRiver river)
 {
     try
     {
         List <Country> tempList = new List <Country>();
         foreach (var country in CountryManager.GetAll())
         {
             if (river.Countries.Contains(country.ID.ToString()))
             {
                 tempList.Add(country);
             }
         }
         if (tempList.Count == river.Countries.Count)
         {
             logger.LogInformation("RiverController : Get => " + DateTime.Now);
             River x = new River(river.Name, river.Lenght, tempList);
             RiverManager.Add(x);
             return(CreatedAtAction(nameof(Get), new { id = x.ID }, x));
         }
         else
         {
             return(NotFound("Country input not found"));
         }
     }catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Exemple #2
0
        public ActionResult <SampleRiver> Put(int id, [FromBody] SampleRiver river)
        {
            try
            {
                var temp = RiverManager.Get(id);
                if (temp == null)
                {
                    return(NotFound("River is not found"));
                }
                else
                {
                    List <Country> tempList = new List <Country>();
                    foreach (var country in CountryManager.GetAll())
                    {
                        if (river.Countries.Contains(country.ID.ToString()))
                        {
                            tempList.Add(country);
                        }
                    }
                    if (tempList.Count == river.Countries.Count)
                    {
                        logger.LogInformation("RiverController : Put => " + DateTime.Now);

                        RiverManager.Update(temp, river.Name, river.Lenght, tempList);
                        return(Ok());
                    }
                    else
                    {
                        return(NotFound("Country input not found"));
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }