add RestApi
This commit is contained in:
parent
50bc49151d
commit
3d5b7a93f8
@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarShowroomContracts", "Car
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarShowroomDatabaseStorage", "CarShowroomDatabaseStorage\CarShowroomDatabaseStorage.csproj", "{7F0A0E4D-6EFD-459D-AFFF-99F3185243F8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarShowroomBusinessLogic", "CarShowroomBusinessLogic\CarShowroomBusinessLogic.csproj", "{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarShowroomBusinessLogic", "CarShowroomBusinessLogic\CarShowroomBusinessLogic.csproj", "{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarShowroomRestApi", "CarShowroomRestApi\CarShowroomRestApi.csproj", "{A2A7076D-5EE3-46CA-B52C-D263213CE33D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -33,6 +35,10 @@ Global
|
||||
{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A2A7076D-5EE3-46CA-B52C-D263213CE33D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A2A7076D-5EE3-46CA-B52C-D263213CE33D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A2A7076D-5EE3-46CA-B52C-D263213CE33D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A2A7076D-5EE3-46CA-B52C-D263213CE33D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -47,6 +47,7 @@ namespace CarShowroomBusinessLogic.BusinessLogic
|
||||
public bool Create(SaleDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.SaleTime = DateTime.Now;
|
||||
if (_saleStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
|
@ -3,7 +3,6 @@ using CarShowroomContracts.StorageContracts;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using ServiceShowroomContracts.BusinessLogic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -7,7 +7,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceShowroomContracts.BusinessLogic
|
||||
namespace CarShowroomContracts.BusinessLogic
|
||||
{
|
||||
public interface IServiceLogic
|
||||
{
|
||||
|
19
CarShowroom/CarShowroomRestApi/CarShowroomRestApi.csproj
Normal file
19
CarShowroom/CarShowroomRestApi/CarShowroomRestApi.csproj
Normal file
@ -0,0 +1,19 @@
|
||||
<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.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarShowroomBusinessLogic\CarShowroomBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\CarShowroomDatabaseStorage\CarShowroomDatabaseStorage.csproj" />
|
||||
<ProjectReference Include="..\CarShowroomDataModels\CarShowroomDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
95
CarShowroom/CarShowroomRestApi/Controllers/CarController.cs
Normal file
95
CarShowroom/CarShowroomRestApi/Controllers/CarController.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CarShowroomRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class CarController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICarLogic _logic;
|
||||
|
||||
public CarController(ILogger<CarController> logger, ICarLogic car)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = car;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<CarView>? GetCarList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка машин");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public CarView? GetCar(int CarId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new CarSearch
|
||||
{
|
||||
Id = CarId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения машины по Id={Id}", CarId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateCar(CarDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания машины");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public void UpdateCar(CarDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления машины");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteCar(CarDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления машины");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CarShowroomRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ClientController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientLogic _logic;
|
||||
|
||||
public ClientController(ILogger<ClientController> logger, IClientLogic client)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = client;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ClientView>? GetClientList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Îøèáêà ïîëó÷åíèÿ ñïèñêà êëèåíòîâ");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ClientView? GetClient(int ClientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ClientSearch
|
||||
{
|
||||
Id = ClientId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Îøèáêà ïîëó÷åíèÿ êëèåíòà ïî Id={Id}", ClientId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateClient(ClientDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Îøèáêà ñîçäàíèÿ êëèåíòà");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public void UpdateClient(ClientDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Îøèáêà îáíîâëåíèÿ êëèåíòà");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteClient(ClientDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Îøèáêà óäàëåíèÿ êëèåíòà");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
113
CarShowroom/CarShowroomRestApi/Controllers/EmployeeController.cs
Normal file
113
CarShowroom/CarShowroomRestApi/Controllers/EmployeeController.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CarShowroomRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class EmployeeController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IEmployeeLogic _logic;
|
||||
|
||||
public EmployeeController(ILogger<EmployeeController> logger, IEmployeeLogic employee)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = employee;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<EmployeeView>? GetEmployeeList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка сотрудников");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public EmployeeView? GetEmployee(int EmployeeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new EmployeeSearch
|
||||
{
|
||||
Id = EmployeeId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения сотрудника по Id={Id}", EmployeeId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public EmployeeView? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new EmployeeSearch
|
||||
{
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateEmployee(EmployeeDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания сотрудника");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public void UpdateEmployee(EmployeeDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления сотрудника");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteEmployee(EmployeeDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления сотрудника");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
95
CarShowroom/CarShowroomRestApi/Controllers/MakeController.cs
Normal file
95
CarShowroom/CarShowroomRestApi/Controllers/MakeController.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CarShowroomRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class MakeController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMakeLogic _logic;
|
||||
|
||||
public MakeController(ILogger<MakeController> logger, IMakeLogic make)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = make;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<MakeView>? GetMakeList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка марок");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public MakeView? GetMake(int MakeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new MakeSearch
|
||||
{
|
||||
Id = MakeId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения марки по Id={Id}", MakeId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateMake(MakeDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания марки");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public void UpdateMake(MakeDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления марки");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteMake(MakeDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления марки");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CarShowroomRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ModelController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IModelLogic _logic;
|
||||
|
||||
public ModelController(ILogger<ModelController> logger, IModelLogic model)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = model;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ModelView>? GetModelList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка моделей");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ModelView? GetModel(int ModelId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ModelSearch
|
||||
{
|
||||
Id = ModelId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения модели по Id={Id}", ModelId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateModel(ModelDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания модели");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public void UpdateModel(ModelDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления модели");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteModel(ModelDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления модели");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
95
CarShowroom/CarShowroomRestApi/Controllers/SaleController.cs
Normal file
95
CarShowroom/CarShowroomRestApi/Controllers/SaleController.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CarShowroomRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class SaleController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISaleLogic _logic;
|
||||
|
||||
public SaleController(ILogger<SaleController> logger, ISaleLogic sale)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = sale;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<SaleView>? GetSaleList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка продаж");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public SaleView? GetSale(int SaleId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new SaleSearch
|
||||
{
|
||||
Id = SaleId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения продажи по Id={Id}", SaleId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateSale(SaleDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания продажи");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public void UpdateSale(SaleDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления продажи");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteSale(SaleDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления продажи");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CarShowroomRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ServiceController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IServiceLogic _logic;
|
||||
|
||||
public ServiceController(ILogger<ServiceController> logger, IServiceLogic service)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = service;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ServiceView>? GetServiceList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка услуг");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ServiceView? GetService(int ServiceId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ServiceSearch
|
||||
{
|
||||
Id = ServiceId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения услуги по Id={Id}", ServiceId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateService(ServiceDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания услуги");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public void UpdateService(ServiceDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления услуги");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteService(ServiceDto model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления услуги");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
47
CarShowroom/CarShowroomRestApi/Program.cs
Normal file
47
CarShowroom/CarShowroomRestApi/Program.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using CarShowroomBusinessLogic.BusinessLogic;
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomContracts.StorageContracts;
|
||||
using CarShowroomDatabaseStorage.Storages;
|
||||
using Microsoft.OpenApi.Models;
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||
// Add services to the container.
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IEmployeeStorage, EmployeeStorage>();
|
||||
builder.Services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
||||
builder.Services.AddTransient<IMakeStorage, MakeStorage>();
|
||||
builder.Services.AddTransient<IMakeLogic, MakeLogic>();
|
||||
builder.Services.AddTransient<IModelStorage, ModelStorage>();
|
||||
builder.Services.AddTransient<IModelLogic, ModelLogic>();
|
||||
builder.Services.AddTransient<ICarStorage, CarStorage>();
|
||||
builder.Services.AddTransient<ICarLogic, CarLogic>();
|
||||
builder.Services.AddTransient<ISaleStorage, SaleStorage>();
|
||||
builder.Services.AddTransient<ISaleLogic, SaleLogic>();
|
||||
builder.Services.AddTransient<IServiceStorage, ServiceStorage>();
|
||||
builder.Services.AddTransient<IServiceLogic, ServiceLogic>();
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at
|
||||
//https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Title = "CarShowroomRestApi",
|
||||
Version
|
||||
= "v1"
|
||||
});
|
||||
});
|
||||
var app = builder.Build();
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json",
|
||||
"CarShowroomRestApi v1"));
|
||||
}
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
app.Run();
|
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:56574",
|
||||
"sslPort": 44389
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"CarShowroomRestApi": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7014;http://localhost:5250",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
CarShowroom/CarShowroomRestApi/appsettings.json
Normal file
9
CarShowroom/CarShowroomRestApi/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Loading…
Reference in New Issue
Block a user