Exemplo n.º 1
0
        public IHttpActionResult Create(WeatherTDO weatherDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var weather    = Mapper.Map <WeatherTDO, Weather>(weatherDTO);
            var weatherDto = context.Weather.Add(weather);

            context.SaveChanges();
            var dto = Mapper.Map <Weather, WeatherTDO>(weatherDto);

            return(Created(new Uri(Request.RequestUri.ToString()), dto));
        }
Exemplo n.º 2
0
        public IHttpActionResult Update(int id, WeatherTDO weatherDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var weather = context.City.Find(id);

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

            Mapper.Map(weatherDTO, weather);
            context.SaveChanges();
            return(Ok(weatherDTO));
        }