Download Controllers/HomeController.cs from automindy/Toolhub: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/spaces/automindy/Toolhub/resolve/main/Controllers/HomeController.cs
- Command line
-
hf download hf://spaces/automindy/Toolhub/Controllers/HomeController.cs
-
curl -L -o HomeController.cs https://huggingface.co/spaces/automindy/Toolhub/resolve/main/Controllers/HomeController.cs
2.19 kB
| using System.Diagnostics; | |
| using Microsoft.AspNetCore.Mvc; | |
| using ToolHub.Models; | |
| using ToolHub.Services; | |
| namespace ToolHub.Controllers | |
| { | |
| public class HomeController : Controller | |
| { | |
| private readonly ILogger<HomeController> _logger; | |
| private readonly IToolService _toolService; | |
| public HomeController(ILogger<HomeController> logger, IToolService toolService) | |
| { | |
| _logger = logger; | |
| _toolService = toolService; | |
| } | |
| public async Task<IActionResult> Index() | |
| { | |
| ViewBag.Categories = await _toolService.GetCategoriesAsync(); | |
| ViewBag.HotTools = await _toolService.GetHotToolsAsync(); | |
| ViewBag.NewTools = await _toolService.GetNewToolsAsync(); | |
| return View(); | |
| } | |
| public async Task<IActionResult> Tools(int categoryId = 0, int page = 1, string? search = null) | |
| { | |
| ViewBag.Categories = await _toolService.GetCategoriesAsync(); | |
| ViewBag.CurrentCategory = categoryId; | |
| ViewBag.Search = search; | |
| List<Tool> tools; | |
| if (!string.IsNullOrEmpty(search)) | |
| { | |
| tools = await _toolService.SearchToolsAsync(search, page); | |
| } | |
| else | |
| { | |
| tools = await _toolService.GetToolsByCategoryAsync(categoryId, page); | |
| } | |
| return View(tools); | |
| } | |
| public async Task<IActionResult> Tool(int id) | |
| { | |
| var tool = await _toolService.GetToolByIdAsync(id); | |
| if (tool == null) | |
| { | |
| return NotFound(); | |
| } | |
| // 增加浏览次数 | |
| await _toolService.IncrementViewCountAsync(id); | |
| return View(tool); | |
| } | |
| public IActionResult Privacy() | |
| { | |
| return View(); | |
| } | |
| [] | |
| public IActionResult Error() | |
| { | |
| return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | |
| } | |
| } | |
| } | |