public IList<UserBookRequest> SearchUser(String searchString) { try { String searchPattern = "%" + searchString + "%"; IDal<UserBookRequest> dal = new Dal<UserBookRequest>(); NHibernate.ISession session = dal.GetSession(); var criteriaQuery = session.CreateCriteria<UserBookRequest>("ubr") .CreateAlias("ubr.User","u") .CreateAlias("ubr.BookRequest","br") .CreateAlias("br.Book","b") .Add(Restrictions.Disjunction() .Add(Restrictions.Like("u.Name", searchPattern)) .Add(Restrictions.Like("u.Username", searchPattern)) .Add(Restrictions.Like("b.Name", searchPattern))); IList<UserBookRequest> returnedList = dal.Search(criteriaQuery); return returnedList; } catch (Exception e) { Console.WriteLine("Some problem with UserDal SearchUser()"); Console.Write(e.ToString()); return null; } }
public IList<Book> SearchBook(String searchString) { try { IDal<Book> dal = new Dal<Book>(); NHibernate.ISession session = dal.GetSession(); var criteriaQuery = session.CreateCriteria<Book>() .Add(Restrictions.Disjunction() .Add(Restrictions.Like("Name", "%"+searchString+"%")) .Add(Restrictions.Like("Author", "%" + searchString + "%")) .Add(Restrictions.Like("Publisher", "%"+searchString+"%")) .Add(Restrictions.Like("Description", "%" + searchString + "%"))); IList<Book> returnedList = dal.Search(criteriaQuery); return returnedList; } catch (Exception e) { Console.WriteLine("Some problem with BookDal SearchBook()"); Console.Write(e.ToString()); return null; } }