Добавил поиск
This commit is contained in:
@ -1,33 +1,34 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using PaydayFrontend.Models;
|
||||
using PaydayFrontend.Services;
|
||||
|
||||
namespace PaydayFrontend.Controllers;
|
||||
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly IUniversityService _universityService;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
public HomeController(ILogger<HomeController> logger, IUniversityService universityService)
|
||||
{
|
||||
_logger = logger;
|
||||
_universityService = universityService;
|
||||
}
|
||||
|
||||
|
||||
public async Task<IActionResult> Index()
|
||||
|
||||
public async Task<IActionResult> Index(string searchString)
|
||||
{
|
||||
using HttpClient client = new();
|
||||
IEnumerable<University> universities = await _universityService.GetAllUniversity();
|
||||
|
||||
string json = await client.GetStringAsync(
|
||||
"https://payday.zetcraft.ru/v1/public/university");
|
||||
if (!String.IsNullOrEmpty(searchString))
|
||||
{
|
||||
universities = universities.Where(s => s.Name!.ToLower().Contains(searchString.ToLower()));
|
||||
}
|
||||
|
||||
List<University> universities = JsonConvert.DeserializeObject<List<University>>(json);
|
||||
|
||||
return View(universities);
|
||||
return View(universities.ToList());
|
||||
}
|
||||
|
||||
public IActionResult SecondPage()
|
||||
public IActionResult SecondPage([FromQuery] long universityId)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
Reference in New Issue
Block a user