Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b6349efae | |||
| 2900dc81a9 | |||
| 178ea8736e | |||
| 037f9db304 | |||
| 3caad41432 | |||
| fb558a7ff2 | |||
| ad36b8034a | |||
| 1dab9faa62 | |||
| 3dd0029329 | |||
| 1a09e4f8ee | |||
| fb842980e3 | |||
| 789e0f79c1 | |||
| 126ace800a | |||
| ae68aacce0 | |||
| c4c81ca954 | |||
| 81b9544baf | |||
| fffe836607 | |||
| dd52116f62 | |||
| f38d94afa8 | |||
| aba6593945 | |||
| 35856195e8 | |||
| 47eb037c61 | |||
| 9c846fdaed |
@@ -11,7 +11,9 @@ namespace SoftwareInstallationClientApp
|
||||
|
||||
public static ClientViewModel? Client { get; set; } = null;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
public static int CurrentPage { get; set; } = 0;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
@@ -28,9 +30,9 @@ namespace SoftwareInstallationClientApp
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
@@ -4,6 +4,9 @@ using SoftwareInstallationContracts.BindingModels;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using SoftwareInstallationContracts.SearchModels;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
|
||||
namespace SoftwareInstallationClientApp.Controllers
|
||||
@@ -145,15 +148,55 @@ namespace SoftwareInstallationClientApp.Controllers
|
||||
var prod = APIClient.GetRequest<PackageViewModel>($"api/main/getpackage?packageId={package}");
|
||||
return count * (prod?.Price ?? 1);
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Mails()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Mails()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Switches the page.
|
||||
/// </summary>
|
||||
/// <returns>Возвращает кортеж с таблицой в html, текущей страницей писем, выключать ли кнопку пред. страницы, выключать ли кнопку след. страницы</returns>
|
||||
[HttpGet]
|
||||
public Tuple<string?, string?, bool, bool>? SwitchPage(bool isNext)
|
||||
{
|
||||
if (isNext)
|
||||
{
|
||||
APIClient.CurrentPage++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (APIClient.CurrentPage == 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
APIClient.CurrentPage--;
|
||||
}
|
||||
|
||||
var res = APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client!.Id}&page={APIClient.CurrentPage}");
|
||||
if (isNext && (res == null || res.Count == 0))
|
||||
{
|
||||
APIClient.CurrentPage--;
|
||||
return Tuple.Create<string?, string?, bool, bool>(null, null, APIClient.CurrentPage != 1, false);
|
||||
}
|
||||
|
||||
StringBuilder htmlTable = new();
|
||||
foreach (var mail in res)
|
||||
{
|
||||
htmlTable.Append("<tr>" +
|
||||
$"<td>{mail.DateDelivery}</td>" +
|
||||
$"<td>{mail.Subject}</td>" +
|
||||
$"<td>{mail.Body}</td>" +
|
||||
"<td>" + (mail.HasRead ? "Прочитано" : "Непрочитано") + "</td>" +
|
||||
$"<td>{mail.Reply}</td>" +
|
||||
"</tr>");
|
||||
}
|
||||
return Tuple.Create<string?, string?, bool, bool>(htmlTable.ToString(), APIClient.CurrentPage.ToString(), APIClient.CurrentPage != 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:20662",
|
||||
"sslPort": 44346
|
||||
"applicationUrl": "http://localhost:37980",
|
||||
"sslPort": 44326
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
@@ -12,7 +12,7 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7085;http://localhost:5011",
|
||||
"applicationUrl": "https://localhost:7000;http://localhost:5137",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -0,0 +1,80 @@
|
||||
@{
|
||||
ViewData["Title"] = "Mails";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Письма</h1>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Дата письма
|
||||
</th>
|
||||
<th>
|
||||
Заголовок
|
||||
</th>
|
||||
<th>
|
||||
Текст
|
||||
</th>
|
||||
<th>
|
||||
Статус
|
||||
</th>
|
||||
<th>
|
||||
Ответ
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="mails-table-body">
|
||||
</tbody>
|
||||
</table>
|
||||
<ul class="pagination justify-content-center">
|
||||
<li id="prev-page" class="page-item">
|
||||
<a class="page-link" href="#" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
<span class="sr-only">Предыдущее</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a id="current-page" class="page-link"></a>
|
||||
</li>
|
||||
<li id="next-page" class="page-item">
|
||||
<a class="page-link" href="#" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
<span class="sr-only">Следующее</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function onClicked(isNext) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/SwitchPage",
|
||||
data: { isNext: isNext },
|
||||
success: function (result) {
|
||||
if (result != null) {
|
||||
if (result.item1 != null && result.item2 != null) {
|
||||
$("#mails-table-body").html(result.item1);
|
||||
$("#current-page").text(result.item2);
|
||||
}
|
||||
if (result.item3)
|
||||
$("#prev-page").removeClass("page-item disabled");
|
||||
else
|
||||
$("#prev-page").addClass("page-item disabled");
|
||||
if (result.item4)
|
||||
$("#next-page").removeClass("page-item disabled");
|
||||
else
|
||||
$("#next-page").addClass("page-item disabled");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Чтобы в первый раз загрузить данные и попасть на первую страницу
|
||||
onClicked(true);
|
||||
$("#prev-page").on('click', () => onClicked(false));
|
||||
$("#next-page").on('click', () => onClicked(true));
|
||||
|
||||
</script>
|
||||
@@ -15,7 +15,7 @@
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<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"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
@@ -6,5 +6,5 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"IPAddress": "http://localhost:5044"
|
||||
"IPAddress": "http://localhost:5010/"
|
||||
}
|
||||
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
@@ -4,7 +4,6 @@ using SoftwareInstallationContracts.SearchModels;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SoftwareInstallationContracts.BusinessLogicsContracts;
|
||||
using SoftwareInstallationContracts.SearchModels;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
|
||||
namespace SoftwareInstallationRestApi.Controllers
|
||||
@@ -17,16 +16,17 @@ namespace SoftwareInstallationRestApi.Controllers
|
||||
|
||||
private readonly IClientLogic _logic;
|
||||
|
||||
private readonly IMessageInfoLogic _mailLogic;
|
||||
private readonly IMessageInfoLogic _mailLogic;
|
||||
public int pageSize = 3;
|
||||
|
||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
|
||||
{
|
||||
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_mailLogic = mailLogic;
|
||||
}
|
||||
_mailLogic = mailLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet]
|
||||
public ClientViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
@@ -72,21 +72,23 @@ namespace SoftwareInstallationRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId, int page)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mailLogic.ReadList(new()
|
||||
{
|
||||
ClientId = clientId,
|
||||
Page = page,
|
||||
PageSize = pageSize
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,11 @@ namespace SoftwareInstallationRestApi.Controllers
|
||||
|
||||
private readonly IPackageLogic _Package;
|
||||
|
||||
public MainController(ILogger<MainController> logger, IOrderLogic order, IPackageLogic package)
|
||||
public MainController(ILogger<MainController> logger, IOrderLogic order, IPackageLogic Package)
|
||||
{
|
||||
_logger = logger;
|
||||
_order = order;
|
||||
_Package = package;
|
||||
_Package = Package;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -0,0 +1,112 @@
|
||||
using SoftwareInstallationContracts.BindingModels;
|
||||
using SoftwareInstallationContracts.BusinessLogicsContracts;
|
||||
using SoftwareInstallationContracts.SearchModels;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
using SoftwareInstallationDatabaseImplement.Models;
|
||||
using SoftwareInstallationDataModels.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Text.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace SoftwareInstallationRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ShopController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IShopLogic _logic;
|
||||
|
||||
public ShopController(IShopLogic logic, ILogger<ShopController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ShopViewModel>? GetShops()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получает на вход айди магазина и по нему возвращает магазин
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier.</param>
|
||||
/// <returns>
|
||||
/// Кортеж из магазина, итератора с изделиями которые находятся в магазине и итератора с количеством этих изделий.
|
||||
/// </returns>
|
||||
/// Почему изделия и их количество не находятся в одном кортеже? потому что тогда он их не сериализует
|
||||
/// и я не знаю почему.
|
||||
/// Также, к сожалению, приходится явно присваивать каждое поле из IPastyModel в PastyViewModel, поскольку
|
||||
/// нельзя сериализовать интерфейс, и при это нельзя его неявно кастануть к PackageViewModel, даже если в
|
||||
/// истинном типе SoftwareInstallationDatabaseImplement.Package такой каст есть.
|
||||
/// Сделать же каст в PackageViewModel из IPackageModel нельзя, потому что запрещен каст с интерфейсами.
|
||||
/// Единственный нормальный вариант создать отдельную сущность, где объединить изделия и их количество,
|
||||
/// и уже ее хранить в магазине и соответственно ее передавать. Но поскольку для этого нужно перелопатить пол-проекта
|
||||
/// и получить минус баллы на pr я откажусь от подобной идеи.
|
||||
[HttpGet]
|
||||
public Tuple<ShopViewModel, IEnumerable<PackageViewModel>, IEnumerable<int>>? GetShopWithPackages(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var shop = _logic.ReadElement(new() { Id = id });
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Tuple.Create(shop,
|
||||
shop.Packages.Select(x => new PackageViewModel ()
|
||||
{
|
||||
Id = x.Value.Item1.Id,
|
||||
Price = x.Value.Item1.Price,
|
||||
PackageName = x.Value.Item1.PackageName,
|
||||
}),
|
||||
shop.Packages.Select(x => x.Value.Item2));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CRUDShop(Action action)
|
||||
{
|
||||
try
|
||||
{
|
||||
action.Invoke();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка операции CRUD - {operation} с магазином", action.Method.Name);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateShop(ShopBindingModel model) => CRUDShop(() => _logic.Update(model));
|
||||
[HttpPost]
|
||||
public void CreateShop(ShopBindingModel model) => CRUDShop(() => _logic.Create(model));
|
||||
[HttpPost]
|
||||
public void DeleteShop(ShopBindingModel model) => CRUDShop(() => _logic.Delete(model));
|
||||
|
||||
[HttpPost]
|
||||
public void AddPackageInShop(Tuple<ShopSearchModel, PackageViewModel, int> countPackageForShop)
|
||||
{
|
||||
CRUDShop(() => _logic.AddPackage(countPackageForShop.Item1, countPackageForShop.Item2, countPackageForShop.Item3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
using SoftwareInstallationBusinessLogic;
|
||||
using SoftwareInstallationBusinessLogic.BusinessLogics;
|
||||
using SoftwareInstallationContracts.BusinessLogicsContracts;
|
||||
using SoftwareInstallationContracts.StoragesContracts;
|
||||
using SoftwareInstallationDatabaseImplement;
|
||||
using SoftwareInstallationDatabaseImplement.Implements;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using SoftwareInstallationContracts.StoragesContracts;
|
||||
using SoftwareInstallationBusinessLogic.MailWorker;
|
||||
using SoftwareInstallationContracts.BindingModels;
|
||||
using SoftwareInstallationDatabaseImplement;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using SoftwareInstallationBusinessLogic.MailWorker;
|
||||
using SoftwareInstallationBusinessLogic;
|
||||
using SoftwareInstallationContracts.BusinessLogicsContracts;
|
||||
using SoftwareInstallationContracts.StoragesContract;
|
||||
using SoftwareInstallationContracts.BindingModels;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -16,16 +21,16 @@ builder.Logging.AddLog4Net("log4net.config");
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IPackageStorage, PackageStorage>();
|
||||
|
||||
builder.Services.AddTransient<IShopStorage, ShopStorage>();
|
||||
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IPackageLogic, PackageLogic>();
|
||||
|
||||
builder.Services.AddTransient<IShopLogic, ShopLogic>();
|
||||
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
builder.Services.AddControllers();
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at
|
||||
https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
@@ -33,9 +38,8 @@ builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Title = "SoftwareInstallationRestApi",
|
||||
Version
|
||||
= "v1"
|
||||
Title = "ConfectoneryRestApi",
|
||||
Version = "v1"
|
||||
});
|
||||
});
|
||||
var app = builder.Build();
|
||||
@@ -44,19 +48,19 @@ var mailSender = app.Services.GetService<AbstractMailWorker>();
|
||||
|
||||
mailSender?.MailConfig(new MailConfigBindingModel
|
||||
{
|
||||
MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
|
||||
MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
|
||||
PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
|
||||
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
|
||||
MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
|
||||
MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
|
||||
PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
|
||||
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
|
||||
});
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json",
|
||||
"SoftwareInstallationRestApi v1"));
|
||||
"ConfectoneryRestApi v1"));
|
||||
}
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
@@ -4,8 +4,8 @@
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:7121",
|
||||
"sslPort": 44331
|
||||
"applicationUrl": "http://localhost:29422",
|
||||
"sslPort": 44350
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
@@ -14,7 +14,7 @@
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7123;http://localhost:5044",
|
||||
"applicationUrl": "https://localhost:7146;http://localhost:5010",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
@@ -17,4 +17,10 @@
|
||||
<ProjectReference Include="..\SoftwareInstallationDatabaseImplement\SoftwareInstallationDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="log4net.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -6,7 +6,7 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"PasswordToAccessShop": "12345",
|
||||
"SmtpClientHost": "smtp.mail.ru",
|
||||
"SmtpClientPort": "587",
|
||||
"PopHost": "pop.mail.ru",
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<log4net>
|
||||
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||
<file value="c:/temp/SoftwareInstallationRestApi.log" />
|
||||
<file value="c:/temp/AbstractShopRestApi.log" />
|
||||
<appendToFile value="true" />
|
||||
<maximumFileSize value="100KB" />
|
||||
<maxSizeRollBackups value="2" />
|
||||
55
SoftwareInstallation/ConfectioneryShopApp/APIClient.cs
Normal file
55
SoftwareInstallation/ConfectioneryShopApp/APIClient.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace SoftwareInstallationShopApp
|
||||
{
|
||||
public class APIClient
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
|
||||
public static bool IsAccessAllowed { get; private set; } = false;
|
||||
|
||||
public static string AccessPassword { get; private set; } = string.Empty;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
AccessPassword = configuration["PasswordToAccessShop"];
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static void Login(string password)
|
||||
{
|
||||
IsAccessAllowed = password == AccessPassword;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
using SoftwareInstallationShopApp;
|
||||
using SoftwareInstallationContracts.BindingModels;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
using SoftwareInstallationShopApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using SoftwareInstallationContracts.SearchModels;
|
||||
|
||||
namespace SoftwareInstallationShopApp.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<ShopViewModel>>($"api/shop/getshops"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Enter(string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("введите пароль");
|
||||
}
|
||||
APIClient.Login(password);
|
||||
if (!APIClient.IsAccessAllowed)
|
||||
{
|
||||
throw new Exception("Неверный пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Create()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(string name, string address, int maxCount)
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (maxCount <= 0)
|
||||
{
|
||||
throw new Exception("Количество и сумма должны быть больше 0");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception($"Имя магазина не должно быть пустым");
|
||||
}
|
||||
if (string.IsNullOrEmpty(address))
|
||||
{
|
||||
throw new Exception($"Адрес магазина не должен быть пустым");
|
||||
}
|
||||
APIClient.PostRequest("api/shop/createshop", new ShopBindingModel
|
||||
{
|
||||
Name = name,
|
||||
Address = address,
|
||||
MaxCountPackages = maxCount,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<string, ShopViewModel>? GetTablePackagesFromShop(int shop)
|
||||
{
|
||||
var result = APIClient.GetRequest<Tuple<ShopViewModel, IEnumerable<PackageViewModel>, IEnumerable<int>>?>($"api/shop/getshopwithpackages?id={shop}");
|
||||
if (result == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var shopModel = result.Item1;
|
||||
var resultHtml = "";
|
||||
foreach (var (item, count) in result.Item2.Zip(result.Item3))
|
||||
{
|
||||
resultHtml += "<tr>";
|
||||
resultHtml += $"<td>{item?.PackageName ?? string.Empty}</td>";
|
||||
resultHtml += $"<td>{item?.Price ?? 0}</td>";
|
||||
resultHtml += $"<td>{count}</td>";
|
||||
resultHtml += "</tr>";
|
||||
}
|
||||
return Tuple.Create(resultHtml, shopModel);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Update()
|
||||
{
|
||||
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>("api/shop/getshops");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update(int shop, string name, string address)
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception($"Имя магазина не должно быть пустым");
|
||||
}
|
||||
if (string.IsNullOrEmpty(address))
|
||||
{
|
||||
throw new Exception($"Адрес магазина не должен быть пустым");
|
||||
}
|
||||
APIClient.PostRequest("api/shop/updateshop", new ShopBindingModel
|
||||
{
|
||||
Id = shop,
|
||||
Name = name,
|
||||
Address = address,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Delete()
|
||||
{
|
||||
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>("api/shop/getshops");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int shop)
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/shop/deleteshop", new ShopBindingModel
|
||||
{
|
||||
Id = shop,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AddPackage()
|
||||
{
|
||||
ViewBag.Shops = APIClient.GetRequest<List<ShopViewModel>>("api/shop/getshops");
|
||||
ViewBag.Packages = APIClient.GetRequest<List<PackageViewModel>>("api/main/getpackagelist");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddPackage(int shop, int package, int count)
|
||||
{
|
||||
if (APIClient.IsAccessAllowed is false)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new Exception("Количество должно быть больше 0");
|
||||
}
|
||||
APIClient.PostRequest("api/shop/addpackageinshop", Tuple.Create(
|
||||
new ShopSearchModel() { Id = shop },
|
||||
new PackageViewModel() { Id = package },
|
||||
count
|
||||
));
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SoftwareInstallationShopApp.Models
|
||||
{
|
||||
public class ErrorViewModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
}
|
||||
}
|
||||
31
SoftwareInstallation/ConfectioneryShopApp/Program.cs
Normal file
31
SoftwareInstallation/ConfectioneryShopApp/Program.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using SoftwareInstallationShopApp;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
APIClient.Connect(builder.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:40086",
|
||||
"sslPort": 44313
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"SoftwareInstallationShopApp": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7114;http://localhost:5129",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SoftwareInstallationContracts\SoftwareInstallationContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="Views\Shared\_Layout.cshtml">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,33 @@
|
||||
@using SoftwareInstallationContracts.ViewModels;
|
||||
@using SoftwareInstallationDataModels.Models;
|
||||
|
||||
@model Dictionary<int, (IPackageModel, int)>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "AddPackage";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Пополнения магазина изделием</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Выбранный магазин:</div>
|
||||
<div class="col-8">
|
||||
<select id="shop" name="shop" class="form-control" asp-items="@(new SelectList(@ViewBag.Shops, "Id", "Name"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Выбранное изделие:</div>
|
||||
<div class="col-8">
|
||||
<select id="package" name="package" class="form-control" asp-items="@(new SelectList(@ViewBag.Packages, "Id", "PackageName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<div class="col-8"><input type="text" id="count" name="count"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Добавить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,33 @@
|
||||
@using SoftwareInstallationContracts.ViewModels;
|
||||
@using SoftwareInstallationDataModels.Models;
|
||||
|
||||
@model Dictionary<int, (IPackageModel, int)>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "AddPackage";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Пополнения магазина изделием</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Выбранный магазин:</div>
|
||||
<div class="col-8">
|
||||
<select id="shop" name="shop" class="form-control" asp-items="@(new SelectList(@ViewBag.Shops, "Id", "Name"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Выбранное изделие:</div>
|
||||
<div class="col-8">
|
||||
<select id="package" name="package" class="form-control" asp-items="@(new SelectList(@ViewBag.Packages, "Id", "PackageName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<div class="col-8"><input type="text" id="count" name="count"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Добавить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,24 @@
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание магазина</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Название магазина:</div>
|
||||
<div class="col-8"><input type="text" name="name" id="name" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Адрес магазина:</div>
|
||||
<div class="col-8"><input type="text" id="address" name="address"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Максимальное кол-во изделий:</div>
|
||||
<div class="col-8"><input type="text" id="maxCount" name="maxCount"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,18 @@
|
||||
@{
|
||||
ViewData["Title"] = "Update";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Редактирование магазина</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Выбранный магазин:</div>
|
||||
<div class="col-8">
|
||||
<select id="shop" name="shop" class="form-control" asp-items="@(new SelectList(@ViewBag.Shops, "Id", "Name"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Удалить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user