EmployeeSearchModel have been changed and restAPI with basic CRUD methods for models has been created.
This commit is contained in:
parent
b37e13575b
commit
a55b6c91ea
@ -3,15 +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}") = "ComputerStoreEmployeeApp", "ComputerStoreEmployeeApp.csproj", "{695B79EB-71FD-456D-BFEA-634500FF2ECB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerStoreBusinessLogic", "..\ComputerStoreBusinessLogic\ComputerStoreBusinessLogic.csproj", "{17F8960F-03CB-49D7-B335-931E6BE5F9FF}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerStoreBusinessLogic", "..\ComputerStoreBusinessLogic\ComputerStoreBusinessLogic.csproj", "{17F8960F-03CB-49D7-B335-931E6BE5F9FF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerStoreContracts", "..\ComputerStoreContracts\ComputerStoreContracts.csproj", "{1C8DB816-F530-4CC3-9F36-F6191FE49C10}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerStoreContracts", "..\ComputerStoreContracts\ComputerStoreContracts.csproj", "{1C8DB816-F530-4CC3-9F36-F6191FE49C10}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerStoreDataModels", "..\ComputerStoreDataModels\ComputerStoreDataModels.csproj", "{93679794-7F9A-43C4-A7C3-A1AE77FAB964}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerStoreDataModels", "..\ComputerStoreDataModels\ComputerStoreDataModels.csproj", "{93679794-7F9A-43C4-A7C3-A1AE77FAB964}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerStoreDatabaseImplement", "..\ComputerStoreDatabaseImplement\ComputerStoreDatabaseImplement.csproj", "{24D66D03-F9DA-46C0-8C52-F55DDACDE8AF}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerStoreDatabaseImplement", "..\ComputerStoreDatabaseImplement\ComputerStoreDatabaseImplement.csproj", "{24D66D03-F9DA-46C0-8C52-F55DDACDE8AF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerStoreRestAPI", "..\ComputerStoreRestAPI\ComputerStoreRestAPI.csproj", "{11E7B5B7-7AF5-4E1E-837F-E6645D3C0EFB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -39,6 +41,10 @@ Global
|
||||
{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
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -10,5 +10,6 @@ namespace ComputerStoreContracts.SearchModels
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public string? Username { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
13
ComputerStoreRestAPI/ComputerStoreRestAPI.csproj
Normal file
13
ComputerStoreRestAPI/ComputerStoreRestAPI.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
63
ComputerStoreRestAPI/Controllers/EmployeeController.cs
Normal file
63
ComputerStoreRestAPI/Controllers/EmployeeController.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ComputerStoreRestAPI.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class EmployeeController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IEmployeeLogic _logic;
|
||||
|
||||
public EmployeeController(IEmployeeLogic logic, ILogger<EmployeeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public EmployeeViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new EmployeeSearchModel { Username = login, Password = password });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Employee logging in error"); throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public bool Register(EmployeeBindingModel employee)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.Create(employee);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Employee registration error ");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
public bool UpdateData(EmployeeBindingModel employee)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.Update(employee);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Update of data error ");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
195
ComputerStoreRestAPI/Controllers/MainController.cs
Normal file
195
ComputerStoreRestAPI/Controllers/MainController.cs
Normal file
@ -0,0 +1,195 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ComputerStoreRestAPI.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class MainController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentLogic _componentLogic;
|
||||
private readonly IPCLogic _pcLogic;
|
||||
private readonly IProductLogic _productLogic;
|
||||
private readonly IEmployeeReportLogic _employeeReportLogic;
|
||||
|
||||
public MainController(ILogger<MainController> logger, IComponentLogic componentLogic, IPCLogic pcLogic, IProductLogic productLogic, IEmployeeReportLogic employeeReportLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_componentLogic = componentLogic;
|
||||
_pcLogic = pcLogic;
|
||||
_productLogic = productLogic;
|
||||
_employeeReportLogic = employeeReportLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ComponentViewModel>? GetComponentsList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _componentLogic.ReadList(null);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Receiving list of components error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public bool DeleteComponent(ComponentBindingModel component)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _componentLogic.Delete(component);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Removing component error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
public bool UpdateComponent(ComponentBindingModel component)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _componentLogic.Update(component);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Updating component error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public bool InsertComponent(ComponentBindingModel component)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _componentLogic.Create(component);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Inserting component error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ProductViewModel>? GetProductsList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _productLogic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Receiving list of products error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public bool DeleteProduct(ProductBindingModel product)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _productLogic.Delete(product);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Removing product error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
public bool UpdateProduct(ProductBindingModel product)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _productLogic.Update(product);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Updating product error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public bool InsertProduct(ProductBindingModel product)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _productLogic.Create(product);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Inserting product error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<PCViewModel>? GetPCsList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _pcLogic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Receiving list of PCs error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public bool DeletePC(PCBindingModel pc)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _pcLogic.Delete(pc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Removing PC error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
public bool UpdateProduct(PCBindingModel pc)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _pcLogic.Update(pc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Updating PC error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public bool InsertProduct(PCBindingModel pc)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _pcLogic.Create(pc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Inserting PC error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
ComputerStoreRestAPI/Program.cs
Normal file
44
ComputerStoreRestAPI/Program.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using ComputerStoreBusinessLogic.BusinessLogic;
|
||||
using ComputerStoreContracts.BusinessLogicContracts;
|
||||
using ComputerStoreContracts.StorageContracts;
|
||||
using ComputerStoreDatabaseImplement.Implements;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||
builder.Logging.AddLog4Net("log4net.config");
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddTransient<IEmployeeStorage,EmployeeStorage>();
|
||||
builder.Services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
builder.Services.AddTransient<IPCStorage,PCStorage>();
|
||||
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
||||
|
||||
builder.Services.AddTransient<IEmployeeLogic,EmployeeLogic>();
|
||||
builder.Services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
builder.Services.AddTransient<IEmployeeReportLogic, EmployeeReportLogic>();
|
||||
builder.Services.AddTransient<IPCLogic, PCLogic>();
|
||||
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
31
ComputerStoreRestAPI/Properties/launchSettings.json
Normal file
31
ComputerStoreRestAPI/Properties/launchSettings.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:11328",
|
||||
"sslPort": 44392
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"ComputerStoreRestAPI": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7081;http://localhost:5112",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
ComputerStoreRestAPI/appsettings.Development.json
Normal file
8
ComputerStoreRestAPI/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
ComputerStoreRestAPI/appsettings.json
Normal file
9
ComputerStoreRestAPI/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Loading…
Reference in New Issue
Block a user