big fixes with repository lab5

This commit is contained in:
10Г Егор Романов 2023-05-01 16:55:27 +04:00
parent bb722556eb
commit 78ddde117f
92 changed files with 309 additions and 51 deletions

View File

@ -21,14 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemDatabaseImple
{D12D1329-4362-472B-B6E6-D62B0FF00C63} = {D12D1329-4362-472B-B6E6-D62B0FF00C63} {D12D1329-4362-472B-B6E6-D62B0FF00C63} = {D12D1329-4362-472B-B6E6-D62B0FF00C63}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemClientApp", "..\..\PIbd-22_Kalyshev_Y_V_BlacksmithWorkshop_Base\BlacksmithWorkshop\BlacksmithWorkshopClientApp\SecuritySystemClientApp.csproj", "{8D616ABB-7ADE-47B8-9338-E7AAE084945B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemClientApp", "..\SecuritySystemClientApp\SecuritySystemClientApp.csproj", "{E2624D4E-771E-4F6D-A638-AD322C64C20B}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemRestApi", "..\..\PIbd-22_Kalyshev_Y_V_BlacksmithWorkshop_Base\BlacksmithWorkshop\BlacksmithWorkshopRestApi\SecuritySystemRestApi.csproj", "{2974E9EB-F123-4C5E-8D40-DC17692AC07B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemRestApi", "..\SecuritySystemRestApi\SecuritySystemRestApi.csproj", "{E8B437F4-DFC7-4875-AC0C-F458B85FB253}"
ProjectSection(ProjectDependencies) = postProject
{AB7134B4-1BEF-44FC-91DF-76D99BD7C065} = {AB7134B4-1BEF-44FC-91DF-76D99BD7C065}
{C1C491F5-4CB7-4B6B-92CE-41688769709A} = {C1C491F5-4CB7-4B6B-92CE-41688769709A}
{EF5F4167-954D-4414-8F76-372410029641} = {EF5F4167-954D-4414-8F76-372410029641}
EndProjectSection
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -64,14 +59,14 @@ Global
{AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Debug|Any CPU.Build.0 = Debug|Any CPU {AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Release|Any CPU.ActiveCfg = Release|Any CPU {AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Release|Any CPU.Build.0 = Release|Any CPU {AB7134B4-1BEF-44FC-91DF-76D99BD7C065}.Release|Any CPU.Build.0 = Release|Any CPU
{8D616ABB-7ADE-47B8-9338-E7AAE084945B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E2624D4E-771E-4F6D-A638-AD322C64C20B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D616ABB-7ADE-47B8-9338-E7AAE084945B}.Debug|Any CPU.Build.0 = Debug|Any CPU {E2624D4E-771E-4F6D-A638-AD322C64C20B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D616ABB-7ADE-47B8-9338-E7AAE084945B}.Release|Any CPU.ActiveCfg = Release|Any CPU {E2624D4E-771E-4F6D-A638-AD322C64C20B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D616ABB-7ADE-47B8-9338-E7AAE084945B}.Release|Any CPU.Build.0 = Release|Any CPU {E2624D4E-771E-4F6D-A638-AD322C64C20B}.Release|Any CPU.Build.0 = Release|Any CPU
{2974E9EB-F123-4C5E-8D40-DC17692AC07B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E8B437F4-DFC7-4875-AC0C-F458B85FB253}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2974E9EB-F123-4C5E-8D40-DC17692AC07B}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8B437F4-DFC7-4875-AC0C-F458B85FB253}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2974E9EB-F123-4C5E-8D40-DC17692AC07B}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8B437F4-DFC7-4875-AC0C-F458B85FB253}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2974E9EB-F123-4C5E-8D40-DC17692AC07B}.Release|Any CPU.Build.0 = Release|Any CPU {E8B437F4-DFC7-4875-AC0C-F458B85FB253}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,7 +1,7 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StorageContracts; using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models; using SecuritySystemDataModels.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -1,3 +0,0 @@
@using BlacksmithWorkshopClientApp
@using BlacksmithWorkshopClientApp.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -1,9 +1,9 @@
using BlacksmithWorkshopContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Text; using System.Text;
namespace BlacksmithWorkshopClientApp namespace SecuritySystemClientApp
{ {
public class APIClient public class APIClient
{ {

View File

@ -102,11 +102,11 @@ namespace SecuritySystemClientApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Create() public IActionResult Create()
{ {
ViewBag.Manufactures = APIClient.GetRequest<List<ManufactureViewModel>>("api/main/getmanufacturelist"); ViewBag.Secures = APIClient.GetRequest<List<SecureViewModel>>("api/main/getSecurelist");
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Create(int manufacture, int count) public void Create(int Secure, int count)
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
@ -119,17 +119,17 @@ namespace SecuritySystemClientApp.Controllers
APIClient.PostRequest("api/main/createorder", new OrderBindingModel APIClient.PostRequest("api/main/createorder", new OrderBindingModel
{ {
ClientId = APIClient.Client.Id, ClientId = APIClient.Client.Id,
ManufactureId = manufacture, SecureId = Secure,
Count = count, Count = count,
Sum = Calc(count, manufacture) Sum = Calc(count, Secure)
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpPost] [HttpPost]
public double Calc(int count, int manufacture) public double Calc(int count, int Secure)
{ {
var prod = APIClient.GetRequest<ManufactureViewModel>($"api/main/getmanufacture?manufactureId={manufacture}"); var prod = APIClient.GetRequest<SecureViewModel>($"api/main/getSecure?SecureId={Secure}");
return count * (prod?.Price ?? 1); return count * (prod?.Price ?? 1);
} }
} }

View File

@ -1,4 +1,4 @@
namespace BlacksmithWorkshopClientApp.Models namespace SecuritySystemClientApp.Models
{ {
public class ErrorViewModel public class ErrorViewModel
{ {

View File

@ -1,10 +1,12 @@
using SecuritySystemClientApp;
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();
var app = builder.Build(); var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
{ {

View File

@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:27418",
"sslPort": 44380
}
},
"profiles": {
"SecuritySystemClientApp": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7277;http://localhost:5118",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -8,15 +8,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" /> <ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\lib\" />
</ItemGroup>
</Project> </Project>

View File

@ -8,7 +8,7 @@
<div class="row"> <div class="row">
<div class="col-4">Изделие:</div> <div class="col-4">Изделие:</div>
<div class="col-8"> <div class="col-8">
<select id="manufacture" name="manufacture" class="form-control" asp-items="@(new SelectList(@ViewBag.Manufactures,"Id", "ManufactureName"))"></select> <select id="Secure" name="Secure" class="form-control" asp-items="@(new SelectList(@ViewBag.Secures,"Id", "SecureName"))"></select>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
@ -26,7 +26,7 @@
</form> </form>
<script> <script>
$('#manufacture').on('change', function () { $('#Secure').on('change', function () {
check(); check();
}); });
$('#count').on('change', function () { $('#count').on('change', function () {
@ -34,12 +34,12 @@
}); });
function check() { function check() {
var count = $('#count').val(); var count = $('#count').val();
var manufacture = $('#manufacture').val(); var Secure = $('#Secure').val();
if (count && manufacture) { if (count && Secure) {
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: "/Home/Calc", url: "/Home/Calc",
data: { count: count, manufacture: manufacture }, data: { count: count, Secure: Secure },
success: function (result) { success: function (result) {
$("#sum").val(result); $("#sum").val(result);
} }

View File

@ -1,4 +1,4 @@
@using BlacksmithWorkshopContracts.ViewModels @using SecuritySystemContracts.ViewModels
@model List<OrderViewModel> @model List<OrderViewModel>
@{ @{
ViewData["Title"] = "Home Page"; ViewData["Title"] = "Home Page";
@ -48,7 +48,7 @@
@Html.DisplayFor(modelItem => item.Id) @Html.DisplayFor(modelItem => item.Id)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.ManufactureName) @Html.DisplayFor(modelItem => item.SecureName)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.DateCreate) @Html.DisplayFor(modelItem => item.DateCreate)

View File

@ -3,16 +3,16 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - BlacksmithWorkshopClientApp</title> <title>@ViewData["Title"] - SecuritySystemClientApp</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" /> <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/BlacksmithWorkshopClientApp.styles.css" asp-append-version="true" /> <link rel="stylesheet" href="~/SecuritySystemClientApp.styles.css" asp-append-version="true" />
</head> </head>
<body> <body>
<header> <header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Кузнечная мастерская</a> <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Система охраны</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent" <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation"> aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
@ -44,7 +44,7 @@
<footer class="border-top footer text-muted"> <footer class="border-top footer text-muted">
<div class="container"> <div class="container">
&copy; 2023 - BlacksmithWorkshopClientApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a> &copy; 2023 - SecuritySystemClientApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div> </div>
</footer> </footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script> <script src="~/lib/jquery/dist/jquery.min.js"></script>

View File

@ -0,0 +1,3 @@
@using SecuritySystemClientApp
@using SecuritySystemClientApp.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -0,0 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"IPAddress": "https://localhost:7116/"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -9,7 +9,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SecuritySystemContracts.StorageContracts namespace SecuritySystemContracts.StoragesContracts
{ {
public interface IClientStorage public interface IClientStorage
{ {

View File

@ -1,6 +1,6 @@
using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StorageContracts; using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels; using SecuritySystemContracts.ViewModels;
using SecuritySystemDatabaseImplement.Models; using SecuritySystemDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

View File

@ -0,0 +1,64 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace SecuritySystemRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public ClientViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new ClientSearchModel
{
Email = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(ClientBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void UpdateData(ClientBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
}
}

View File

@ -0,0 +1,75 @@
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace SecuritySystemRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MainController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
private readonly ISecureLogic _Secure;
public MainController(ILogger<MainController> logger, IOrderLogic order, ISecureLogic Secure)
{
_logger = logger;
_order = order;
_Secure = Secure;
}
[HttpGet]
public List<SecureViewModel>? GetSecureList()
{
try
{
return _Secure.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка продуктов");
throw;
}
}
[HttpGet]
public SecureViewModel? GetSecure(int SecureId)
{
try
{
return _Secure.ReadElement(new SecureSearchModel { Id = SecureId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения продукта по id={Id}", SecureId);
throw;
}
}
[HttpGet]
public List<OrderViewModel>? GetOrders(int clientId)
{
try
{
return _order.ReadList(new OrderSearchModel { ClientId = clientId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", clientId);
throw;
}
}
[HttpPost]
public void CreateOrder(OrderBindingModel model)
{
try
{
_order.CreateOrder(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
}
}

View File

@ -0,0 +1,44 @@
using SecuritySystemBusinessLogic.BusinessLogics;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemDatabaseImplement.Implements;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
// Add services to the container.
builder.Services.AddTransient<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
builder.Services.AddTransient<ISecureStorage, SecureStorage>();
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<ISecureLogic, SecureLogic>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "SecuritySystemRestApi", Version = "v1" });
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AbstractShopRestApi v1"));
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -4,17 +4,17 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:14404", "applicationUrl": "http://localhost:57787",
"sslPort": 44320 "sslPort": 44379
} }
}, },
"profiles": { "profiles": {
"SecuritySystemClientAPI": { "SecuritySystemRestApi": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "swagger", "launchUrl": "swagger",
"applicationUrl": "https://localhost:7062;http://localhost:5062", "applicationUrl": "https://localhost:7116;http://localhost:5263",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj" />
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
<ProjectReference Include="..\SecuritySystemDatabaseImplement\SecuritySystemDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="c:/temp/AbstractShopRestApi.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>