private async Task GetAndBindData(LibrariesViewModel model, Cache cache) { //clear any error messages model.PostcodeLookupError = string.Empty; // need to convert miles to metres Int32 rad = (int)ConvertMilesToMetres(60); // call the appropriate method which returns a dataset DataSet ds = await GetNearestLibrariesRadialFromCms(rad, model.Postcode, cache); if (ds != null) { // get a default view on the dataset which we can then sort DataView dv = ds.Tables[0].DefaultView; // sort by distance dv.Sort = "Miles ASC"; // bind data foreach (DataRowView row in dv) { var libraryResult = new LibraryResult(); libraryResult.Name = row["Name"].ToString(); libraryResult.Url = new Uri(row["URL"].ToString(), UriKind.RelativeOrAbsolute); libraryResult.Description = row["Description"].ToString(); libraryResult.MilesAway = (double)row["Miles"]; model.Libraries.Add(libraryResult); } } if (model.Libraries.Count == 0) { model.PostcodeLookupError = Properties.Resources.ErrorNoLibrariesFound; } }
// GET: Default public async Task <ActionResult> Index(string postcode) { // Ensure there's one version of this URL so that the data is consistent in Google Analytics if (Path.GetFileName(Request.RawUrl).ToUpperInvariant() == "DEFAULT.ASPX") { return(new RedirectResult(Url.Content("~/"), true)); } var model = new LibrariesViewModel(); var templateRequest = new EastSussexGovUKTemplateRequest(Request); try { model.WebChat = await templateRequest.RequestWebChatSettingsAsync(); } catch (Exception ex) { // Catch and report exceptions - don't throw them and cause the page to fail ex.ToExceptionless().Submit(); } try { model.TemplateHtml = await templateRequest.RequestTemplateHtmlAsync(); } catch (Exception ex) { // Catch and report exceptions - don't throw them and cause the page to fail ex.ToExceptionless().Submit(); } return(View(model)); }
// GET: Default public async Task <ActionResult> Index(string pc) { var model = new LibrariesViewModel(); model.Postcode = pc; if (!String.IsNullOrEmpty(model.Postcode)) { try { await GetAndBindData(model, HttpContext.Cache); } catch (SoapException ex) { if (!ex.Message.Contains("The postcode entered appears to be incorrect.") && !ex.Message.Contains("The postcode entered could not be found.")) { ex.ToExceptionless().Submit(); } var helper = new SoapExceptionWrapper(ex); model.PostcodeLookupError = String.Format(CultureInfo.InvariantCulture, Properties.Resources.ErrorFromWebService, helper.Message, helper.Description); } } var templateRequest = new EastSussexGovUKTemplateRequest(Request); try { // Do this if you want your page to support web chat. It should, unless you have a reason not to. model.WebChat = await templateRequest.RequestWebChatSettingsAsync(); } catch (Exception ex) { // Catch and report exceptions - don't throw them and cause the page to fail ex.ToExceptionless().Submit(); } try { // Do this to load the template controls. model.TemplateHtml = await templateRequest.RequestTemplateHtmlAsync(); } catch (Exception ex) { // Catch and report exceptions - don't throw them and cause the page to fail ex.ToExceptionless().Submit(); } return(View(model)); }