Esempio n. 1
0
        public IHttpActionResult PutCity(int id, CityDTO city)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != city.CityId)
            {
                return(BadRequest());
            }

            Handin22.City city1 = _unitOfWork.Cities.Get(id);

            if (city1 == null)
            {
                return(NotFound());
            }

            city1.Name    = city.Name;
            city1.ZipCode = city.ZipCode;

            _unitOfWork.Complete();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public IHttpActionResult GetCity(int id)
        {
            Handin22.City city = _unitOfWork.Cities.Get(id);
            if (city == null)
            {
                return(NotFound());
            }

            return(Ok(city));
        }
Esempio n. 3
0
        public IHttpActionResult PostCity(CityDTO city)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Handin22.City city1 = new Handin22.City()
            {
                Name    = city.Name,
                ZipCode = city.ZipCode
            };

            _unitOfWork.Cities.Add(city1);
            _unitOfWork.Complete();

            return(CreatedAtRoute("DefaultApi", new { id = city.CityId }, city));
        }
Esempio n. 4
0
        public IHttpActionResult DeleteCity(int id)
        {
            Handin22.City city = _unitOfWork.Cities.Get(id);
            if (city == null)
            {
                return(NotFound());
            }

            _unitOfWork.Cities.Remove(city);
            _unitOfWork.Complete();

            var t = new CityDTO()
            {
                CityId  = city.CityId,
                ZipCode = city.ZipCode,
                Name    = city.Name
            };

            return(Ok(city));
        }