/// <summary> /// Searches the database for blog posts containing the specified keywords /// </summary> /// <param name="searchTerm">Search term for which to query the model against</param> /// <returns>The search results of the query</returns> public ActionResult Search(string searchTerm) { BlogListBase model; List<BlogPost> posts; using (IDataRepository<BlogPost> repository = new DataRepository<BlogPost>()) // TODO: Replace this with StructureMap { posts = (from b in repository.Fetch() where b.Title.Contains(searchTerm) || b.Post.Contains(searchTerm) select b).ToList(); } model = new BlogListBase(posts); return View(model); }
/// <summary> /// Searches the database for blog posts containing the specified tags /// </summary> /// <param name="tag">Search term for which to query the model against</param> /// <returns>The search results of the query</returns> public ActionResult SearchByTag(string tag) { Guid blogId = BlogUtility.GetBlogId(); BlogListBase model; List<BlogPost> posts; IObjectContext context = new ObjectContextAdapter(DatabaseUtility.GetContext()); using (IBlogPostRepository blogPostRepository = ObjectFactory.With(context).GetInstance<IBlogPostRepository>()) using (IKeywordRepository keywordRepository = ObjectFactory.With(context).GetInstance<IKeywordRepository>()) { // TODO: There must be a better way to do this posts = (from k in keywordRepository.Fetch() where k.BlogId == blogId && k.Keyword1 == tag select k.BlogPosts).ToList()[0].ToList(); } model = new BlogListBase(posts); return View("Search", model); }