Skip to content

Commit

Permalink
functionality of search done
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamFXX committed Jan 9, 2025
1 parent 8b5f4a1 commit aaf19a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions FoodMenu/FoodMenu/Controllers/FoodMenu.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FoodMenu.Data;
using FoodMenu.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.TagHelpers.Cache;
using Microsoft.EntityFrameworkCore;

namespace FoodMenu.Controllers
Expand All @@ -14,10 +15,19 @@ public FoodMenu(FoodMenuContext context)
_context = context;
}

public async Task<IActionResult> Index()
public async Task<IActionResult> Index(string searchString)
{
var dishes = from d in _context.Dishes
select d;

if (!string.IsNullOrEmpty(searchString))
{
dishes = dishes.Where(d => d.Name.Contains(searchString));
return View(await dishes.ToListAsync());
}

//await počká na odpověd contextu. async a await se používají pro asynchronní programování (Příprava snídaně).
return View(await _context.Dishes.ToListAsync());
return View(await dishes.ToListAsync());
}

public async Task<IActionResult> Details(int? id)
Expand Down
2 changes: 1 addition & 1 deletion FoodMenu/FoodMenu/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2025 - FoodMenu - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
&copy; 2025 - FoodMenu - <a asp-area="" asp-controller="Home" asp-action="Privacy">Priv acy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
Expand Down

0 comments on commit aaf19a9

Please sign in to comment.