/* This overload of the ShowHotelDeals takes no paramters. * It is the one called when the page is rendered for the first time */ public ActionResult ShowHotelDeals() { Models.HotelDealsData objHotelDealsData = null; ViewBag.Message = "Your show hotel deals page."; objHotelDealsData = HotelDeals.GetHotelDeals(); return(View(objHotelDealsData.offers.Hotel)); }
public ActionResult ShowHotelDeals(IFormCollection frmCollection) { Models.HotelDealsData objHotelDealsData = null; var objSearchAtts = new Models.SearchAttributes(); DateTime TripStartDate = DateTime.MinValue; DateTime TripEndtDate = DateTime.MinValue; objSearchAtts.Destination = frmCollection["DestinationName"]; objSearchAtts.MinTripStartDate = frmCollection["StartDate"]; objSearchAtts.MaxTripStartDate = frmCollection["EndDate"]; objSearchAtts.MinStarRating = frmCollection["MinStarRate"]; objSearchAtts.MaxStarRating = frmCollection["MaxStarRate"]; objSearchAtts.MinGuestRating = frmCollection["MinGuestRate"]; objSearchAtts.MaxGuestRating = frmCollection["MaxGuestRate"]; objSearchAtts.MinTotalRating = frmCollection["MinTotalRate"]; objSearchAtts.MaxTotalRating = frmCollection["MaxTotalRate"]; //Persist search criteria to be rendered back to the search form. TempData["Destination"] = objSearchAtts.Destination; TempData["StartDate"] = objSearchAtts.MinTripStartDate; TempData["EndDate"] = objSearchAtts.MaxTripStartDate; TempData["MinStarRate"] = objSearchAtts.MinStarRating; TempData["MaxStarRate"] = objSearchAtts.MaxStarRating; TempData["MinGuestRate"] = objSearchAtts.MinGuestRating; TempData["MaxGuestRate"] = objSearchAtts.MaxGuestRating; TempData["MinTotalRate"] = objSearchAtts.MinTotalRating; TempData["MaxTotalRate"] = objSearchAtts.MaxTotalRating; if (objSearchAtts.MinTripStartDate != String.Empty) { TripStartDate = DateTime.Parse(objSearchAtts.MinTripStartDate); } if (objSearchAtts.MaxTripStartDate != String.Empty) { TripEndtDate = DateTime.Parse(objSearchAtts.MaxTripStartDate); } objSearchAtts.lengthOfStay = (int)(TripEndtDate.Subtract(TripStartDate).TotalDays); objHotelDealsData = HotelDeals.GetHotelDeals(objSearchAtts); if (objHotelDealsData == null) { return(View()); } else { return(View(objHotelDealsData.offers.Hotel)); } }
/* Takes an object that contains all the search fields that were added by the user. If the attributes */ /* GetAllDeals if true, then no search criteria was provided. */ public static Models.HotelDealsData GetHotelDeals(Models.SearchAttributes oSearchAtts) { Models.HotelDealsData objHotelDealsData = null; string url = "https://offersvc.expedia.com/offers/v2/getOffers?scenario=deal-finder&page=foo&uid=foo&productType=Hotel"; try { if (!oSearchAtts.GetAllDeals) { string queryString = MakeQueryString(oSearchAtts); url += queryString; } var syncClient = new WebClient(); var content = syncClient.DownloadString(url); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Models.HotelDealsData)); using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(content))) { objHotelDealsData = (Models.HotelDealsData)serializer.ReadObject(ms); } if (objHotelDealsData.offers.Hotel.Count > 0) { foreach (var Hotel in objHotelDealsData.offers.Hotel) { // this loop in case you need to do an processing on the returned returned data before send it back to the controller. } } return(objHotelDealsData); } catch { //Something went wrong //ToDO: Show an error message to the user. return(null); } }