protected void btnSearch_Click(object sender, EventArgs e) { try { HomePageControl hpcSeek = new HomePageControl(); List<BookEntity> lstBooksData = new List<BookEntity>(); BookNotesEntity bneBookNotes = new BookNotesEntity(); bneBookNotes = hpcSeek.SeekAndGetBooks(txtSearch.Value, GetSearchCriteria(), hvfEmail.Value); lstBooksData = bneBookNotes.lstBook; if (lstBooksData.Count.Equals(0)) GetBooksFromGoogle(); else { ViewState["NoteDet"] = bneBookNotes.lstNote; BindGridData(lstBooksData); } } catch(Exception ex) { //log to be created ScriptManager.RegisterStartupScript(this, this.GetType(), "Apologies", "alert('We are facing a technical difficulty, Please try again later :-( ')", true); } }
internal BookNotesEntity SeekAndGetBookDet(String strTxtVal, int iSearchCondn, string strUserId) { try { cnn.Open(); SqlParameter[] spParameter = new SqlParameter[3]; spParameter[0] = new SqlParameter("@SearchFor", SqlDbType.VarChar); spParameter[0].Direction = ParameterDirection.Input; spParameter[0].Value = strTxtVal; spParameter[1] = new SqlParameter("@SearchCondn", SqlDbType.VarChar); spParameter[1].Direction = ParameterDirection.Input; spParameter[1].Value = iSearchCondn; spParameter[2] = new SqlParameter("@UserId", SqlDbType.VarChar); spParameter[2].Direction = ParameterDirection.Input; spParameter[2].Value = strUserId; DataSet ds = SqlHelper.ExecuteDataset(cnn, CommandType.StoredProcedure, "usp_SeekAndGetBookDet", spParameter); cnn.Close(); List<BookEntity> lstBooks = ds.Tables[0].AsEnumerable().Select(dataRow => new BookEntity { ISBNType = dataRow.Field<string>("ISBNType"), ISBNNo = dataRow.Field<string>("ISBN"), etag = dataRow.Field<string>("ETag"), title = dataRow.Field<string>("Title"), authors = dataRow.Field<string>("Author"), publisher = dataRow.Field<string>("Publisher"), publishedDate = dataRow.Field<string>("PublishDate"), Image = dataRow.Field<string>("ImageURL"), preview = dataRow.Field<string>("Preview"), pageCount = dataRow.Field<string>("PageCount"), textSnippet = dataRow.Field<string>("Snippet"), UserRead = dataRow.Field<string>("UserRead") }).ToList(); List<NotesEntity> lstNotes = ds.Tables[1].AsEnumerable().Select(dataRow => new NotesEntity { UserId = dataRow.Field<string>("UserId"), Notes = dataRow.Field<string>("NoteDetails"), ISBNNo = dataRow.Field<string>("ISBNNo") }).ToList(); BookNotesEntity bneCollection = new BookNotesEntity(); bneCollection.lstBook = lstBooks; bneCollection.lstNote = lstNotes; return bneCollection; } catch (Exception e) { //log to be created return null; } }