Compare commits
96 Commits
main
...
Coursework
Author | SHA1 | Date | |
---|---|---|---|
d705e02dc2 | |||
2d238b59ea | |||
cca786bc4b | |||
2e8bdedb3c | |||
00a90506c8 | |||
e36877d0db | |||
f82fc6157c | |||
474eaefff6 | |||
50e7193a47 | |||
3a2a5683f3 | |||
2cc83f06cb | |||
8ef56e41f0 | |||
6a587d523c | |||
e32bdbf76a | |||
5bfcab5958 | |||
474e15675b | |||
2ebbe9789f | |||
5802a5a4dd | |||
54dadbeb7e | |||
5f7994beaa | |||
30663c7429 | |||
884a3692c9 | |||
a05aede159 | |||
1a10fbed1d | |||
3131e7626c | |||
2a1d3bb6fa | |||
92a8fefd66 | |||
55ce9512ea | |||
ab9da1c1de | |||
df16e3dba4 | |||
f777a0ee3c | |||
6e2912f1c4 | |||
ad23e94dea | |||
9bd7b98042 | |||
96e135f0a1 | |||
2070a1597b | |||
28c48c45c5 | |||
93680fa335 | |||
391a54d200 | |||
8682259cfb | |||
bd52da4a56 | |||
d87953dab8 | |||
5d42a15fef | |||
b4b10c4eb6 | |||
156f8dc820 | |||
89eaf4c5b4 | |||
4b5f3b7b66 | |||
f7c05cc17d | |||
f64c7b284c | |||
8a4b8a5f79 | |||
23449b08ce | |||
27fc34b712 | |||
82be9eab7d | |||
eeda90cb78 | |||
3385f124d0 | |||
2fec7dfdf0 | |||
c5603b1ceb | |||
247ffd3b74 | |||
a2d01ef8de | |||
1ce0d8db0b | |||
d3babc62ff | |||
c9e44e977b | |||
aee700f1fb | |||
e5eec7f4ca | |||
a55b6c91ea | |||
b37e13575b | |||
2f7dac91e4 | |||
7bc1dc6adf | |||
c9c4bd00aa | |||
769979a406 | |||
7cbd0a5e50 | |||
262e730c94 | |||
fbf7292ee2 | |||
c2baea1737 | |||
9347ef10b4 | |||
d878842ac1 | |||
81454cabe4 | |||
ee3f2ff447 | |||
74de95f90b | |||
ff3957a457 | |||
a31e821be3 | |||
81673b0767 | |||
e65286870e | |||
377a803ac1 | |||
ef018c1331 | |||
42790d8e3b | |||
e0a3c1e1fd | |||
7d2196d4e8 | |||
e7ec00c14e | |||
67e03f94a1 | |||
bc4efdc01a | |||
81eba38ae9 | |||
c3f77f6bad | |||
9b8c383e22 | |||
7cff6fd966 | |||
5e275843c9 |
@ -3,7 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.33516.290
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerStore", "ComputerStore.csproj", "{695B79EB-71FD-456D-BFEA-634500FF2ECB}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerStoreBusinessLogic", "..\ComputerStoreBusinessLogic\ComputerStoreBusinessLogic.csproj", "{17F8960F-03CB-49D7-B335-931E6BE5F9FF}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerStoreContracts", "..\ComputerStoreContracts\ComputerStoreContracts.csproj", "{1C8DB816-F530-4CC3-9F36-F6191FE49C10}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerStoreDataModels", "..\ComputerStoreDataModels\ComputerStoreDataModels.csproj", "{93679794-7F9A-43C4-A7C3-A1AE77FAB964}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerStoreDatabaseImplement", "..\ComputerStoreDatabaseImplement\ComputerStoreDatabaseImplement.csproj", "{24D66D03-F9DA-46C0-8C52-F55DDACDE8AF}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerStoreRestAPI", "..\ComputerStoreRestAPI\ComputerStoreRestAPI.csproj", "{11E7B5B7-7AF5-4E1E-837F-E6645D3C0EFB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerStoreEmployeeApp", "..\ComputerStoreEmployeeApp\ComputerStoreEmployeeApp.csproj", "{E1091CF6-5350-402F-A305-2973C96D2AC5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -11,10 +21,30 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{695B79EB-71FD-456D-BFEA-634500FF2ECB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{695B79EB-71FD-456D-BFEA-634500FF2ECB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{695B79EB-71FD-456D-BFEA-634500FF2ECB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{695B79EB-71FD-456D-BFEA-634500FF2ECB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{17F8960F-03CB-49D7-B335-931E6BE5F9FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{17F8960F-03CB-49D7-B335-931E6BE5F9FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{17F8960F-03CB-49D7-B335-931E6BE5F9FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{17F8960F-03CB-49D7-B335-931E6BE5F9FF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1C8DB816-F530-4CC3-9F36-F6191FE49C10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1C8DB816-F530-4CC3-9F36-F6191FE49C10}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1C8DB816-F530-4CC3-9F36-F6191FE49C10}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1C8DB816-F530-4CC3-9F36-F6191FE49C10}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{93679794-7F9A-43C4-A7C3-A1AE77FAB964}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93679794-7F9A-43C4-A7C3-A1AE77FAB964}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93679794-7F9A-43C4-A7C3-A1AE77FAB964}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93679794-7F9A-43C4-A7C3-A1AE77FAB964}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{24D66D03-F9DA-46C0-8C52-F55DDACDE8AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{24D66D03-F9DA-46C0-8C52-F55DDACDE8AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{24D66D03-F9DA-46C0-8C52-F55DDACDE8AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{24D66D03-F9DA-46C0-8C52-F55DDACDE8AF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{11E7B5B7-7AF5-4E1E-837F-E6645D3C0EFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{11E7B5B7-7AF5-4E1E-837F-E6645D3C0EFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{11E7B5B7-7AF5-4E1E-837F-E6645D3C0EFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{11E7B5B7-7AF5-4E1E-837F-E6645D3C0EFB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E1091CF6-5350-402F-A305-2973C96D2AC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E1091CF6-5350-402F-A305-2973C96D2AC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E1091CF6-5350-402F-A305-2973C96D2AC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E1091CF6-5350-402F-A305-2973C96D2AC5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
20
ComputerStore/ComputerStoreEmployeeApp1.csproj
Normal file
20
ComputerStore/ComputerStoreEmployeeApp1.csproj
Normal 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.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerStoreDatabaseImplement\ComputerStoreDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
4
ComputerStore/Pages/ComponentMenu.cshtml
Normal file
4
ComputerStore/Pages/ComponentMenu.cshtml
Normal file
@ -0,0 +1,4 @@
|
||||
@page
|
||||
@model ComputerStoreEmployeeApp.Pages.ComponentMenuModel
|
||||
@{
|
||||
}
|
12
ComputerStore/Pages/ComponentMenu.cshtml.cs
Normal file
12
ComputerStore/Pages/ComponentMenu.cshtml.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace ComputerStoreEmployeeApp.Pages
|
||||
{
|
||||
public class ComponentMenuModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,6 @@
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||
<h1 class="display-4">ComputerStore"Ты же программист"</h1>
|
||||
<p>This app was created for employees.</p>
|
||||
</div>
|
||||
|
@ -3,33 +3,52 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - ComputerStore</title>
|
||||
<title>@ViewData["Title"] - EmployeeApp</title>
|
||||
<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="~/ComputerStore.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">ComputerStore</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</li>
|
||||
</ul>
|
||||
@if(ViewBag.ShowTopBar == false)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">EmployeeApp</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Menu</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/ComponentMenu">Components</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/ProductMenu">Products</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/PCsMenu">PCs</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Request">Requests</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Report">Reports</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
</nav>
|
||||
</header>
|
||||
}
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
@ -38,7 +57,7 @@
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2023 - ComputerStore - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
© 2023 - ComputerStore - Privacy
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
116
ComputerStoreBusinessLogic/BusinessLogic/ComponentLogic.cs
Normal file
116
ComputerStoreBusinessLogic/BusinessLogic/ComponentLogic.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ComponentLogic : IComponentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_componentStorage = componentStorage;
|
||||
}
|
||||
|
||||
public bool Create(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if(_componentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model,false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_componentStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}.ID:{ ID}", model.Name, model.ID);
|
||||
|
||||
var element = _componentStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. ID:{ ID}", model?.Name, model?.ID);
|
||||
|
||||
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void CheckModel(ComponentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
if (!withParams) { return; }
|
||||
if(string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Invalid component's name", nameof(model)); }
|
||||
if(model.Price <= 0) { throw new ArgumentNullException("Invalid component's price", nameof(model)); }
|
||||
|
||||
_logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. ID: { ID} ", model.Name, model.Price, model.ID);
|
||||
|
||||
var element = _componentStorage.GetElement(new ComponentSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
|
||||
if (element != null && element.ID != model.ID)
|
||||
{
|
||||
throw new InvalidOperationException("Component with such name already exists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
104
ComputerStoreBusinessLogic/BusinessLogic/ConsignmentLogic.cs
Normal file
104
ComputerStoreBusinessLogic/BusinessLogic/ConsignmentLogic.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ConsignmentLogic : IConsignmentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConsignmentStorage _consignmentStorage;
|
||||
public ConsignmentLogic(ILogger<ConsignmentLogic> logger, IConsignmentStorage consignmentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_consignmentStorage = consignmentStorage;
|
||||
}
|
||||
|
||||
public bool Create(ConsignmentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_consignmentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ConsignmentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_consignmentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ConsignmentBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_consignmentStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ConsignmentViewModel? ReadElement(ConsignmentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Consignment ID:{ ID}", model.ID);
|
||||
|
||||
var element = _consignmentStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Consignment ID:{ID}", element.ID);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ConsignmentViewModel>? ReadList(ConsignmentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Consignment ID:{ ID}", model?.ID);
|
||||
|
||||
var list = model == null ? _consignmentStorage.GetFullList() : _consignmentStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void CheckModel(ConsignmentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
if (!withParams) { return; }
|
||||
if (model.Price <= 0) { throw new ArgumentNullException("Invalid consignment's price", nameof(model)); }
|
||||
|
||||
_logger.LogInformation("Consignment. Consignment ID:{ ID}. Order ID:{ OrderID}.", model.ID, model.OrderID);
|
||||
}
|
||||
}
|
||||
}
|
122
ComputerStoreBusinessLogic/BusinessLogic/EmployeeLogic.cs
Normal file
122
ComputerStoreBusinessLogic/BusinessLogic/EmployeeLogic.cs
Normal file
@ -0,0 +1,122 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class EmployeeLogic : IEmployeeLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IEmployeeStorage _employeeStorage;
|
||||
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_employeeStorage = employeeStorage;
|
||||
}
|
||||
public bool Create(EmployeeBindingModel model)
|
||||
{
|
||||
CheckEmployee(model);
|
||||
if (_employeeStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(EmployeeBindingModel model)
|
||||
{
|
||||
CheckEmployee(model);
|
||||
if (_employeeStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(EmployeeBindingModel model)
|
||||
{
|
||||
CheckEmployee(model, false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_employeeStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Username:{Username}.ID:{ ID}", model.Username, model.ID);
|
||||
var element = _employeeStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Username:{Username}. ID:{ ID}", model?.Username, model?.ID);
|
||||
|
||||
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public void CheckEmployee(EmployeeBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Username))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid username of user", nameof(model.Username));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid password of user", nameof(model.Password));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Client. Username:{ Username}. ID: { ID} ", model.Username, model.ID);
|
||||
|
||||
var element = _employeeStorage.GetElement(new EmployeeSearchModel
|
||||
{
|
||||
Username = model.Username
|
||||
});
|
||||
|
||||
if (element != null && element.ID != model.ID)
|
||||
{
|
||||
throw new InvalidOperationException("Employee with such username already exists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
169
ComputerStoreBusinessLogic/BusinessLogic/EmployeeReportLogic.cs
Normal file
169
ComputerStoreBusinessLogic/BusinessLogic/EmployeeReportLogic.cs
Normal file
@ -0,0 +1,169 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage;
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperModels;
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using MigraDoc.DocumentObjectModel.Fields;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class EmployeeReportLogic : IEmployeeReportLogic
|
||||
{
|
||||
private readonly IPCStorage _pcStorage;
|
||||
private readonly IProductStorage _productStorage;
|
||||
private readonly IConsignmentStorage _consignmentStorage;
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
private readonly AbstractSaveToPDF _saveToPDF;
|
||||
private readonly AbstractSaveToWord _saveToWord;
|
||||
|
||||
public EmployeeReportLogic(IPCStorage pcStorage, IProductStorage productStorage, IConsignmentStorage consignmentStorage, AbstractSaveToPDF saveToPDF, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel)
|
||||
{
|
||||
_pcStorage = pcStorage;
|
||||
_productStorage = productStorage;
|
||||
_consignmentStorage = consignmentStorage;
|
||||
_saveToPDF = saveToPDF;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToExcel = saveToExcel;
|
||||
}
|
||||
|
||||
public List<ReportPCByDateViewModel> GetPCsByDate(ReportDateBindingModel model)
|
||||
{
|
||||
return _pcStorage.GetFilteredList(new PCSearchModel
|
||||
{
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo
|
||||
})
|
||||
.Select(x => new ReportPCByDateViewModel
|
||||
{
|
||||
PCName = x.Name,
|
||||
Price = x.Price,
|
||||
Components = x.PCComponents.Values.Select(x => (x.Item1.Name, x.Item2)).ToList(),
|
||||
EmployeeUsername = x.EmployeeUsername
|
||||
}).ToList();
|
||||
|
||||
}
|
||||
|
||||
public List<ReportProductByDateViewModel> GetProductsByDate(ReportDateBindingModel model)
|
||||
{
|
||||
return _productStorage.GetFilteredList(new ProductSearchModel
|
||||
{
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo
|
||||
})
|
||||
.Select(x => new ReportProductByDateViewModel
|
||||
{
|
||||
ProductName = x.Name,
|
||||
EmployeeUsername = x.EmployeeUsername,
|
||||
Price = x.Price,
|
||||
Components = x.ProductComponents.Values.Select(x => (x.Item1.Name, x.Item2)).ToList()
|
||||
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<ReportConsignmentsViewModel> GetConsignmentsByComponents(ReportComponentsBindingModel model)
|
||||
{
|
||||
var list = new List<ReportConsignmentsViewModel>();
|
||||
|
||||
Dictionary<int, IProductModel> specifiedProducts = new Dictionary<int, IProductModel>();
|
||||
|
||||
foreach(var component in model.Components)
|
||||
{
|
||||
var products = _productStorage.GetFilteredList(new ProductSearchModel
|
||||
{
|
||||
ComponentID = component.ID
|
||||
});
|
||||
|
||||
foreach(var product in products)
|
||||
{
|
||||
if(!specifiedProducts.ContainsKey(product.ID))
|
||||
{
|
||||
specifiedProducts.Add(product.ID, product);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<int, IConsignmentModel> specifiedConsignments = new Dictionary<int, IConsignmentModel>();
|
||||
|
||||
foreach (var product in specifiedProducts)
|
||||
{
|
||||
var consignments = _consignmentStorage.GetFilteredList(new ConsignmentSearchModel
|
||||
{
|
||||
ProductID = product.Key
|
||||
});
|
||||
|
||||
if(!specifiedConsignments.Any())
|
||||
{
|
||||
foreach (var consignment in consignments)
|
||||
{
|
||||
specifiedConsignments.Add(consignment.ID, consignment);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(var consignment in consignments)
|
||||
{
|
||||
if (!specifiedConsignments.ContainsKey(consignment.ID))
|
||||
{
|
||||
specifiedConsignments.Add(consignment.ID,consignment);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach(var consignment in specifiedConsignments)
|
||||
{
|
||||
var record = new ReportConsignmentsViewModel
|
||||
{
|
||||
ID = consignment.Key,
|
||||
Products = consignment.Value.ConsignmentProducts.Values.Select(x => (x.Item1.Name,x.Item2)).ToList()
|
||||
};
|
||||
list.Add(record);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public MemoryStream SavePCsAndProductsToPdfFile(ReportDateBindingModel model)
|
||||
{
|
||||
return _saveToPDF.CreateDoc(new PDFInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Products 'n orders list",
|
||||
DateFrom = model.DateFrom!.Value,
|
||||
DateTo = model.DateTo!.Value,
|
||||
Products = GetProductsByDate(model),
|
||||
PCs = GetPCsByDate(model)
|
||||
});
|
||||
}
|
||||
|
||||
public MemoryStream SaveConsignmentsToExcelFile(ReportComponentsBindingModel model)
|
||||
{
|
||||
return _saveToExcel.CreateReport(new ExcelInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Consignments list",
|
||||
ConsignmentProducts = GetConsignmentsByComponents(model)
|
||||
});
|
||||
}
|
||||
|
||||
public MemoryStream SaveConsignmentsToWordFile(ReportComponentsBindingModel model)
|
||||
{
|
||||
return _saveToWord.CreateDoc(new WordInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Consignments list",
|
||||
Consignments = GetConsignmentsByComponents(model)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
180
ComputerStoreBusinessLogic/BusinessLogic/OrderLogic.cs
Normal file
180
ComputerStoreBusinessLogic/BusinessLogic/OrderLogic.cs
Normal file
@ -0,0 +1,180 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (model.Status != OrderStatus.Unknown)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
model.Status = OrderStatus.Accepted;
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
model.Status = OrderStatus.Unknown;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeleteOrder (OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_orderStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool UpdateOrder (OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool StatusUpdate(OrderBindingModel rawModel, OrderStatus newStatus)
|
||||
{
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
ID = rawModel.ID
|
||||
});
|
||||
|
||||
if (viewModel == null)
|
||||
{
|
||||
_logger.LogWarning("Order model not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
OrderBindingModel model = new OrderBindingModel
|
||||
{
|
||||
ID = viewModel.ID,
|
||||
Status = viewModel.Status,
|
||||
DateCreate = viewModel.DateCreate,
|
||||
DateImplement = viewModel.DateImplement,
|
||||
Price = viewModel.Price,
|
||||
SellerID = viewModel.SellerID,
|
||||
OrderConsignments = viewModel.OrderConsignments,
|
||||
OrderRequests = viewModel.OrderRequests
|
||||
};
|
||||
|
||||
CheckModel(model, false);
|
||||
if (model.Status + 1 != newStatus)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
model.Status = newStatus;
|
||||
if (model.Status == OrderStatus.Given) model.DateImplement = DateTime.Now;
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInProcess(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.InProcess);
|
||||
}
|
||||
|
||||
public bool TakeOrderReady(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Ready);
|
||||
}
|
||||
|
||||
public bool TakeOrderGiven(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Given);
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Order ID:{ OrderID}", model.ID);
|
||||
|
||||
var element = _orderStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("Order. OrderID:{Id}", model?.ID);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Incorrect Price", nameof(model.Price));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.SellerID.ToString()) && model.SellerID < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Incorrect seller ID", nameof(model.SellerID));
|
||||
}
|
||||
_logger.LogInformation("Order. OrderID:{ ID}. SellerID: { SellerID}", model.ID, model.SellerID);
|
||||
}
|
||||
}
|
||||
}
|
117
ComputerStoreBusinessLogic/BusinessLogic/PCLogic.cs
Normal file
117
ComputerStoreBusinessLogic/BusinessLogic/PCLogic.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class PCLogic : IPCLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPCStorage _PCStorage;
|
||||
public PCLogic(ILogger<PCLogic> logger, IPCStorage PCStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_PCStorage = PCStorage;
|
||||
}
|
||||
|
||||
public bool Create(PCBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_PCStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(PCBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_PCStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(PCBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_PCStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public PCViewModel? ReadElement(PCSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. PCName:{PCName}.ID:{ ID}", model.Name, model.ID);
|
||||
|
||||
var element = _PCStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<PCViewModel>? ReadList(PCSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. PCName:{PCName}. ID:{ ID}", model?.Name, model?.ID);
|
||||
|
||||
var list = model == null ? _PCStorage.GetFullList() : _PCStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void CheckModel(PCBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
if (!withParams) { return; }
|
||||
if (string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Invalid PC's name", nameof(model)); }
|
||||
if (model.Price <= 0) { throw new ArgumentNullException("Invalid PC's price", nameof(model)); }
|
||||
if (string.IsNullOrEmpty(model.EmployeeID.ToString())) { throw new ArgumentNullException("Invalid PC's employee ID", nameof(model)); }
|
||||
if (string.IsNullOrEmpty(model.RequestID.ToString())) { throw new ArgumentNullException("Invalid PC's request ID", nameof(model)); }
|
||||
|
||||
_logger.LogInformation("PC. RequestID: {RequestID}. EmployeeID: {EmployeeID}. PCName:{PCName}. Cost:{ Cost}. ID: { ID} ",model.RequestID,model.EmployeeID, model.Name, model.Price, model.ID);
|
||||
|
||||
var element = _PCStorage.GetElement(new PCSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
|
||||
if (element != null && element.ID != model.ID)
|
||||
{
|
||||
throw new InvalidOperationException("PC with such name already exists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
121
ComputerStoreBusinessLogic/BusinessLogic/ProductLogic.cs
Normal file
121
ComputerStoreBusinessLogic/BusinessLogic/ProductLogic.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ProductLogic : IProductLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProductStorage _productStorage;
|
||||
public ProductLogic(ILogger<ProductLogic> logger, IProductStorage productStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_productStorage = productStorage;
|
||||
}
|
||||
|
||||
public bool Create(ProductBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ProductBindingModel model)
|
||||
{
|
||||
if(string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
model.Name = _productStorage.GetElement(new ProductSearchModel { ID = model.ID }).Name;
|
||||
}
|
||||
|
||||
CheckModel(model);
|
||||
if (_productStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ProductBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_productStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ProductViewModel? ReadElement(ProductSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. ProductName:{ProductName}.ID:{ ID}", model.Name, model.ID);
|
||||
|
||||
var element = _productStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ProductName:{ProductName}. ID:{ ID}", model?.Name, model?.ID);
|
||||
|
||||
var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void CheckModel(ProductBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
if (!withParams) { return; }
|
||||
if (string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Invalid product's name", nameof(model)); }
|
||||
if (model.Price <= 0) { throw new ArgumentNullException("Invalid product's price", nameof(model)); }
|
||||
if (string.IsNullOrEmpty(model.EmployeeID.ToString())) { throw new ArgumentNullException("Invalid Product's employee ID", nameof(model)); }
|
||||
|
||||
_logger.LogInformation("Product. EmployeeID: {EmployeeID}. product:{product}. Cost:{ Cost}. ID: { ID} ",model.EmployeeID, model.Name, model.Price, model.ID);
|
||||
|
||||
var element = _productStorage.GetElement(new ProductSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
|
||||
if (element != null && element.ID != model.ID)
|
||||
{
|
||||
throw new InvalidOperationException("Product with such name already exists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
125
ComputerStoreBusinessLogic/BusinessLogic/ReportOrderLogic.cs
Normal file
125
ComputerStoreBusinessLogic/BusinessLogic/ReportOrderLogic.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ReportOrderLogic : IReportOrderLogic
|
||||
{
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IConsignmentStorage _consignmentStorage;
|
||||
private readonly IRequestStorage _requestStorage;
|
||||
private readonly IPCStorage _pcStorage;
|
||||
|
||||
public ReportOrderLogic(
|
||||
IOrderStorage orderStorage,
|
||||
IConsignmentStorage consignmentStorage,
|
||||
IRequestStorage requestStorage,
|
||||
IPCStorage pcStorage)
|
||||
{
|
||||
_orderStorage = orderStorage;
|
||||
_consignmentStorage = consignmentStorage;
|
||||
_requestStorage = requestStorage;
|
||||
_pcStorage = pcStorage;
|
||||
}
|
||||
|
||||
public ReportOrderViewModel GetPCsByOrders(ReportOrderBindingModel model)
|
||||
{
|
||||
var report = new ReportOrderViewModel();
|
||||
List<OrderViewModel> orders = new List<OrderViewModel>();
|
||||
|
||||
foreach (var orderSearch in model.Orders)
|
||||
{
|
||||
var element = _orderStorage.GetElement(orderSearch);
|
||||
if (element == null)
|
||||
{
|
||||
throw new Exception("Selected order is not find.");
|
||||
}
|
||||
orders.Add(element);
|
||||
}
|
||||
|
||||
foreach (var order in orders)
|
||||
{
|
||||
if (order.OrderRequests == null) { continue; }
|
||||
report.OrderPCs.Add(order.ID, (new(), new()));
|
||||
|
||||
foreach (var requestRaw in order.OrderRequests)
|
||||
{
|
||||
var request = _requestStorage.GetElement(new RequestSearchModel { ID = requestRaw.ID });
|
||||
if (request == null) { throw new Exception("Request for report is not find."); }
|
||||
|
||||
var pc = _pcStorage.GetElement(new PCSearchModel { ID = request.PCID });
|
||||
if (pc == null) { throw new Exception("PC for report is not find."); }
|
||||
|
||||
report.OrderPCs[order.ID].Item1.Add(request);
|
||||
report.OrderPCs[order.ID].Item2.Add(pc);
|
||||
}
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
public ReportOrderByDateViewModel GetOrdersByDate(ReportDateBindingModel model)
|
||||
{
|
||||
var report = new ReportOrderByDateViewModel();
|
||||
var orders = _orderStorage.GetFullList();
|
||||
foreach (var order in orders)
|
||||
{
|
||||
if (order.OrderConsignments == null && order.OrderRequests == null) { continue; }
|
||||
|
||||
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
||||
{
|
||||
report.OrderConsignmentsAndRequests.Add(order.ID, (new(), new()));
|
||||
|
||||
if (order.OrderConsignments != null)
|
||||
{
|
||||
foreach (var consignmentRaw in order.OrderConsignments)
|
||||
{
|
||||
var consignment = _consignmentStorage.GetElement(new ConsignmentSearchModel { ID = consignmentRaw.ID });
|
||||
if (consignment == null)
|
||||
{
|
||||
throw new Exception("Consignment for create report is not found");
|
||||
}
|
||||
report.OrderConsignmentsAndRequests[order.ID].Item1.Add(consignment);
|
||||
}
|
||||
}
|
||||
|
||||
if (order.OrderRequests != null)
|
||||
{
|
||||
foreach (var requestRaw in order.OrderRequests)
|
||||
{
|
||||
var request = _requestStorage.GetElement(new RequestSearchModel { ID = requestRaw.ID });
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception("Request for create report is not found");
|
||||
}
|
||||
report.OrderConsignmentsAndRequests[order.ID].Item2.Add(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
public void SaveOrdersToExcelFile(ReportOrderBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveOrdersToPdfFile(ReportDateBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveOrdersToWordFile(ReportOrderBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class RequestComponentLogic : IRequestComponentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRequestComponentStorage _requestComponentStorage;
|
||||
public RequestComponentLogic(ILogger<PCLogic> logger, IRequestComponentStorage requestComponentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_requestComponentStorage = requestComponentStorage;
|
||||
}
|
||||
|
||||
public List<RequestComponentViewModel>? ReadList(RequestSearchModel model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. PCID:{ PCID}. OrderID:{ OrderID}. ID:{ ID}", model?.PCID, model?.OrderID,model?.ID);
|
||||
var list = model.ID == null ? _requestComponentStorage.GetFullList() : _requestComponentStorage.GetFilteredList(model);
|
||||
|
||||
if(list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return new();
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
104
ComputerStoreBusinessLogic/BusinessLogic/RequestLogic.cs
Normal file
104
ComputerStoreBusinessLogic/BusinessLogic/RequestLogic.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class RequestLogic : IRequestLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRequestStorage _requestStorage;
|
||||
public RequestLogic(ILogger<RequestLogic> logger, IRequestStorage requestStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_requestStorage = requestStorage;
|
||||
}
|
||||
|
||||
public bool Create(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_requestStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_requestStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_requestStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public RequestViewModel? ReadElement(RequestSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Request ID:{ ID}. Order ID:{ OrderID}", model.ID, model.OrderID);
|
||||
|
||||
var element = _requestStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<RequestViewModel>? ReadList(RequestSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Request ID:{ ID}. Order ID: { OrderID}", model?.ID, model?.OrderID);
|
||||
|
||||
var list = model == null ? _requestStorage.GetFullList() : _requestStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void CheckModel(RequestBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
if (!withParams) { return; }
|
||||
if (model.Price <= 0) { throw new ArgumentNullException("Invalid request's price", nameof(model)); }
|
||||
|
||||
_logger.LogInformation("Request. Request ID:{ ID}. Order ID: { OrderID}. PC ID: { PCID}", model.ID, model.OrderID, model.PCID);
|
||||
}
|
||||
}
|
||||
}
|
122
ComputerStoreBusinessLogic/BusinessLogic/SellerLogic.cs
Normal file
122
ComputerStoreBusinessLogic/BusinessLogic/SellerLogic.cs
Normal file
@ -0,0 +1,122 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class SellerLogic : ISellerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISellerStorage _sellerStorage;
|
||||
public SellerLogic(ILogger<SellerLogic> logger, ISellerStorage sellerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_sellerStorage = sellerStorage;
|
||||
}
|
||||
public bool Create(SellerBindingModel model)
|
||||
{
|
||||
CheckSeller(model);
|
||||
if (_sellerStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(SellerBindingModel model)
|
||||
{
|
||||
CheckSeller(model);
|
||||
if (_sellerStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(SellerBindingModel model)
|
||||
{
|
||||
CheckSeller(model, false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_sellerStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public SellerViewModel? ReadElement(SellerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Username:{Username}.ID:{ ID}", model.Username, model.ID);
|
||||
var element = _sellerStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. ID:{ID}", element.ID);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<SellerViewModel>? ReadList(SellerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Username:{Username}. ID:{ ID}", model?.Username, model?.ID);
|
||||
|
||||
var list = model == null ? _sellerStorage.GetFullList() : _sellerStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public void CheckSeller(SellerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Username))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid username of user", nameof(model.Username));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid password of user", nameof(model.Password));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Client. Username:{ Username}. ID: { ID} ", model.Username, model.ID);
|
||||
|
||||
var element = _sellerStorage.GetElement(new SellerSearchModel
|
||||
{
|
||||
Username = model.Username
|
||||
});
|
||||
|
||||
if (element != null && element.ID != model.ID)
|
||||
{
|
||||
throw new InvalidOperationException("Seller with such username already exists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
ComputerStoreBusinessLogic/ComputerStoreBusinessLogic.csproj
Normal file
20
ComputerStoreBusinessLogic/ComputerStoreBusinessLogic.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerStoreContracts\ComputerStoreContracts.csproj" />
|
||||
<ProjectReference Include="..\ComputerStoreDataModels\ComputerStoreDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
60
ComputerStoreBusinessLogic/MailStuff/AbstractMail.cs
Normal file
60
ComputerStoreBusinessLogic/MailStuff/AbstractMail.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.MailStuff
|
||||
{
|
||||
public abstract class AbstractMail
|
||||
{
|
||||
protected string _mailLogin = string.Empty;
|
||||
protected string _mailPassword = string.Empty;
|
||||
protected string _smtpClientHost = string.Empty;
|
||||
|
||||
protected int _smtpClientPort;
|
||||
protected string _popHost = string.Empty;
|
||||
protected int _popPort;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public AbstractMail(ILogger<AbstractMail> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void MailConfig(MailConfigBindingModel config)
|
||||
{
|
||||
_mailLogin = config.Login;
|
||||
_mailPassword = config.Password;
|
||||
_smtpClientHost = config.SmtpClientHost;
|
||||
_smtpClientPort = config.SmtpClientPort;
|
||||
_popHost = config.PopHost;
|
||||
_popPort = config.PopPort;
|
||||
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPort}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
|
||||
}
|
||||
|
||||
public async void MailSendAsync(string receiver, MemoryStream report)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(receiver))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogDebug("Send E-mail: {To}, {Subject}", receiver, "Report");
|
||||
await SendMailAsync(receiver,report);
|
||||
}
|
||||
|
||||
protected abstract Task SendMailAsync(string receiver, MemoryStream report);
|
||||
}
|
||||
}
|
42
ComputerStoreBusinessLogic/MailStuff/MailKit.cs
Normal file
42
ComputerStoreBusinessLogic/MailStuff/MailKit.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.MailStuff
|
||||
{
|
||||
public class MailKit : AbstractMail
|
||||
{
|
||||
public MailKit(ILogger<MailKit> logger) : base(logger)
|
||||
{
|
||||
|
||||
}
|
||||
protected override async Task SendMailAsync(string receiver, MemoryStream report)
|
||||
{
|
||||
using var objMailMessage = new MailMessage();
|
||||
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
||||
try
|
||||
{
|
||||
objMailMessage.From = new MailAddress(_mailLogin);
|
||||
objMailMessage.To.Add(new MailAddress(receiver));
|
||||
objMailMessage.Subject = "Report";
|
||||
objMailMessage.Attachments.Add(new Attachment(report, "ReportProductsPCs.pdf", "application/pdf"));
|
||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
objSmtpClient.UseDefaultCredentials = false;
|
||||
objSmtpClient.EnableSsl = true;
|
||||
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
102
ComputerStoreBusinessLogic/OfficePackage/AbstractSaveToExcel.cs
Normal file
102
ComputerStoreBusinessLogic/OfficePackage/AbstractSaveToExcel.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToExcel
|
||||
{
|
||||
public MemoryStream CreateReport(ExcelInfo info)
|
||||
{
|
||||
|
||||
CreateExcel(info);
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = 1,
|
||||
Text = info.Title,
|
||||
StyleInfo = ExcelStyleInfoType.Title
|
||||
});
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A1",
|
||||
CellToName = "C1"
|
||||
});
|
||||
uint rowIndex = 2;
|
||||
foreach (var consignment in info.ConsignmentProducts)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = $"ConsignmentID: {consignment.ID}",
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
foreach (var (Product, Count) in consignment.Products)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = "ProductID:",
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = Product,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "E",
|
||||
RowIndex = rowIndex,
|
||||
Text = "Count:",
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "F",
|
||||
RowIndex = rowIndex,
|
||||
Text = Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
rowIndex+=2;
|
||||
}
|
||||
rowIndex++;
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = "Total products:",
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = consignment.Products.Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex+=3;
|
||||
}
|
||||
return SaveExcel(info);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected abstract void CreateExcel(ExcelInfo info);
|
||||
|
||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||
|
||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
|
||||
protected abstract MemoryStream SaveExcel(ExcelInfo info);
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPDF
|
||||
{
|
||||
public MemoryStream CreateDoc(PDFInfo info)
|
||||
{
|
||||
CreatePDF(info);
|
||||
CreateParagraph(new PDFParagraph
|
||||
{
|
||||
Text = info.Title,
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PDFParagraphAlignmentType.Center
|
||||
});
|
||||
CreateParagraph(new PDFParagraph
|
||||
{
|
||||
Text = $"from {info.DateFrom.ToShortDateString()} to {info.DateTo.ToShortDateString()}",
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PDFParagraphAlignmentType.Center
|
||||
});
|
||||
CreateTable(new List<string> { "7cm", "3cm", "2cm", "5cm"});
|
||||
CreateRow(new PDFRowParameters
|
||||
{
|
||||
Texts = new List<string> { "PC's name", "Employee's username", "Total", "Components" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PDFParagraphAlignmentType.Center
|
||||
});
|
||||
foreach (var pc in info.PCs)
|
||||
{
|
||||
CreateComplicatedRow(new PDFRowParameters
|
||||
{
|
||||
Texts = new List<string> { pc.PCName, pc.EmployeeUsername, pc.Price.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PDFParagraphAlignmentType.Left
|
||||
},pc.Components);
|
||||
}
|
||||
CreateTable(new List<string> { "7cm", "3cm", "2cm", "5cm" });
|
||||
CreateRow(new PDFRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Product's name", "Employee's username", "Total", "Components" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PDFParagraphAlignmentType.Center
|
||||
});
|
||||
foreach (var product in info.Products)
|
||||
{
|
||||
CreateComplicatedRow(new PDFRowParameters
|
||||
{
|
||||
Texts = new List<string> { product.ProductName, product.EmployeeUsername, product.Price.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PDFParagraphAlignmentType.Left
|
||||
},product.Components);
|
||||
}
|
||||
CreateParagraph(new PDFParagraph
|
||||
{
|
||||
Text = $"Total by products: {info.Products.Sum(x => x.Price)}\t",
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PDFParagraphAlignmentType.Right
|
||||
});
|
||||
CreateParagraph(new PDFParagraph
|
||||
{
|
||||
Text = $"Total by pcs: {info.PCs.Sum(x => x.Price)}\t",
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PDFParagraphAlignmentType.Right
|
||||
});
|
||||
CreateParagraph(new PDFParagraph
|
||||
{
|
||||
Text = $"Total: {info.PCs.Sum(x => x.Price) + info.Products.Sum(x => x.Price)}\t",
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PDFParagraphAlignmentType.Right
|
||||
});
|
||||
return SavePDF(info);
|
||||
}
|
||||
|
||||
protected abstract MemoryStream SavePDF(PDFInfo info);
|
||||
protected abstract void CreatePDF(PDFInfo info);
|
||||
protected abstract void CreateParagraph(PDFParagraph PDFParagraph);
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
protected abstract void CreateRow(PDFRowParameters rowParameters);
|
||||
protected abstract void CreateComplicatedRow(PDFRowParameters rowParameters, IEnumerable<(string,int)> components);
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToWord
|
||||
{
|
||||
public MemoryStream CreateDoc(WordInfo info)
|
||||
{
|
||||
CreateWord(info);
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
foreach (var consigment in info.Consignments)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { ($"ConsignmentID: {consigment.ID}", new WordTextProperties { Bold = true, Size = "24", }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
|
||||
foreach(var products in consigment.Products)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> {
|
||||
($"ProductID: {products.product} ", new WordTextProperties { Bold = false, Size = "24", }), ($"ProductCount: {products.count}", new WordTextProperties { Bold = false, Size = "24", }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
return SaveWord(info);
|
||||
}
|
||||
|
||||
protected abstract void CreateWord(WordInfo info);
|
||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||
protected abstract MemoryStream SaveWord(WordInfo info);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum ExcelStyleInfoType
|
||||
{
|
||||
Title,
|
||||
Text,
|
||||
TextWithBroder
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum PDFParagraphAlignmentType
|
||||
{
|
||||
Center,
|
||||
|
||||
Left,
|
||||
|
||||
Right
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum WordJustificationType
|
||||
{
|
||||
Center,
|
||||
Both
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelCellParameters
|
||||
{
|
||||
public string ColumnName { get; set; } = string.Empty;
|
||||
public uint RowIndex { get; set; }
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string CellReference => $"{ColumnName}{RowIndex}";
|
||||
public ExcelStyleInfoType StyleInfo { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ReportConsignmentsViewModel> ConsignmentProducts
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelMergeParameters
|
||||
{
|
||||
public string CellFromName { get; set; } = string.Empty;
|
||||
public string CellToName { get; set; } = string.Empty;
|
||||
public string Merge => $"{CellFromName}:{CellToName}";
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PDFInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportPCByDateViewModel> PCs { get; set; } = new();
|
||||
public List<ReportProductByDateViewModel> Products { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PDFParagraph
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PDFParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PDFRowParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PDFParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ReportConsignmentsViewModel> Consignments { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordParagraph
|
||||
{
|
||||
public List<(string, WordTextProperties)> Texts { get; set; } = new();
|
||||
public WordTextProperties? TextProperties { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordTextProperties
|
||||
{
|
||||
public string Size { get; set; } = string.Empty;
|
||||
public bool Bold { get; set; }
|
||||
public WordJustificationType JustificationType { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,357 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperModels;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using DocumentFormat.OpenXml.Office2013.Excel;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToExcel : AbstractSaveToExcel
|
||||
{
|
||||
private SpreadsheetDocument? _spreadsheetDocument;
|
||||
private SharedStringTablePart? _shareStringPart;
|
||||
private Worksheet? _worksheet;
|
||||
private MemoryStream mem;
|
||||
private static void CreateStyles(WorkbookPart workbookpart)
|
||||
{
|
||||
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
||||
sp.Stylesheet = new Stylesheet();
|
||||
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
|
||||
|
||||
var fontUsual = new Font();
|
||||
fontUsual.Append(new FontSize() { Val = 12D });
|
||||
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||
{ Theme = 1U });
|
||||
fontUsual.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
var fontTitle = new Font();
|
||||
fontTitle.Append(new Bold());
|
||||
fontTitle.Append(new FontSize() { Val = 14D });
|
||||
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||
{ Theme = 1U });
|
||||
fontTitle.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
fonts.Append(fontUsual);
|
||||
fonts.Append(fontTitle);
|
||||
|
||||
var fills = new Fills() { Count = 2U };
|
||||
var fill1 = new Fill();
|
||||
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
||||
var fill2 = new Fill();
|
||||
fill2.Append(new PatternFill()
|
||||
{
|
||||
PatternType = PatternValues.Gray125
|
||||
});
|
||||
fills.Append(fill1);
|
||||
fills.Append(fill2);
|
||||
|
||||
var borders = new Borders() { Count = 2U };
|
||||
var borderNoBorder = new Border();
|
||||
borderNoBorder.Append(new LeftBorder());
|
||||
borderNoBorder.Append(new RightBorder());
|
||||
borderNoBorder.Append(new TopBorder());
|
||||
borderNoBorder.Append(new BottomBorder());
|
||||
borderNoBorder.Append(new DiagonalBorder());
|
||||
var borderThin = new Border();
|
||||
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
||||
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||
{ Indexed = 64U });
|
||||
var rightBorder = new RightBorder()
|
||||
{
|
||||
Style = BorderStyleValues.Thin
|
||||
};
|
||||
rightBorder.Append(new
|
||||
DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||
{ Indexed = 64U });
|
||||
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
|
||||
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||
{ Indexed = 64U });
|
||||
var bottomBorder = new BottomBorder()
|
||||
{
|
||||
Style =
|
||||
BorderStyleValues.Thin
|
||||
};
|
||||
bottomBorder.Append(new
|
||||
DocumentFormat.OpenXml.Office2010.Excel.Color()
|
||||
{ Indexed = 64U });
|
||||
borderThin.Append(leftBorder);
|
||||
borderThin.Append(rightBorder);
|
||||
borderThin.Append(topBorder);
|
||||
borderThin.Append(bottomBorder);
|
||||
borderThin.Append(new DiagonalBorder());
|
||||
borders.Append(borderNoBorder);
|
||||
borders.Append(borderThin);
|
||||
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
||||
var cellFormatStyle = new CellFormat()
|
||||
{
|
||||
NumberFormatId = 0U,
|
||||
FontId
|
||||
= 0U,
|
||||
FillId = 0U,
|
||||
BorderId = 0U
|
||||
};
|
||||
cellStyleFormats.Append(cellFormatStyle);
|
||||
var cellFormats = new CellFormats() { Count = 3U };
|
||||
var cellFormatFont = new CellFormat()
|
||||
{
|
||||
NumberFormatId = 0U,
|
||||
FontId =
|
||||
0U,
|
||||
FillId = 0U,
|
||||
BorderId = 0U,
|
||||
FormatId = 0U,
|
||||
ApplyFont = true
|
||||
};
|
||||
var cellFormatFontAndBorder = new CellFormat()
|
||||
{
|
||||
NumberFormatId = 0U,
|
||||
FontId = 0U,
|
||||
FillId = 0U,
|
||||
BorderId = 1U,
|
||||
FormatId = 0U,
|
||||
ApplyFont = true,
|
||||
ApplyBorder = true
|
||||
};
|
||||
var cellFormatTitle = new CellFormat()
|
||||
{
|
||||
NumberFormatId = 0U,
|
||||
FontId
|
||||
= 1U,
|
||||
FillId = 0U,
|
||||
BorderId = 0U,
|
||||
FormatId = 0U,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true,
|
||||
Horizontal =
|
||||
HorizontalAlignmentValues.Center
|
||||
},
|
||||
ApplyFont = true
|
||||
};
|
||||
cellFormats.Append(cellFormatFont);
|
||||
cellFormats.Append(cellFormatFontAndBorder);
|
||||
cellFormats.Append(cellFormatTitle);
|
||||
var cellStyles = new CellStyles() { Count = 1U };
|
||||
cellStyles.Append(new CellStyle()
|
||||
{
|
||||
Name = "Normal",
|
||||
FormatId = 0U,
|
||||
BuiltinId = 0U
|
||||
});
|
||||
var differentialFormats = new
|
||||
DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats()
|
||||
{ Count = 0U };
|
||||
|
||||
var tableStyles = new TableStyles()
|
||||
{
|
||||
Count = 0U,
|
||||
DefaultTableStyle =
|
||||
"TableStyleMedium2",
|
||||
DefaultPivotStyle = "PivotStyleLight16"
|
||||
};
|
||||
var stylesheetExtensionList = new StylesheetExtensionList();
|
||||
var stylesheetExtension1 = new StylesheetExtension()
|
||||
{
|
||||
Uri =
|
||||
"{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
|
||||
};
|
||||
stylesheetExtension1.AddNamespaceDeclaration("x14",
|
||||
"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
|
||||
stylesheetExtension1.Append(new SlicerStyles()
|
||||
{
|
||||
DefaultSlicerStyle =
|
||||
"SlicerStyleLight1"
|
||||
});
|
||||
var stylesheetExtension2 = new StylesheetExtension()
|
||||
{
|
||||
Uri =
|
||||
"{9260A510-F301-46a8-8635-F512D64BE5F5}"
|
||||
};
|
||||
stylesheetExtension2.AddNamespaceDeclaration("x15",
|
||||
"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
|
||||
stylesheetExtension2.Append(new TimelineStyles()
|
||||
{
|
||||
DefaultTimelineStyle = "TimeSlicerStyleLight1"
|
||||
});
|
||||
stylesheetExtensionList.Append(stylesheetExtension1);
|
||||
stylesheetExtensionList.Append(stylesheetExtension2);
|
||||
sp.Stylesheet.Append(fonts);
|
||||
sp.Stylesheet.Append(fills);
|
||||
sp.Stylesheet.Append(borders);
|
||||
sp.Stylesheet.Append(cellStyleFormats);
|
||||
sp.Stylesheet.Append(cellFormats);
|
||||
sp.Stylesheet.Append(cellStyles);
|
||||
sp.Stylesheet.Append(differentialFormats);
|
||||
sp.Stylesheet.Append(tableStyles);
|
||||
sp.Stylesheet.Append(stylesheetExtensionList);
|
||||
}
|
||||
|
||||
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
|
||||
{
|
||||
return styleInfo switch
|
||||
{
|
||||
ExcelStyleInfoType.Title => 2U,
|
||||
ExcelStyleInfoType.TextWithBroder => 1U,
|
||||
ExcelStyleInfoType.Text => 0U,
|
||||
_ => 0U,
|
||||
};
|
||||
}
|
||||
|
||||
protected override void CreateExcel(ExcelInfo info)
|
||||
{
|
||||
mem = new MemoryStream();
|
||||
_spreadsheetDocument = SpreadsheetDocument.Create(mem, SpreadsheetDocumentType.Workbook);
|
||||
|
||||
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
||||
workbookpart.Workbook = new Workbook();
|
||||
|
||||
CreateStyles(workbookpart);
|
||||
|
||||
_shareStringPart =
|
||||
_spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
|
||||
?
|
||||
_spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
|
||||
:
|
||||
_spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
||||
|
||||
|
||||
if (_shareStringPart.SharedStringTable == null)
|
||||
{
|
||||
_shareStringPart.SharedStringTable = new SharedStringTable();
|
||||
}
|
||||
|
||||
|
||||
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
||||
|
||||
|
||||
var sheets =
|
||||
_spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
|
||||
var sheet = new Sheet()
|
||||
{
|
||||
Id =
|
||||
_spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
||||
SheetId = 1,
|
||||
Name = "List"
|
||||
};
|
||||
sheets.Append(sheet);
|
||||
_worksheet = worksheetPart.Worksheet;
|
||||
}
|
||||
|
||||
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null || _shareStringPart == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var sheetData = _worksheet.GetFirstChild<SheetData>();
|
||||
if (sheetData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Row row;
|
||||
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
|
||||
{
|
||||
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
row = new Row() { RowIndex = excelParams.RowIndex };
|
||||
sheetData.Append(row);
|
||||
}
|
||||
|
||||
Cell cell;
|
||||
if (row.Elements<Cell>().Where(c => c.CellReference!.Value ==
|
||||
excelParams.CellReference).Any())
|
||||
{
|
||||
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value ==
|
||||
excelParams.CellReference).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
Cell? refCell = null;
|
||||
foreach (Cell rowCell in row.Elements<Cell>())
|
||||
{
|
||||
if (string.Compare(rowCell.CellReference!.Value,
|
||||
excelParams.CellReference, true) > 0)
|
||||
{
|
||||
refCell = rowCell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var newCell = new Cell()
|
||||
{
|
||||
CellReference =
|
||||
excelParams.CellReference
|
||||
};
|
||||
row.InsertBefore(newCell, refCell);
|
||||
cell = newCell;
|
||||
}
|
||||
|
||||
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
|
||||
_shareStringPart.SharedStringTable.Save();
|
||||
|
||||
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
|
||||
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
||||
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
||||
}
|
||||
|
||||
protected override void MergeCells(ExcelMergeParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MergeCells mergeCells;
|
||||
if (_worksheet.Elements<MergeCells>().Any())
|
||||
{
|
||||
mergeCells = _worksheet.Elements<MergeCells>().First();
|
||||
}
|
||||
else
|
||||
{
|
||||
mergeCells = new MergeCells();
|
||||
if (_worksheet.Elements<CustomSheetView>().Any())
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells,
|
||||
_worksheet.Elements<CustomSheetView>().First());
|
||||
}
|
||||
else
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells,
|
||||
_worksheet.Elements<SheetData>().First());
|
||||
}
|
||||
}
|
||||
var mergeCell = new MergeCell()
|
||||
{
|
||||
Reference = new StringValue(excelParams.Merge)
|
||||
};
|
||||
mergeCells.Append(mergeCell);
|
||||
}
|
||||
|
||||
protected override MemoryStream SaveExcel(ExcelInfo info)
|
||||
{
|
||||
if (_spreadsheetDocument == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
|
||||
_spreadsheetDocument.Dispose();
|
||||
|
||||
mem.Seek(0,SeekOrigin.Begin);
|
||||
return mem;
|
||||
}
|
||||
}
|
||||
}
|
152
ComputerStoreBusinessLogic/OfficePackage/Implements/SaveToPDF.cs
Normal file
152
ComputerStoreBusinessLogic/OfficePackage/Implements/SaveToPDF.cs
Normal file
@ -0,0 +1,152 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperModels;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToPDF : AbstractSaveToPDF
|
||||
{
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
private static ParagraphAlignment GetParagraphAlignment(PDFParagraphAlignmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PDFParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PDFParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PDFParagraphAlignmentType.Right => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
private static void DefineStyles(Document document)
|
||||
{
|
||||
var style = document.Styles["Normal"];
|
||||
style.Font.Name = "Times New Roman";
|
||||
style.Font.Size = 14;
|
||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||
style.Font.Bold = true;
|
||||
}
|
||||
|
||||
protected override void CreateComplicatedRow(PDFRowParameters rowParameters, IEnumerable<(string, int)> components)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var row = _table.AddRow();
|
||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
||||
{
|
||||
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
|
||||
if (!string.IsNullOrEmpty(rowParameters.Style))
|
||||
{
|
||||
row.Cells[i].Style = rowParameters.Style;
|
||||
}
|
||||
|
||||
Unit borderWidth = 0.5;
|
||||
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
||||
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||
|
||||
}
|
||||
foreach (var component in components)
|
||||
{
|
||||
row.Cells[rowParameters.Texts.Count].AddParagraph($"{component.Item1} {component.Item2}");
|
||||
if (!string.IsNullOrEmpty(rowParameters.Style))
|
||||
{
|
||||
row.Cells[rowParameters.Texts.Count].Style = rowParameters.Style;
|
||||
}
|
||||
|
||||
Unit borderWidth = 0.5;
|
||||
row.Cells[rowParameters.Texts.Count].Borders.Left.Width = borderWidth;
|
||||
row.Cells[rowParameters.Texts.Count].Borders.Right.Width = borderWidth;
|
||||
row.Cells[rowParameters.Texts.Count].Borders.Top.Width = borderWidth;
|
||||
row.Cells[rowParameters.Texts.Count].Borders.Bottom.Width = borderWidth;
|
||||
row.Cells[rowParameters.Texts.Count].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
||||
row.Cells[rowParameters.Texts.Count].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateParagraph(PDFParagraph PDFParagraph)
|
||||
{
|
||||
if (_section == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var paragraph = _section.AddParagraph(PDFParagraph.Text);
|
||||
paragraph.Format.SpaceAfter = "1cm";
|
||||
paragraph.Format.Alignment = GetParagraphAlignment(PDFParagraph.ParagraphAlignment);
|
||||
paragraph.Style = paragraph.Style;
|
||||
}
|
||||
|
||||
protected override void CreatePDF(PDFInfo info)
|
||||
{
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
|
||||
protected override void CreateRow(PDFRowParameters rowParameters)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var row = _table.AddRow();
|
||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
||||
{
|
||||
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
|
||||
if (!string.IsNullOrEmpty(rowParameters.Style))
|
||||
{
|
||||
row.Cells[i].Style = rowParameters.Style;
|
||||
}
|
||||
Unit borderWidth = 0.5;
|
||||
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
||||
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateTable(List<string> columns)
|
||||
{
|
||||
if (_document == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_table = _document.LastSection.AddTable();
|
||||
foreach (var elem in columns)
|
||||
{
|
||||
_table.AddColumn(elem);
|
||||
}
|
||||
}
|
||||
|
||||
protected override MemoryStream SavePDF(PDFInfo info)
|
||||
{
|
||||
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
|
||||
MemoryStream mem = new MemoryStream();
|
||||
renderer.PdfDocument.Save(mem,false);
|
||||
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
return mem;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperEnums;
|
||||
using ComputerStoreBusinessLogic.OfficePackage.HelperModels;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToWord : AbstractSaveToWord
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
private Body? _docBody;
|
||||
private MemoryStream mem;
|
||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
WordJustificationType.Both => JustificationValues.Both,
|
||||
WordJustificationType.Center => JustificationValues.Center,
|
||||
_ => JustificationValues.Left,
|
||||
};
|
||||
}
|
||||
|
||||
private static SectionProperties CreateSectionProperties()
|
||||
{
|
||||
var properties = new SectionProperties();
|
||||
var pageSize = new PageSize
|
||||
{
|
||||
Orient = PageOrientationValues.Portrait
|
||||
};
|
||||
properties.AppendChild(pageSize);
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||
{
|
||||
if (paragraphProperties == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var properties = new ParagraphProperties();
|
||||
properties.AppendChild(new Justification()
|
||||
{
|
||||
Val = GetJustificationValues(paragraphProperties.JustificationType)
|
||||
});
|
||||
properties.AppendChild(new SpacingBetweenLines
|
||||
{
|
||||
LineRule = LineSpacingRuleValues.Auto
|
||||
});
|
||||
properties.AppendChild(new Indentation());
|
||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||
{
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize
|
||||
{
|
||||
Val = paragraphProperties.Size
|
||||
});
|
||||
}
|
||||
properties.AppendChild(paragraphMarkRunProperties);
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected override void CreateParagraph(WordParagraph paragraph)
|
||||
{
|
||||
if (_docBody == null || paragraph == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var docParagraph = new Paragraph();
|
||||
|
||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||
foreach (var run in paragraph.Texts)
|
||||
{
|
||||
var docRun = new Run();
|
||||
var properties = new RunProperties();
|
||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||
if (run.Item2.Bold)
|
||||
{
|
||||
properties.AppendChild(new Bold());
|
||||
}
|
||||
docRun.AppendChild(properties);
|
||||
docRun.AppendChild(new Text
|
||||
{
|
||||
Text = run.Item1,
|
||||
Space = SpaceProcessingModeValues.Preserve
|
||||
});
|
||||
docParagraph.AppendChild(docRun);
|
||||
}
|
||||
_docBody.AppendChild(docParagraph);
|
||||
}
|
||||
|
||||
protected override void CreateWord(WordInfo info)
|
||||
{
|
||||
mem = new MemoryStream();
|
||||
_wordDocument = WordprocessingDocument.Create(mem, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
}
|
||||
|
||||
protected override MemoryStream SaveWord(WordInfo info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_docBody.AppendChild(CreateSectionProperties());
|
||||
_wordDocument.MainDocumentPart!.Document.Save();
|
||||
_wordDocument.Dispose();
|
||||
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
return mem;
|
||||
}
|
||||
}
|
||||
}
|
12
ComputerStoreBusinessLogic/Properties/launchSettings.json
Normal file
12
ComputerStoreBusinessLogic/Properties/launchSettings.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"ComputerStoreBusinessLogic": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:50448;http://localhost:50454"
|
||||
}
|
||||
}
|
||||
}
|
23
ComputerStoreContracts/APIModels/APIProductModel.cs
Normal file
23
ComputerStoreContracts/APIModels/APIProductModel.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.APIModels
|
||||
{
|
||||
public class APIProductModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public int EmployeeID { get; set; }
|
||||
|
||||
public Dictionary<int, (ComponentViewModel Component, int Quantity)> ProductComponents { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class ComponentBindingModel : IComponentModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class ConsignmentBindingModel : IConsignmentModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public int? OrderID { get; set; }
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IProductModel, int)> ConsignmentProducts { get; set; } = new();
|
||||
}
|
||||
}
|
19
ComputerStoreContracts/BindingModels/EmployeeBindingModel.cs
Normal file
19
ComputerStoreContracts/BindingModels/EmployeeBindingModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class EmployeeBindingModel : IEmployeeModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string? FirstName { get; set; } = string.Empty;
|
||||
public string? LastName { get; set; } = string.Empty;
|
||||
public string? MiddleName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class MailConfigBindingModel
|
||||
{
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string SmtpClientHost { get; set; } = string.Empty;
|
||||
public int SmtpClientPort { get; set; }
|
||||
public string PopHost { get; set; } = string.Empty;
|
||||
public int PopPort { get; set; }
|
||||
}
|
||||
}
|
22
ComputerStoreContracts/BindingModels/OrderBindingModel.cs
Normal file
22
ComputerStoreContracts/BindingModels/OrderBindingModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using ComputerStoreDataModels.Enums;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public double Price { get; set; }
|
||||
public List<IConsignmentModel>? OrderConsignments { get; set; } = new();
|
||||
public List<IRequestModel>? OrderRequests { get; set; } = new();
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public int SellerID { get; set; }
|
||||
}
|
||||
}
|
31
ComputerStoreContracts/BindingModels/PCBindingModel.cs
Normal file
31
ComputerStoreContracts/BindingModels/PCBindingModel.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class PCBindingModel : IPCModel
|
||||
{
|
||||
public int ID {get; set;}
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public int EmployeeID { get; set; }
|
||||
|
||||
public int RequestID { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> PCComponents { get; set; } = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public PCBindingModel(Dictionary<int, (ComponentBindingModel Component, int Quantity)> PCComponents)
|
||||
{
|
||||
this.PCComponents = PCComponents.ToDictionary(x => x.Key, x => (x.Value.Component as IComponentModel, x.Value.Quantity));
|
||||
}
|
||||
public PCBindingModel() { }
|
||||
}
|
||||
}
|
24
ComputerStoreContracts/BindingModels/ProductBindingModel.cs
Normal file
24
ComputerStoreContracts/BindingModels/ProductBindingModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class ProductBindingModel : IProductModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public int EmployeeID { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel Component, int Quantity)> ProductComponents { get; set; } = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public ProductBindingModel(Dictionary<int, (ComponentBindingModel Component, int Quantity)> ProductComponents)
|
||||
{
|
||||
this.ProductComponents = ProductComponents.ToDictionary(x => x.Key, x => (x.Value.Component as IComponentModel, x.Value.Quantity));
|
||||
}
|
||||
public ProductBindingModel() { }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class ReportComponentsBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public List<ComponentSearchModel> Components { get; set; } = new List<ComponentSearchModel>();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class ReportDateBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set;}
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class ReportOrderBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public List<OrderSearchModel> Orders { get; set; } = new();
|
||||
}
|
||||
}
|
19
ComputerStoreContracts/BindingModels/RequestBindingModel.cs
Normal file
19
ComputerStoreContracts/BindingModels/RequestBindingModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class RequestBindingModel : IRequestModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public int? OrderID { get; set; }
|
||||
public double Price { get; set; }
|
||||
public int? PCID { get; set; }
|
||||
|
||||
public List<(IComponentModel, int)> RequestComponents { get; set; } = new();
|
||||
}
|
||||
}
|
20
ComputerStoreContracts/BindingModels/SellerBindingModel.cs
Normal file
20
ComputerStoreContracts/BindingModels/SellerBindingModel.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BindingModels
|
||||
{
|
||||
public class SellerBindingModel : ISellerModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string? FirstName { get; set; } = string.Empty;
|
||||
public string? LastName { get; set; } = string.Empty;
|
||||
public string? MiddleName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||
|
||||
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||
|
||||
bool Create(ComponentBindingModel model);
|
||||
bool Update(ComponentBindingModel model);
|
||||
bool Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IConsignmentLogic
|
||||
{
|
||||
List<ConsignmentViewModel>? ReadList(ConsignmentSearchModel? model);
|
||||
ConsignmentViewModel? ReadElement(ConsignmentSearchModel model);
|
||||
bool Create(ConsignmentBindingModel model);
|
||||
bool Update(ConsignmentBindingModel model);
|
||||
bool Delete(ConsignmentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IEmployeeLogic
|
||||
{
|
||||
List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model);
|
||||
EmployeeViewModel? ReadElement(EmployeeSearchModel model);
|
||||
bool Create(EmployeeBindingModel model);
|
||||
bool Update(EmployeeBindingModel model);
|
||||
bool Delete(EmployeeBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IEmployeeReportLogic
|
||||
{
|
||||
List<ReportProductByDateViewModel> GetProductsByDate(ReportDateBindingModel model);
|
||||
List<ReportPCByDateViewModel> GetPCsByDate(ReportDateBindingModel model);
|
||||
List<ReportConsignmentsViewModel> GetConsignmentsByComponents(ReportComponentsBindingModel model);
|
||||
|
||||
MemoryStream SavePCsAndProductsToPdfFile(ReportDateBindingModel model);
|
||||
MemoryStream SaveConsignmentsToExcelFile(ReportComponentsBindingModel model);
|
||||
MemoryStream SaveConsignmentsToWordFile(ReportComponentsBindingModel model);
|
||||
}
|
||||
}
|
24
ComputerStoreContracts/BusinessLogicContracts/IOrderLogic.cs
Normal file
24
ComputerStoreContracts/BusinessLogicContracts/IOrderLogic.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInProcess(OrderBindingModel model);
|
||||
bool TakeOrderReady(OrderBindingModel model);
|
||||
bool TakeOrderGiven(OrderBindingModel model);
|
||||
|
||||
OrderViewModel? ReadElement(OrderSearchModel model);
|
||||
bool UpdateOrder(OrderBindingModel model);
|
||||
bool DeleteOrder(OrderBindingModel model);
|
||||
}
|
||||
}
|
22
ComputerStoreContracts/BusinessLogicContracts/IPCLogic.cs
Normal file
22
ComputerStoreContracts/BusinessLogicContracts/IPCLogic.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IPCLogic
|
||||
{
|
||||
List<PCViewModel>? ReadList(PCSearchModel? model);
|
||||
|
||||
PCViewModel? ReadElement(PCSearchModel model);
|
||||
|
||||
bool Create(PCBindingModel model);
|
||||
bool Update(PCBindingModel model);
|
||||
bool Delete(PCBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IProductLogic
|
||||
{
|
||||
List<ProductViewModel>? ReadList(ProductSearchModel? model);
|
||||
|
||||
ProductViewModel? ReadElement(ProductSearchModel model);
|
||||
|
||||
bool Create(ProductBindingModel model);
|
||||
bool Update(ProductBindingModel model);
|
||||
bool Delete(ProductBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IReportOrderLogic
|
||||
{
|
||||
ReportOrderViewModel GetPCsByOrders(ReportOrderBindingModel model);
|
||||
ReportOrderByDateViewModel GetOrdersByDate(ReportDateBindingModel model);
|
||||
void SaveOrdersToWordFile(ReportOrderBindingModel model);
|
||||
void SaveOrdersToExcelFile(ReportOrderBindingModel model);
|
||||
void SaveOrdersToPdfFile(ReportDateBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IRequestComponentLogic
|
||||
{
|
||||
List<RequestComponentViewModel>? ReadList(RequestSearchModel? model);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IRequestLogic
|
||||
{
|
||||
List<RequestViewModel>? ReadList(RequestSearchModel? model);
|
||||
RequestViewModel? ReadElement(RequestSearchModel model);
|
||||
bool Create(RequestBindingModel model);
|
||||
bool Update(RequestBindingModel model);
|
||||
bool Delete(RequestBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface ISellerLogic
|
||||
{
|
||||
List<SellerViewModel>? ReadList(SellerSearchModel? model);
|
||||
SellerViewModel? ReadElement(SellerSearchModel model);
|
||||
bool Create(SellerBindingModel model);
|
||||
bool Update(SellerBindingModel model);
|
||||
bool Delete(SellerBindingModel model);
|
||||
}
|
||||
}
|
17
ComputerStoreContracts/ComputerStoreContracts.csproj
Normal file
17
ComputerStoreContracts/ComputerStoreContracts.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerStoreDataModels\ComputerStoreDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
12
ComputerStoreContracts/Properties/launchSettings.json
Normal file
12
ComputerStoreContracts/Properties/launchSettings.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"ComputerStoreContracts": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:50450;http://localhost:50453"
|
||||
}
|
||||
}
|
||||
}
|
14
ComputerStoreContracts/SearchModels/ComponentSearchModel.cs
Normal file
14
ComputerStoreContracts/SearchModels/ComponentSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.SearchModels
|
||||
{
|
||||
public class ConsignmentSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public int? OrderID { get; set; }
|
||||
public int? ProductID { get; set; }
|
||||
}
|
||||
}
|
15
ComputerStoreContracts/SearchModels/EmployeeSearchModel.cs
Normal file
15
ComputerStoreContracts/SearchModels/EmployeeSearchModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.SearchModels
|
||||
{
|
||||
public class EmployeeSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public string? Username { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
19
ComputerStoreContracts/SearchModels/OrderSearchModel.cs
Normal file
19
ComputerStoreContracts/SearchModels/OrderSearchModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using ComputerStoreDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public int? ConsignmentID { get; set; }
|
||||
public int? RequestID { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public int? SellerID { get; set; }
|
||||
}
|
||||
}
|
18
ComputerStoreContracts/SearchModels/PCSearchModel.cs
Normal file
18
ComputerStoreContracts/SearchModels/PCSearchModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.SearchModels
|
||||
{
|
||||
public class PCSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? RequestID { get; set; }
|
||||
public int? EmployeeID { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set;}
|
||||
}
|
||||
}
|
18
ComputerStoreContracts/SearchModels/ProductSearchModel.cs
Normal file
18
ComputerStoreContracts/SearchModels/ProductSearchModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.SearchModels
|
||||
{
|
||||
public class ProductSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? EmployeeID { get; set; }
|
||||
public int? ComponentID { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
}
|
||||
}
|
15
ComputerStoreContracts/SearchModels/RequestSearchModel.cs
Normal file
15
ComputerStoreContracts/SearchModels/RequestSearchModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.SearchModels
|
||||
{
|
||||
public class RequestSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public int? OrderID { get; set; }
|
||||
public int? PCID { get; set; }
|
||||
}
|
||||
}
|
15
ComputerStoreContracts/SearchModels/SellerSearchModel.cs
Normal file
15
ComputerStoreContracts/SearchModels/SellerSearchModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.SearchModels
|
||||
{
|
||||
public class SellerSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public string? Username { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
21
ComputerStoreContracts/StorageContracts/IComponentStorage.cs
Normal file
21
ComputerStoreContracts/StorageContracts/IComponentStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IComponentStorage
|
||||
{
|
||||
List<ComponentViewModel> GetFullList();
|
||||
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||
ComponentViewModel? Update(ComponentBindingModel model);
|
||||
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IConsignmentStorage
|
||||
{
|
||||
List<ConsignmentViewModel> GetFullList();
|
||||
List<ConsignmentViewModel> GetFilteredList(ConsignmentSearchModel model);
|
||||
ConsignmentViewModel? GetElement(ConsignmentSearchModel model);
|
||||
ConsignmentViewModel? Insert(ConsignmentBindingModel model);
|
||||
ConsignmentViewModel? Update(ConsignmentBindingModel model);
|
||||
ConsignmentViewModel? Delete(ConsignmentBindingModel model);
|
||||
}
|
||||
}
|
21
ComputerStoreContracts/StorageContracts/IEmployeeStorage.cs
Normal file
21
ComputerStoreContracts/StorageContracts/IEmployeeStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IEmployeeStorage
|
||||
{
|
||||
List<EmployeeViewModel> GetFullList();
|
||||
List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model);
|
||||
EmployeeViewModel? GetElement(EmployeeSearchModel model);
|
||||
EmployeeViewModel? Insert(EmployeeBindingModel model);
|
||||
EmployeeViewModel? Update(EmployeeBindingModel model);
|
||||
EmployeeViewModel? Delete(EmployeeBindingModel model);
|
||||
}
|
||||
}
|
21
ComputerStoreContracts/StorageContracts/IOrderStorage.cs
Normal file
21
ComputerStoreContracts/StorageContracts/IOrderStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IOrderStorage
|
||||
{
|
||||
List<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
21
ComputerStoreContracts/StorageContracts/IPCStorage.cs
Normal file
21
ComputerStoreContracts/StorageContracts/IPCStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IPCStorage
|
||||
{
|
||||
List<PCViewModel> GetFullList();
|
||||
List<PCViewModel> GetFilteredList(PCSearchModel model);
|
||||
PCViewModel? GetElement(PCSearchModel model);
|
||||
PCViewModel? Insert(PCBindingModel model);
|
||||
PCViewModel? Update(PCBindingModel model);
|
||||
PCViewModel? Delete(PCBindingModel model);
|
||||
}
|
||||
}
|
21
ComputerStoreContracts/StorageContracts/IProductStorage.cs
Normal file
21
ComputerStoreContracts/StorageContracts/IProductStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IProductStorage
|
||||
{
|
||||
List<ProductViewModel> GetFullList();
|
||||
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
|
||||
ProductViewModel? GetElement(ProductSearchModel model);
|
||||
ProductViewModel? Insert(ProductBindingModel model);
|
||||
ProductViewModel? Update(ProductBindingModel model);
|
||||
ProductViewModel? Delete(ProductBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IRequestComponentStorage
|
||||
{
|
||||
List<RequestComponentViewModel> GetFullList();
|
||||
List<RequestComponentViewModel> GetFilteredList(RequestSearchModel model);
|
||||
}
|
||||
}
|
21
ComputerStoreContracts/StorageContracts/IRequestStorage.cs
Normal file
21
ComputerStoreContracts/StorageContracts/IRequestStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IRequestStorage
|
||||
{
|
||||
List<RequestViewModel> GetFullList();
|
||||
List<RequestViewModel> GetFilteredList(RequestSearchModel model);
|
||||
RequestViewModel? GetElement(RequestSearchModel model);
|
||||
RequestViewModel? Insert(RequestBindingModel model);
|
||||
RequestViewModel? Update(RequestBindingModel model);
|
||||
RequestViewModel? Delete(RequestBindingModel model);
|
||||
}
|
||||
}
|
21
ComputerStoreContracts/StorageContracts/ISellerStorage.cs
Normal file
21
ComputerStoreContracts/StorageContracts/ISellerStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.StorageContracts
|
||||
{
|
||||
public interface ISellerStorage
|
||||
{
|
||||
List<SellerViewModel> GetFullList();
|
||||
List<SellerViewModel> GetFilteredList(SellerSearchModel model);
|
||||
SellerViewModel? GetElement(SellerSearchModel model);
|
||||
SellerViewModel? Insert(SellerBindingModel model);
|
||||
SellerViewModel? Update(SellerBindingModel model);
|
||||
SellerViewModel? Delete(SellerBindingModel model);
|
||||
}
|
||||
}
|
23
ComputerStoreContracts/ViewModels/ComponentViewModel.cs
Normal file
23
ComputerStoreContracts/ViewModels/ComponentViewModel.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int ID {get; set;}
|
||||
|
||||
[DisplayName("Component's name")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Component's price")]
|
||||
public double Price { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
22
ComputerStoreContracts/ViewModels/ConsignmentViewModel.cs
Normal file
22
ComputerStoreContracts/ViewModels/ConsignmentViewModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ConsignmentViewModel : IConsignmentModel
|
||||
{
|
||||
[DisplayName("Consignment ID")]
|
||||
public int ID { get; set; }
|
||||
[DisplayName("Order ID")]
|
||||
public int? OrderID { get; set; }
|
||||
[DisplayName("Price")]
|
||||
public double Price { get; set; }
|
||||
|
||||
public Dictionary<int, (IProductModel, int)> ConsignmentProducts { get; set; } = new();
|
||||
}
|
||||
}
|
31
ComputerStoreContracts/ViewModels/EmployeeViewModel.cs
Normal file
31
ComputerStoreContracts/ViewModels/EmployeeViewModel.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class EmployeeViewModel : IEmployeeModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
|
||||
[DisplayName("Employee's login")]
|
||||
public string Username { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Employee's first name")]
|
||||
public string? FirstName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Employee's last name")]
|
||||
public string? LastName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Employee's middle name")]
|
||||
public string? MiddleName { get; set; } = string.Empty;
|
||||
|
||||
|
||||
}
|
||||
}
|
32
ComputerStoreContracts/ViewModels/OrderViewModel.cs
Normal file
32
ComputerStoreContracts/ViewModels/OrderViewModel.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using ComputerStoreDataModels.Enums;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Order ID")]
|
||||
public int ID { get; set; }
|
||||
[DisplayName("Price")]
|
||||
public double Price { get; set; }
|
||||
[DisplayName("Status")]
|
||||
public OrderStatus Status { get; set; }
|
||||
[DisplayName("Creation date")]
|
||||
public DateTime DateCreate { get; set; }
|
||||
[DisplayName("Implementation date")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
public int SellerID { get; set; }
|
||||
[DisplayName("SellerUsername")]
|
||||
public string? SellerUsername { get; set; } = string.Empty;
|
||||
|
||||
public List<IConsignmentModel>? OrderConsignments { get; set; } = new();
|
||||
public List<IRequestModel>? OrderRequests { get; set; } = new();
|
||||
}
|
||||
}
|
39
ComputerStoreContracts/ViewModels/PCViewModel.cs
Normal file
39
ComputerStoreContracts/ViewModels/PCViewModel.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class PCViewModel : IPCModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
|
||||
[DisplayName("PC's name")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("PC's price")]
|
||||
public double Price { get; set; }
|
||||
|
||||
public int EmployeeID { get; set; }
|
||||
|
||||
[DisplayName("Employee's username")]
|
||||
public string EmployeeUsername { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Request ID")]
|
||||
public int RequestID { get; set; }
|
||||
public Dictionary<int, (IComponentModel Component, int Quantity)> PCComponents { get; set; } = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public PCViewModel(Dictionary<int, (ComponentBindingModel Component, int Quantity)> PCComponents)
|
||||
{
|
||||
this.PCComponents = PCComponents.ToDictionary(x => x.Key, x => (x.Value.Component as IComponentModel, x.Value.Quantity));
|
||||
}
|
||||
public PCViewModel() { }
|
||||
}
|
||||
}
|
38
ComputerStoreContracts/ViewModels/ProductViewModel.cs
Normal file
38
ComputerStoreContracts/ViewModels/ProductViewModel.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ProductViewModel : IProductModel
|
||||
{
|
||||
public int ID {get; set;}
|
||||
|
||||
[DisplayName("Product's name")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Product's price")]
|
||||
public double Price { get; set; }
|
||||
|
||||
public int EmployeeID { get; set; }
|
||||
|
||||
[DisplayName("Employee's username")]
|
||||
public string EmployeeUsername { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, (IComponentModel Component, int Quantity)> ProductComponents { get; set; } = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public ProductViewModel(Dictionary<int, (ComponentBindingModel Component, int Quantity)> ProductComponents)
|
||||
{
|
||||
this.ProductComponents = ProductComponents.ToDictionary(x => x.Key, x => (x.Value.Component as IComponentModel, x.Value.Quantity));
|
||||
}
|
||||
public ProductViewModel() { }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ReportConsignmentsViewModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public List<(string product, int count)> Products { get; set; } = new List<(string, int)>();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ReportOrderByDateViewModel
|
||||
{
|
||||
public Dictionary<int, (List<ConsignmentViewModel>, List<RequestViewModel>)> OrderConsignmentsAndRequests { get; set; } = new();
|
||||
}
|
||||
}
|
13
ComputerStoreContracts/ViewModels/ReportOrderViewModel.cs
Normal file
13
ComputerStoreContracts/ViewModels/ReportOrderViewModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ReportOrderViewModel
|
||||
{
|
||||
public Dictionary<int, (List<RequestViewModel>, List<PCViewModel>)> OrderPCs { get; set; } = new();
|
||||
}
|
||||
}
|
17
ComputerStoreContracts/ViewModels/ReportPCByDateViewModel.cs
Normal file
17
ComputerStoreContracts/ViewModels/ReportPCByDateViewModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ReportPCByDateViewModel
|
||||
{
|
||||
public string PCName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public List<(string Component, int count)> Components { get; set; } = new List<(string Component, int count)> ();
|
||||
|
||||
public string EmployeeUsername { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class ReportProductByDateViewModel
|
||||
{
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public List<(string Component, int count)> Components { get; set; } = new List<(string Component, int count)>();
|
||||
public string EmployeeUsername { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class RequestComponentViewModel
|
||||
{
|
||||
[DisplayName("RequestID")]
|
||||
public int RequestID { get; set; }
|
||||
|
||||
[DisplayName("ComponentID")]
|
||||
public int ComponentID { get; set; }
|
||||
|
||||
[DisplayName("Component's name")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Component's count")]
|
||||
public int ComponentCount { get; set; }
|
||||
|
||||
[DisplayName("PCID")]
|
||||
public int PCID { get; set; }
|
||||
|
||||
}
|
||||
}
|
28
ComputerStoreContracts/ViewModels/RequestViewModel.cs
Normal file
28
ComputerStoreContracts/ViewModels/RequestViewModel.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class RequestViewModel : IRequestModel
|
||||
{
|
||||
[DisplayName("Request ID")]
|
||||
public int ID { get; set; }
|
||||
[DisplayName("Order ID")]
|
||||
public int? OrderID { get; set; }
|
||||
[DisplayName("Price")]
|
||||
public double Price { get; set; }
|
||||
|
||||
[DisplayName("PC ID")]
|
||||
public int? PCID { get; set; }
|
||||
|
||||
[DisplayName("PC's name")]
|
||||
public string? PCName { get; set; } = string.Empty;
|
||||
|
||||
public List<(IComponentModel, int)> RequestComponents { get; set; } = new();
|
||||
}
|
||||
}
|
26
ComputerStoreContracts/ViewModels/SellerViewModel.cs
Normal file
26
ComputerStoreContracts/ViewModels/SellerViewModel.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreContracts.ViewModels
|
||||
{
|
||||
public class SellerViewModel : ISellerModel
|
||||
{
|
||||
[DisplayName("Seller ID")]
|
||||
public int ID { get; set; }
|
||||
[DisplayName("Username")]
|
||||
public string Username { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[DisplayName("FirstName")]
|
||||
public string? FirstName { get; set; } = string.Empty;
|
||||
[DisplayName("LastName")]
|
||||
public string? LastName { get; set; } = string.Empty;
|
||||
[DisplayName("MiddleName")]
|
||||
public string? MiddleName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
17
ComputerStoreDataModels/Enums/OrderStatus.cs
Normal file
17
ComputerStoreDataModels/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreDataModels.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Unknown = -1,
|
||||
Accepted = 0,
|
||||
InProcess = 1,
|
||||
Ready = 2,
|
||||
Given = 3
|
||||
}
|
||||
}
|
13
ComputerStoreDataModels/IID.cs
Normal file
13
ComputerStoreDataModels/IID.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreDataModels
|
||||
{
|
||||
public interface IID
|
||||
{
|
||||
int ID { get; }
|
||||
}
|
||||
}
|
17
ComputerStoreDataModels/Models/IComponentModel.cs
Normal file
17
ComputerStoreDataModels/Models/IComponentModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreDataModels.Models
|
||||
{
|
||||
public interface IComponentModel : IID
|
||||
{
|
||||
[MaxLength(255)]
|
||||
string Name { get;}
|
||||
double Price { get;}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user