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

добавила файл логов, класс апиклиент, прописала зависимости
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 Microsoft.AspNetCore.Mvc;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.ViewModels;
using PolyclinicWebAppSuretor.Models; using PolyclinicWebAppSuretor.Models;
using System.Diagnostics; using System.Diagnostics;
@ -7,10 +9,12 @@ namespace PolyclinicWebAppSuretor.Controllers
public class HomeController : Controller public class HomeController : Controller
{ {
private readonly ILogger<HomeController> _logger; private readonly ILogger<HomeController> _logger;
private readonly IProcedureLogic _procedureLogic;
public HomeController(ILogger<HomeController> logger) public HomeController(ILogger<HomeController> logger, IProcedureLogic procedureLogic)
{ {
_logger = logger; _logger = logger;
_procedureLogic = procedureLogic;
} }
public IActionResult Index() public IActionResult Index()
@ -30,7 +34,12 @@ namespace PolyclinicWebAppSuretor.Controllers
public IActionResult Procedures() public IActionResult Procedures()
{ {
return View(); List<ProcedureViewModel> procedure = _procedureLogic.ReadList(null);
if (procedure == null)
{
procedure = new();
}
return View(procedure);
} }
public IActionResult Recipes() public IActionResult Recipes()

View File

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

View File

@ -1,7 +1,21 @@
using PolyclinicBusinessLogic.BusinessLogics;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.StoragesContracts;
using PolyclinicDatabaseImplement.Implements;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddControllersWithViews(); 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(); var app = builder.Build();

View File

@ -44,20 +44,23 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var item in Model)
{
<td> <td>
1 @Html.DisplayFor(modelItem => item.Id)
</td> </td>
<td> <td>
Массаж пяточек @Html.DisplayFor(modelItem => item.Name)
</td> </td>
<td> <td>
12.04.2024 @Html.DisplayFor(modelItem => item.DateStartProcedure)
</td> </td>
<td> <td>
17.04.2024 @Html.DisplayFor(modelItem => item.DateStopProcedure)
</td> </td>
<td> <td>
ммммммм @Html.DisplayFor(modelItem => item.Comment)
</td> </td>
<td> <td>
<a asp-action="CreateProcedure"> <a asp-action="CreateProcedure">
@ -73,6 +76,7 @@
<path d="M121 36L101.582 55L75 31" stroke="#D10000" stroke-width="8" stroke-linecap="round" /> <path d="M121 36L101.582 55L75 31" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
</svg> </svg>
</td> </td>
}
</tbody> </tbody>
</table> </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>