Ejemplo n.º 1
0
 public void AddCity(DefaultCity city)
 {
     if (Db.DefaultCities.FirstOrDefault(c => c.Name == city.Name) != null)
     {
         throw new NotUniqueDefaulCityException("City " + city.Name + " already exists in table.");
     }
     else
     {
         Db.DefaultCities.Add(city);
     }
 }
 public IHttpActionResult Delete([FromUri] DefaultCity city)
 {
     if (ctx.DefaultCities.RemoveCity(city))
     {
         ctx.Complete();
         return(Ok());
     }
     else
     {
         return(NotFound());
     }
 }
 public IHttpActionResult Add([FromUri] DefaultCity city)
 {
     if (city.Name.Length > 0)
     {
         ctx.DefaultCities.AddCity(city);
         ctx.Complete();
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 4
0
        public bool RemoveCity(DefaultCity city)
        {
            DefaultCity cityToRemove = Db.DefaultCities.FirstOrDefault(c => c.Name == city.Name);

            if (city != null)
            {
                Db.DefaultCities.Remove(cityToRemove);
                return(true);
            }
            else
            {
                return(false);
            }
        }