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)); }
public IHttpActionResult Create(CityDTO cityDTO) { if (!ModelState.IsValid) { return(BadRequest()); } var city = Mapper.Map <CityDTO, City>(cityDTO); var cityDto = context.City.Add(city); context.SaveChanges(); var dto = Mapper.Map <City, CityDTO>(cityDto); return(Created(new Uri(Request.RequestUri.ToString()), dto)); }
public ActionResult Index(ReservationVM NewReservation) { using (var db = new Y2kContext()) { db.Reservacion.Add(NewReservation.Reservation); db.SaveChanges(); return(RedirectToAction("Resultado", new { Id = NewReservation.Reservation.Id })); } }
/// <summary> /// Guarda el clima de una ciudad en especifico /// </summary> /// <param name="id"></param> public static Models.Weather GetWeather(int id) { _id = id; Models.Weather weather = new Models.Weather(); string content = Task.Run(GetWeather).Result; WeatherAPI weathers = JsonConvert.DeserializeObject <WeatherAPI>(content); weather.IdExternal = weathers.weather[0].id; weather.Main = weathers.weather[0].main; weather.Description = weathers.weather[0].description; weather.Icon = weathers.weather[0].icon; weather.cod = weathers.cod; using (Y2kContext context = new Y2kContext()) { context.Weather.Add(weather); context.SaveChanges(); } return(weather); }
/// <summary> /// Carga las ciudades a la BD /// </summary> public static void GetCity() { using (Y2kContext context = new Y2kContext()) { if (!context.City.Any()) { string content = Task.Run(GetDate).Result; List <Models.City> cities = JsonConvert.DeserializeObject <List <Models.City> >(content); foreach (var c in cities) { Models.City city = new Models.City(); city.IdExternal = c.Id; city.Name = c.Name; city.Country = c.Country; context.City.Add(city); } context.SaveChanges(); } } }