diff --git a/Assignment1/Views/Recipe/AllRecipes.cshtml b/Assignment1/Views/Recipe/AllRecipes.cshtml
index 14caad7..647fdf2 100644
--- a/Assignment1/Views/Recipe/AllRecipes.cshtml
+++ b/Assignment1/Views/Recipe/AllRecipes.cshtml
@@ -6,20 +6,7 @@
@using (Html.BeginForm("AllRecipes", "Recipe", FormMethod.Get))
{
-
+ @Html.TextBox("query")
}
@@ -29,68 +16,31 @@
Cook time |
-
- @{string[] queryWords = Context.Request.Query["query"].ToString().ToLower().Split(' ');}
@functions {
- public bool query(Assignment1.Models.Recipe recipe)
+ public bool query(Assignment1.Models.Recipe recipe)
+ {
+ /*
+ * Query the recipe to see if it contains the user's search words
+ */
+ List properties = new List { recipe.Instructions, recipe.RecipeID.ToString(), recipe.Title, recipe.TotalTime.ToString() };
+ string query = Context.Request.Query["query"].ToString().ToLower();
+ foreach (String property in properties)
{
- ///*
- // * Query the recipe to see if it contains the user's search words. If there is no search words, just shows all recipes
- // */
-
- if (Context.Request.Query["query"].Any() && !Context.Request.Query["query"][0].Equals(""))
- {
- string[] titleWords = recipe.Title.Split(' ');
- string[] queryWords = Context.Request.Query["query"].ToString().ToLower().Split(' ');
- foreach (string queryWord in queryWords)
- {
- foreach (string titleWord in titleWords)
- {
- if (queryWord.ToLower() == titleWord.ToLower())
- {
- return true;
- }
- }
- }
-
- return false;
- }
- else
- {
- return true;
- }
-
- }
-
- public bool category(string category)
- {
- if (Context.Request.Query["category"].Any() && !Context.Request.Query["category"][0].Equals(""))
- {
- if (category.ToLower().Contains(Context.Request.Query["category"].ToString().ToLower()))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
+ if (property.ToLower().Contains(query))
{
return true;
}
}
+ return false;
+ }
}
-
@{ int counter = 1; }
-
- @foreach (Assignment1.Models.Recipe recipe in Model)
+ @foreach (Assignment1.Models.Recipe recipe in Model)
+ {
+ @if (query(recipe))
{
-
- @if (query(recipe) && category(recipe.Category))
- {
-
-
+
+
@*sets the class as alternate for the odd rows according to the RecipeID*@
|
@recipe.Title@*passes the RecipeID of the clicked recipe through the URL*@
@@ -98,24 +48,8 @@
| @recipe.TotalTime |
@recipe.CookTime |
-
- counter++;
- }
-
- }
-
-
-@if (counter == 1)
-{
-
-
-
- No recipe could be found with the selected filters:
- - Category: @Context.Request.Query["category"]
- - Search words: @(Context.Request.Query["query"].ToString())
-
-}
\ No newline at end of file
+ }
+
\ No newline at end of file