Example #1
0
 public City MapAndSaveCityModelDCToCity(City a, CityModelDC b)
 {
     a.CityId   = b.cityId;
     a.CityName = b.cityName;
     a.CountyId = b.countyId;
     return(a);
 }
Example #2
0
 public CityModelDC MapAndSaveCityToCityModelDC(CityModelDC a, City b)
 {
     a.cityId   = b.CityId;
     a.cityName = b.CityName;
     a.countyId = b.CountyId;
     return(a);
 }
Example #3
0
 public void UpdateCity(int id, CityModelDC obj)
 {
     if (id < 0)
     {
         throw new ArgumentException(Messages.CityExceptionUpdateById);
     }
     this._cityDAL.UpdateCity(id, obj);
 }
Example #4
0
 public City MapToCity(CityModelDC a)
 {
     return(new City()
     {
         CityId = a.cityId,
         CityName = a.cityName,
         CountyId = a.countyId
     });
 }
Example #5
0
 public void AddCity(CityModelDC obj)
 {
     foreach (CityModelDC city in _cityDAL.GetCities())
     {
         if (city.cityId == obj.cityId)
         {
             throw new ArgumentException(Messages.CityExceptionAdd);
         }
     }
     this._cityDAL.AddCity(obj);
 }
        public void UpdateCity(int id, CityModelDC obj)
        {
            if (id < 0)
            {
                throw new ArgumentOutOfRangeException(Messages.CityExceptionUpdateById);
            }

            City city = _db.Cities.FirstOrDefault(x => x.CityId == id);

            if (city == null)
            {
                throw new ArgumentException(Messages.CityExceptionUpdateById);
            }

            city = MapAndSaveCityModelDCToCity(city, obj);
            _db.SaveChanges();
        }
        public void AddCity(CityModelDC obj)
        {
            foreach (City city in _db.Cities)
            {
                if (city.CityId == obj.cityId)
                {
                    throw new ArgumentOutOfRangeException(Messages.CityExceptionAdd);
                }
            }
            if (obj == null)
            {
                throw new ArgumentOutOfRangeException(Messages.CityExceptionAdd);
            }

            _db.Cities.Add(MapToCity(obj));
            _db.SaveChanges();
        }
 // PUT: api/City/5
 public void Put(int id, [FromBody] CityModelDC city)
 {
     cityMethods.UpdateCity(id, city);
 }
 // POST: api/City
 public void Post([FromBody] CityModelDC city)
 {
     cityMethods.AddCity(city);
 }