исправлен котроллер, сделала вывод списка процедур

добавила файл логов, класс апиклиент, прописала зависимости
This commit is contained in:
Елена Бакальская 2024-05-26 13:45:07 +04:00
parent 9f44ad75be
commit a24099df3c
6 changed files with 127 additions and 31 deletions

View File

@ -0,0 +1,44 @@
using Newtonsoft.Json;
using PolyclinicContracts.ViewModels;
using System.Net.Http.Headers;
using System.Text;
namespace PolyclinicWebAppSuretor
{
public class APIClient
{
private static readonly HttpClient _client = new();
public static UserViewModel? User { get; set; } = null;
public static void Connect(IConfiguration configuration)
{
_client.BaseAddress = new Uri(configuration["IPAddress"]);
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public static T? GetRequest<T>(string requestUrl)
{
var response = _client.GetAsync(requestUrl);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<T>(result);
}
else
{
throw new Exception(result);
}
}
public static void PostRequest<T>(string requestUrl, T model)
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = _client.PostAsync(requestUrl, data);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (!response.Result.IsSuccessStatusCode)
{
throw new Exception(result);
}
}
}
}

View File

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.ViewModels;
using PolyclinicWebAppSuretor.Models;
using System.Diagnostics;
@ -7,10 +9,12 @@ namespace PolyclinicWebAppSuretor.Controllers
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IProcedureLogic _procedureLogic;
public HomeController(ILogger<HomeController> logger)
public HomeController(ILogger<HomeController> logger, IProcedureLogic procedureLogic)
{
_logger = logger;
_procedureLogic = procedureLogic;
}
public IActionResult Index()
@ -30,7 +34,12 @@ namespace PolyclinicWebAppSuretor.Controllers
public IActionResult Procedures()
{
return View();
List<ProcedureViewModel> procedure = _procedureLogic.ReadList(null);
if (procedure == null)
{
procedure = new();
}
return View(procedure);
}
public IActionResult Recipes()

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
@ -7,10 +7,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net.Extensions.AspNetCore" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
@ -20,4 +23,10 @@
<ProjectReference Include="..\PolyclinicDataModels\PolyclinicDataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Content Update="log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@ -1,7 +1,21 @@
using PolyclinicBusinessLogic.BusinessLogics;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.StoragesContracts;
using PolyclinicDatabaseImplement.Implements;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IProcedureLogic, ProcedureLogic>();
builder.Services.AddTransient<IMedicamentLogic, MedicamentLogic>();
builder.Services.AddTransient<IRecipeLogic, RecipeLogic>();
builder.Services.AddTransient<IProcedureStorage, ProcedureStorage>();
builder.Services.AddTransient<IMedicamentStorage, MedicamentStorage>();
builder.Services.AddTransient<IRecipeStorage, RecipeStorage>();
var app = builder.Build();

View File

@ -44,35 +44,39 @@
</tr>
</thead>
<tbody>
<td>
1
</td>
<td>
Массаж пяточек
</td>
<td>
12.04.2024
</td>
<td>
17.04.2024
</td>
<td>
ммммммм
</td>
<td>
<a asp-action="CreateProcedure">
<svg class="bi-edit-pen" viewBox="0 0 127 127" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M105.5 26L37 114.5C34.5 117 16.3 121.7 7.5 122.5C79.1 34.1 101 5.5 102 4C104.833 4.5 119.3 14.6 122.5 21C105 44 98.5 55 111.5 58.5" stroke="#008315" stroke-width="6" stroke-linecap="round" />
@foreach (var item in Model)
{
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateStartProcedure)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateStopProcedure)
</td>
<td>
@Html.DisplayFor(modelItem => item.Comment)
</td>
<td>
<a asp-action="CreateProcedure">
<svg class="bi-edit-pen" viewBox="0 0 127 127" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M105.5 26L37 114.5C34.5 117 16.3 121.7 7.5 122.5C79.1 34.1 101 5.5 102 4C104.833 4.5 119.3 14.6 122.5 21C105 44 98.5 55 111.5 58.5" stroke="#008315" stroke-width="6" stroke-linecap="round" />
</svg>
</a>
</td>
<td>
<svg class="bi-cart-delete" viewBox="0 0 154 164" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M44.5 123C4.99995 119.5 -11.8431 56.4293 24 19.5C40.5 2.50001 72.5 -5.5 101.5 27.5L115.5 14.5" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
<path d="M65.2123 159.963L56 60.0001C88.0236 76.3307 119.521 77.4194 149 60.0001C141.63 142.346 140.08 160.953 140.226 159.963H65.2123Z" stroke="#D10000" stroke-width="8" />
<path d="M121 36L101.582 55L75 31" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
</svg>
</a>
</td>
<td>
<svg class="bi-cart-delete" viewBox="0 0 154 164" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M44.5 123C4.99995 119.5 -11.8431 56.4293 24 19.5C40.5 2.50001 72.5 -5.5 101.5 27.5L115.5 14.5" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
<path d="M65.2123 159.963L56 60.0001C88.0236 76.3307 119.521 77.4194 149 60.0001C141.63 142.346 140.08 160.953 140.226 159.963H65.2123Z" stroke="#D10000" stroke-width="8" />
<path d="M121 36L101.582 55L75 31" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
</svg>
</td>
</td>
}
</tbody>
</table>
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="logs/polyclinicsuretorclient.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
</layout>
</appender>
<root>
<level value="TRACE" />
<appender-ref ref="RollingFile" />
</root>
</log4net>