/
IamDeveloper
/
IAmConditer
Обзор
Документация
Войти
/
IamDeveloper
/
IAmConditer
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Controllers/HomeController.cs
69 строк
2 KB
Dmitriy Urazlin
добавил игрединеты
23 май 2026, 21:41
23 май 2026, 21:41
d05bb2e
Код
Авторство
О чём код?
using iAmConditer.Models; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System.Diagnostics; using System.Net.Http.Formatting; using System.Net.Http.Headers; using System.Security.Principal; namespace iAmConditer.Controllers { public class Recipe { public int id { get; set; } public string? name { get; set; } public int product_type { get; set; } public string? pname{ get; set; } public int measure { get; set; } public string? mname { get; set; } public int count { get; set; } } public class ProductType { public int id { get; set; } public string? name { get; set; } public int measure { get; set; } } public class HomeController : Controller { public IActionResult Index() { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:8080/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync("/api/recipe").GetAwaiter().GetResult(); string answer = response.Content.ReadAsStringAsync().GetAwaiter().GetResult().Trim('"'); answer = answer.Replace("\\\"", "\""); var recipeList = JsonConvert.DeserializeObject<IEnumerable<Recipe>>(answer); ViewBag.Recipes = recipeList; response = client.GetAsync("/api/ref?mode=product_types").GetAwaiter().GetResult(); answer = response.Content.ReadAsStringAsync().GetAwaiter().GetResult().Trim('"'); answer = answer.Replace("\\\"", "\""); var typeList = JsonConvert.DeserializeObject<IEnumerable<ProductType>>(answer); ViewBag.Types = typeList; return View(); } public IActionResult Ingredients() { return View(); } public IActionResult Privacy() { return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } }