Добавил поиск
This commit is contained in:
parent
2d31231c2e
commit
202ba42bb5
@ -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();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PaydayFrontend.Data;
|
||||
using PaydayFrontend.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@ -15,6 +16,12 @@ builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.Requ
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
builder.Services.AddHttpClient("backend", client =>
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
});
|
||||
builder.Services.AddTransient<IUniversityService, UniversityService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
31
PaydayFrontend/Services/IUniversityService.cs
Normal file
31
PaydayFrontend/Services/IUniversityService.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System.Text.Json;
|
||||
using PaydayFrontend.Models;
|
||||
|
||||
namespace PaydayFrontend.Services;
|
||||
|
||||
public interface IUniversityService
|
||||
{
|
||||
public Task<List<University>> GetAllUniversity();
|
||||
}
|
||||
|
||||
public class UniversityService : IUniversityService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public UniversityService(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_httpClient.BaseAddress = new Uri("https://payday.zetcraft.ru");
|
||||
}
|
||||
|
||||
public async Task<List<University>> GetAllUniversity()
|
||||
{
|
||||
var response = await _httpClient.GetAsync("v1/public/university");
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
var university = JsonSerializer.Deserialize<List<University>>(result, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
return university;
|
||||
}
|
||||
}
|
@ -7,9 +7,10 @@
|
||||
<section class="universe">
|
||||
<div class="container container_flex">
|
||||
<div class="row">
|
||||
<div class="universe_input_block col-md-12">
|
||||
<input type="text" class="universe_input" placeholder="Введите название вуза или суза..."><img src="/img/logo/search.svg" alt="search" class="universe_search">
|
||||
</div>
|
||||
<form class="universe_input_block col-md-12">
|
||||
<input type="text" class="universe_input" name="searchString" placeholder="Введите название вуза или суза...">
|
||||
<input type="image" src="/img/logo/search.svg" alt="search" class="universe_search">
|
||||
</form>
|
||||
@{
|
||||
foreach (var university in Model)
|
||||
{
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 30 KiB |
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
Loading…
x
Reference in New Issue
Block a user