/// <summary> /// Método para poblar el table View /// </summary> /// <param name="data"></param> private void PopulateData(ResponseBooksDto data) { ResponseBooksDto = data; if (BooksTVSource == null) { //se registra el recurso Nib en el table view this.tvBooks.RegisterNibForCellReuse(UINib.FromName("BooksTVCell", null), "BooksTVCell"); BooksTVSource = new BooksTVSource(data.Books); this.tvBooks.Source = BooksTVSource; this.tvBooks.RowHeight = UITableView.AutomaticDimension; this.tvBooks.EstimatedRowHeight = UITableView.AutomaticDimension; BooksTVSource.LoadMoreData += BooksTVSource_LoadMoreData; } if (Page > 1) { //Si es una carga hecha desde el scroll, se concatena los resultados foreach (var item in data.Books) { BooksTVSource.DataList.Add(item); } } else { BooksTVSource.DataList = data.Books; } this.tvBooks.ReloadData(); }
/// <summary> /// Obtiene los libros /// </summary> /// <param name="query">texto query del filtro</param> /// <param name="page">página que se va a configurar</param> /// <returns></returns> public static async Task <ResponseBooksDto> GetBooksAsync(string query, int page) { var responseEntity = new ResponseBooksDto(); try { var url = string.Format("{0}/search/{1}/page/{2}", GlobalConfig.BASE_URL, query, page); HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url); wr.Method = "GET"; wr.ContentType = "application/json"; using (WebResponse response = await wr.GetResponseAsync()) { using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream())) { string responseString = sr.ReadToEnd(); responseEntity = JsonConvert.DeserializeObject <ResponseBooksDto>(responseString); return(responseEntity); } } } catch (System.Net.WebException webEx) { var message = string.Format(ResourcesAgent.GetResource("strWebException"), JsonConvert.SerializeObject(webEx)); responseEntity.Error = "Ha ocurrido un error"; return(responseEntity); } catch (Exception ex) { var message = string.Format(ResourcesAgent.GetResource("strGenericException"), JsonConvert.SerializeObject(ex)); responseEntity.Error = "Ha ocurrido un error"; return(responseEntity); } }