Compare commits
27 Commits
lab-4-hard
...
lab-5-hard
| Author | SHA1 | Date | |
|---|---|---|---|
| 8dc9cc8995 | |||
| 6134ab544d | |||
| f96a4906d0 | |||
| b9fbb33468 | |||
| 7d7c2bd522 | |||
| 813564aece | |||
| a21f0e3d88 | |||
| 00a8846f33 | |||
| c692f50d0d | |||
| e7dcfd6f30 | |||
| a3e1230e5c | |||
| 8f5c38d239 | |||
| dbc3fb8394 | |||
| 524bfca4d0 | |||
| 6b7212a13d | |||
| 4113d2ab9e | |||
| d295b50e32 | |||
| f9966ae73d | |||
| d84b3850d6 | |||
| 6449c0df73 | |||
| 7beb84b967 | |||
| 082111e301 | |||
| 14b48e3a30 | |||
| f649754da7 | |||
| cec7b9240e | |||
| d2f7afae63 | |||
| b7c31860e1 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -10,7 +10,7 @@
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
*.idea
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
@@ -247,9 +247,9 @@ orleans.codegen.cs
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_ingredients
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
#bower_ingredients/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
@@ -414,3 +414,4 @@ FodyWeavers.xsd
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
/.idea/
|
||||
|
||||
@@ -5,15 +5,18 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="CandyHouseTests" />
|
||||
<InternalsVisibleTo Include="CandyHouseWebApi" />
|
||||
<InternalsVisibleTo Include="CandyHouseWebApi"/>
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CandyHouseContracts\CandyHouseContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
using CandyHouseContracts.BuisnessLogicContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
public class ClientBusinessLogicContract(IClientStorageContract clientStorageContract, ILogger logger) : IClientBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IClientStorageContract _clientStorageContract = clientStorageContract;
|
||||
|
||||
public List<ClientDataModel> GetAllClients()
|
||||
{
|
||||
_logger.LogInformation("GetAllClients");
|
||||
return _clientStorageContract.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public ClientDataModel GetClientByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _clientStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
if (Regex.IsMatch(data, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||
{
|
||||
return _clientStorageContract.GetElementByPhoneNumber(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _clientStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertClient(ClientDataModel clientDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(clientDataModel));
|
||||
ArgumentNullException.ThrowIfNull(clientDataModel);
|
||||
clientDataModel.Validate();
|
||||
_clientStorageContract.AddElement(clientDataModel);
|
||||
}
|
||||
|
||||
public void UpdateClient(ClientDataModel clientDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(clientDataModel));
|
||||
ArgumentNullException.ThrowIfNull(clientDataModel);
|
||||
clientDataModel.Validate();
|
||||
_clientStorageContract.UpdElement(clientDataModel);
|
||||
}
|
||||
|
||||
public void DeleteClient(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_clientStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
internal class CustomerBusinessLogicContract(ICustomerStorageContract customerStorage, ILogger<CustomerBusinessLogicContract> logger) : ICustomerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger<CustomerBusinessLogicContract> _logger = logger;
|
||||
private readonly ICustomerStorageContract _customerStorage = customerStorage;
|
||||
|
||||
public List<CustomerDataModel> GetAllCustomers()
|
||||
{
|
||||
_logger.LogInformation("Fetching all customers");
|
||||
return _customerStorage.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public CustomerDataModel GetCustomerByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Fetching customer by data={data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
CustomerDataModel? result;
|
||||
if (data.IsGuid())
|
||||
{
|
||||
result = _customerStorage.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
else if (data.StartsWith("+7"))
|
||||
{
|
||||
result = _customerStorage.GetElementByPhone(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
else if (data.Contains("@"))
|
||||
{
|
||||
result = _customerStorage.GetElementByEmail(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = _customerStorage.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void InsertCustomer(CustomerDataModel customerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Inserting customer: {json}", JsonSerializer.Serialize(customerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(customerDataModel);
|
||||
customerDataModel.Validate();
|
||||
_customerStorage.AddElement(customerDataModel);
|
||||
}
|
||||
|
||||
public void UpdateCustomer(CustomerDataModel customerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Updating customer: {json}", JsonSerializer.Serialize(customerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(customerDataModel);
|
||||
customerDataModel.Validate();
|
||||
_customerStorage.UpdateElement(customerDataModel);
|
||||
}
|
||||
|
||||
public void DeleteCustomer(string id)
|
||||
{
|
||||
_logger.LogInformation("Deleting customer with id={id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_customerStorage.DeleteElement(id);
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
using CandyHouseContracts.BuisnessLogicContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStorageContract, ILogger logger) : IEmployeeBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IEmployeeStorageContract _employeeStorageContract = employeeStorageContract;
|
||||
|
||||
public List<EmployeeDataModel> GetAllEmployees(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllEmployees params: {onlyActive}", onlyActive);
|
||||
return _employeeStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<EmployeeDataModel> GetAllEmployeesByPost(string postId, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllEmployees params: {postId}, {onlyActive},", postId, onlyActive);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _employeeStorageContract.GetList(onlyActive, postId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<EmployeeDataModel> GetAllEmployeesByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllEmployees params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _employeeStorageContract.GetList(onlyActive, fromBirthDate: fromDate, toBirthDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<EmployeeDataModel> GetAllEmployeesByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllEmployees params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _employeeStorageContract.GetList(onlyActive, fromEmploymentDate: fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public EmployeeDataModel GetEmployeeByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _employeeStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
if (Regex.IsMatch(data, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
||||
{
|
||||
return _employeeStorageContract.GetElementByEmail(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _employeeStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertEmployee(EmployeeDataModel employeeDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(employeeDataModel));
|
||||
ArgumentNullException.ThrowIfNull(employeeDataModel);
|
||||
employeeDataModel.Validate();
|
||||
_employeeStorageContract.AddElement(employeeDataModel);
|
||||
}
|
||||
|
||||
public void UpdateEmployee(EmployeeDataModel employeeDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(employeeDataModel));
|
||||
ArgumentNullException.ThrowIfNull(employeeDataModel);
|
||||
employeeDataModel.Validate();
|
||||
_employeeStorageContract.UpdElement(employeeDataModel);
|
||||
}
|
||||
|
||||
public void DeleteEmployee(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_employeeStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
internal class IngredientBusinessLogicContract(IIngredientStorageContract ingredientStorage, ILogger<IngredientBusinessLogicContract> logger) : IIngredientBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger<IngredientBusinessLogicContract> _logger = logger;
|
||||
private readonly IIngredientStorageContract _ingredientStorage = ingredientStorage;
|
||||
|
||||
public List<IngredientDataModel> GetAllIngredients(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllIngredients params: {onlyActive}", onlyActive);
|
||||
return _ingredientStorage.GetList(onlyActive, null) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<IngredientDataModel> GetAllIngredientsByManufacturer(string manufacturerId, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllIngredients params: {manufacturerId}, {onlyActive}", manufacturerId, onlyActive);
|
||||
if (manufacturerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(manufacturerId));
|
||||
}
|
||||
if (!manufacturerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field manufacturerId is not a unique identifier.");
|
||||
}
|
||||
return _ingredientStorage.GetList(onlyActive, manufacturerId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<IngredientHistoryDataModel> GetIngredientHistory(string ingredientId)
|
||||
{
|
||||
_logger.LogInformation("GetIngredientHistory for {ingredientId}", ingredientId);
|
||||
if (ingredientId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(ingredientId));
|
||||
}
|
||||
if (!ingredientId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field ingredientId is not a unique identifier.");
|
||||
}
|
||||
return _ingredientStorage.GetHistoryByIngredientId(ingredientId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public IngredientDataModel GetIngredientByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
IngredientDataModel? result;
|
||||
if (data.IsGuid())
|
||||
{
|
||||
result = _ingredientStorage.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = _ingredientStorage.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void InsertIngredient(IngredientDataModel ingredientDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(ingredientDataModel));
|
||||
ArgumentNullException.ThrowIfNull(ingredientDataModel);
|
||||
ingredientDataModel.Validate();
|
||||
_ingredientStorage.AddElement(ingredientDataModel);
|
||||
}
|
||||
|
||||
public void UpdateIngredient(IngredientDataModel ingredientDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(ingredientDataModel));
|
||||
ArgumentNullException.ThrowIfNull(ingredientDataModel);
|
||||
ingredientDataModel.Validate();
|
||||
_ingredientStorage.UpdateElement(ingredientDataModel);
|
||||
}
|
||||
|
||||
public void DeleteIngredient(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_ingredientStorage.DeleteElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
internal class ManufacturerBusinessLogicContract(IManufacturerStorageContract manufacturerStorage, ILogger<ManufacturerBusinessLogicContract> logger) : IManufacturerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger<ManufacturerBusinessLogicContract> _logger = logger;
|
||||
private readonly IManufacturerStorageContract _manufacturerStorage = manufacturerStorage;
|
||||
|
||||
public List<ManufacturerDataModel> GetAllManufacturers()
|
||||
{
|
||||
_logger.LogInformation("GetAllManufacturers");
|
||||
return _manufacturerStorage.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public ManufacturerDataModel GetManufacturerByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _manufacturerStorage.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
// Сначала ищем по ManufacturerName
|
||||
var manufacturer = _manufacturerStorage.GetElementByName(data);
|
||||
if (manufacturer != null)
|
||||
{
|
||||
return manufacturer;
|
||||
}
|
||||
|
||||
// Если не нашли по ManufacturerName, ищем по PrevManufacturerName
|
||||
manufacturer = _manufacturerStorage.GetList()
|
||||
.FirstOrDefault(m => m.PrevManufacturerName != null && m.PrevManufacturerName.Equals(data, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
return manufacturer ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertManufacturer(ManufacturerDataModel manufacturerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(manufacturerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(manufacturerDataModel);
|
||||
manufacturerDataModel.Validate();
|
||||
_manufacturerStorage.AddElement(manufacturerDataModel);
|
||||
}
|
||||
|
||||
public void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(manufacturerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(manufacturerDataModel);
|
||||
manufacturerDataModel.Validate();
|
||||
_manufacturerStorage.UpdateElement(manufacturerDataModel);
|
||||
}
|
||||
|
||||
public void DeleteManufacturer(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_manufacturerStorage.DeleteElement(id);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,18 @@
|
||||
using CandyHouseContracts.BuisnessLogicContracts;
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
public class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
|
||||
public List<PostDataModel> GetAllPosts()
|
||||
{
|
||||
_logger.LogInformation("GetAllPosts");
|
||||
@@ -33,7 +30,20 @@ public class PostBusinessLogicContract(IPostStorageContract postStorageContract,
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _postStorageContract.GetPostWithHistory(postId) ?? throw new NullListException();
|
||||
return _postStorageContract.GetPostHistory(postId) ?? throw new NullListException();
|
||||
}
|
||||
public List<PostDataModel> GetPostHistory(string postId)
|
||||
{
|
||||
_logger.LogInformation("GetPostHistory for {postId}", postId);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _postStorageContract.GetPostHistory(postId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public PostDataModel GetPostByData(string data)
|
||||
@@ -63,7 +73,7 @@ public class PostBusinessLogicContract(IPostStorageContract postStorageContract,
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
_postStorageContract.UpdElement(postDataModel);
|
||||
_postStorageContract.UpdateElement(postDataModel);
|
||||
}
|
||||
|
||||
public void DeletePost(string id)
|
||||
@@ -77,7 +87,7 @@ public class PostBusinessLogicContract(IPostStorageContract postStorageContract,
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_postStorageContract.DelElement(id);
|
||||
_postStorageContract.DeleteElement(id);
|
||||
}
|
||||
|
||||
public void RestorePost(string id)
|
||||
@@ -93,4 +103,4 @@ public class PostBusinessLogicContract(IPostStorageContract postStorageContract,
|
||||
}
|
||||
_postStorageContract.ResElement(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,75 +1,36 @@
|
||||
using CandyHouseContracts.BuisnessLogicContracts;
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
public class ProductBusinessLogicContract(IProductStorageContract productStorageContract, ILogger logger) : IProductBusinessLogicContract
|
||||
/// <summary>
|
||||
/// Реализация бизнес-логики
|
||||
/// </summary>
|
||||
internal class ProductBusinessLogicContract : IProductBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IProductStorageContract _productStorageContract = productStorageContract;
|
||||
public List<ProductDataModel> GetAllProducts()
|
||||
private readonly ILogger<ProductBusinessLogicContract> _logger;
|
||||
private readonly IProductStorageContract _productStorageContract;
|
||||
|
||||
public ProductBusinessLogicContract(IProductStorageContract productStorage, ILogger<ProductBusinessLogicContract> logger)
|
||||
{
|
||||
_logger.LogInformation("GetAllProducts");
|
||||
return _productStorageContract.GetList() ?? throw new NullListException();
|
||||
_logger = logger;
|
||||
_productStorageContract = productStorage;
|
||||
}
|
||||
|
||||
public List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId)
|
||||
public List<ProductDataModel> GetAllProducts(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetProductHistoryByProduct for {productId}", productId);
|
||||
if (productId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(productId));
|
||||
}
|
||||
if (!productId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field productId is not a unique identifier.");
|
||||
}
|
||||
return _productStorageContract.GetHistoryByProductId(productId) ?? throw new NullListException();
|
||||
_logger.LogInformation("Fetching all products with onlyActive={onlyActive}", onlyActive);
|
||||
return _productStorageContract.GetList(onlyActive: onlyActive) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public ProductDataModel GetProductByData(string data)
|
||||
public ProductDataModel GetProductById(string id)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _productStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _productStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertProduct(ProductDataModel productDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(productDataModel));
|
||||
ArgumentNullException.ThrowIfNull(productDataModel);
|
||||
productDataModel.Validate();
|
||||
_productStorageContract.AddElement(productDataModel);
|
||||
}
|
||||
|
||||
public void UpdateProduct(ProductDataModel productDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(productDataModel));
|
||||
ArgumentNullException.ThrowIfNull(productDataModel);
|
||||
productDataModel.Validate();
|
||||
_productStorageContract.UpdElement(productDataModel);
|
||||
}
|
||||
|
||||
public void DeleteProduct(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
_logger.LogInformation("Fetching sale product by id={id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
@@ -78,6 +39,68 @@ public class ProductBusinessLogicContract(IProductStorageContract productStorage
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_productStorageContract.DelElement(id);
|
||||
return _productStorageContract.GetElementById(id) ?? throw new ElementNotFoundException(id);
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertProduct(ProductDataModel productDataModel)
|
||||
{
|
||||
_logger.LogInformation("Inserting sale product: {json}", JsonSerializer.Serialize(productDataModel));
|
||||
ArgumentNullException.ThrowIfNull(productDataModel);
|
||||
productDataModel.Validate();
|
||||
_productStorageContract.AddElement(productDataModel);
|
||||
}
|
||||
|
||||
public void UpdateProduct(ProductDataModel productDataModel)
|
||||
{
|
||||
_logger.LogInformation("Updating sale product: {json}", JsonSerializer.Serialize(productDataModel));
|
||||
ArgumentNullException.ThrowIfNull(productDataModel);
|
||||
productDataModel.Validate();
|
||||
_productStorageContract.UpdateElement(productDataModel);
|
||||
}
|
||||
|
||||
public void DeleteProduct(string id)
|
||||
{
|
||||
_logger.LogInformation("Deleting sale product with id={id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_productStorageContract.DeleteElement(id);
|
||||
}
|
||||
|
||||
public List<ProductIngredientDataModel> GetIngredientsByProductId(string productId)
|
||||
{
|
||||
_logger.LogInformation("Fetching ingredients for sale product with id={saleProductId}", productId);
|
||||
if (productId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(productId));
|
||||
}
|
||||
if (!productId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("SaleProductId is not a unique identifier");
|
||||
}
|
||||
return _productStorageContract.GetIngredientsByProductId(productId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public void AddIngredientToProduct(ProductIngredientDataModel productIngredient)
|
||||
{
|
||||
_logger.LogInformation("Adding ingredient to product: {json}", JsonSerializer.Serialize(productIngredient));
|
||||
ArgumentNullException.ThrowIfNull(productIngredient);
|
||||
productIngredient.Validate();
|
||||
_productStorageContract.AddIngredientToProduct(productIngredient);
|
||||
}
|
||||
|
||||
public void RemoveIngredientFromProduct(string ingredientId, string productId)
|
||||
{
|
||||
_logger.LogInformation("Removing ingredient {ingredientId} from product {productId}", ingredientId, productId);
|
||||
if (ingredientId.IsEmpty() || productId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException("IngredientId or ProductId cannot be null or empty");
|
||||
}
|
||||
_productStorageContract.RemoveIngredientFromProduct(ingredientId, productId);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +1,140 @@
|
||||
using CandyHouseContracts.BuisnessLogicContracts;
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.Infrastructure.PostConfigurations;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
public class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,ISaleStorageContract saleStorageContract,
|
||||
IPostStorageContract postStorageContract, IEmployeeStorageContract employeeStorageContract, ILogger logger) : ISalaryBusinessLogicContract
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract, ISaleStorageContract saleStorageContract, IPostStorageContract postStorageContract, IWorkerStorageContract workerStorageContract, ILogger logger, IConfigurationSalary сonfiguration) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
private readonly IEmployeeStorageContract _employeeStorageContract = employeeStorageContract;
|
||||
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
|
||||
private readonly IConfigurationSalary _salaryConfiguration = сonfiguration;
|
||||
private readonly object _lockObject = new();
|
||||
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}",
|
||||
fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _salaryStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
return _salaryStorageContract.GetList(fromDate, toDate) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriodByEmployee(DateTime fromDate, DateTime toDate, string employeeId)
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId)
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (employeeId.IsEmpty())
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(employeeId));
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!employeeId.IsGuid())
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field employeeId is not a unique identifier.");
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, {employeeId}", fromDate, toDate, employeeId);
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, employeeId) ?? throw new NullListException();
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, {workerId}", fromDate, toDate, workerId);
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, workerId) ??
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
public void CalculateSalaryByMounth(DateTime date)
|
||||
public void CalculateSalaryByMonth(DateTime date)
|
||||
{
|
||||
_logger.LogInformation("CalculateSalaryByMounth: {date}", date);
|
||||
var startDate = new DateTime(date.Year, date.Month, 1);
|
||||
var finishDate = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
|
||||
var employees = _employeeStorageContract.GetList() ?? throw new NullListException();
|
||||
foreach (var employee in employees)
|
||||
var workers = _workerStorageContract.GetList() ?? throw new NullListException();
|
||||
foreach (var worker in workers)
|
||||
{
|
||||
var sales = _saleStorageContract.GetList(startDate, finishDate, employeeId: employee.Id)?.Sum(x => x.Sum) ??
|
||||
throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(employee.PostId) ??
|
||||
throw new NullListException();
|
||||
var salary = post.Salary + sales * 0.1;
|
||||
_logger.LogDebug("The employee {employeeId} was paid a salary of {salary}", employee.Id, salary);
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(employee.Id, DateTime.SpecifyKind(finishDate, DateTimeKind.Utc), salary));
|
||||
var sales = _saleStorageContract.GetList(startDate, finishDate, workerId: worker.Id) ?? throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(worker.PostId) ?? throw new NullListException();
|
||||
var salary = post.ConfigurationModel switch
|
||||
{
|
||||
null => 0,
|
||||
CashierPostConfiguration cpc => CalculateSalaryForCashier(sales, startDate, finishDate, cpc),
|
||||
SupervisorPostConfiguration spc => CalculateSalaryForSupervisor(startDate, finishDate, spc),
|
||||
PostConfiguration pc => pc.Rate,
|
||||
};
|
||||
_logger.LogDebug("The employee {workerId} was paid a salary of {salary}", worker.Id, salary);
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double CalculateSalaryForCashier(List<SaleDataModel> sales, DateTime startDate, DateTime finishDate, CashierPostConfiguration config)
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
var calcPercent = 0.0;
|
||||
var semaphore = new SemaphoreSlim(_salaryConfiguration.MaxConcurrentThreads); // Ограничение потоков
|
||||
|
||||
// Создаём задачи для каждого дня
|
||||
for (var date = startDate; date <= finishDate; date = date.AddDays(1))
|
||||
{
|
||||
var currentDate = date; // Сохраняем дату для каждой задачи
|
||||
tasks.Add(Task.Run(async () =>
|
||||
{
|
||||
await semaphore.WaitAsync(); // Ждём доступный слот
|
||||
try
|
||||
{
|
||||
var salesInDay = sales.Where(x => x.SaleDate.Date == currentDate.Date && !x.IsCancel).ToArray();
|
||||
if (salesInDay.Length > 0)
|
||||
{
|
||||
lock (_lockObject)
|
||||
{
|
||||
calcPercent += (salesInDay.Sum(x => x.Sum) / salesInDay.Length) * _salaryConfiguration.CashierSalePercent;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release(); // Освобождаем слот
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// Расчёт бонуса в отдельной задаче
|
||||
var calcBonusTask = Task.Run(() =>
|
||||
{
|
||||
return sales.Where(x => x.Sum > _salaryConfiguration.ExtraSaleSum && !x.IsCancel)
|
||||
.Sum(x => x.Sum) * _salaryConfiguration.CashierBonusForExtraSales;
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
Task.WaitAll(tasks.ToArray()); // Ждём завершения всех задач для процентов
|
||||
var bonus = calcBonusTask.Result; // Получаем результат бонуса
|
||||
return config.Rate + calcPercent + bonus;
|
||||
}
|
||||
catch (AggregateException agEx)
|
||||
{
|
||||
foreach (var ex in agEx.InnerExceptions)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the cashier payroll process");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private double CalculateSalaryForSupervisor(DateTime startDate, DateTime finishDate, SupervisorPostConfiguration config)
|
||||
{
|
||||
try
|
||||
{
|
||||
return config.Rate + _salaryConfiguration.SupervisorTrendPremium * _workerStorageContract.GetWorkerTrend(startDate, finishDate); // Из глобальных настроек
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the supervisor payroll process");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +1,66 @@
|
||||
using CandyHouseContracts.BuisnessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,IStorageStorageContract storageStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, IStorageContract storageStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
||||
private readonly IStorageStorageContract _storageStorageContract = storageStorageContract;
|
||||
private readonly IStorageContract _storageStorageContract = storageStorageContract;
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSales params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
_logger.LogInformation("GetAllSales params: {fromDate}, {toDate}",
|
||||
fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _saleStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
return _saleStorageContract.GetList(fromDate, toDate) ?? throw new
|
||||
NullListException();
|
||||
}
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByEmployeeByPeriod(string employeeId, DateTime fromDate, DateTime toDate)
|
||||
public List<SaleDataModel> GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSales params: {employeeId}, {fromDate}, {toDate}", employeeId, fromDate, toDate);
|
||||
_logger.LogInformation("GetAllSales params: {workerId}, {fromDate}, {toDate}", workerId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (employeeId.IsEmpty())
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(employeeId));
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!employeeId.IsGuid())
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field employeeId is not a unique identifier.");
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
return _saleStorageContract.GetList(fromDate, toDate, employeeId: employeeId) ?? throw new NullListException();
|
||||
return _saleStorageContract.GetList(fromDate, toDate, workerId:
|
||||
workerId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByClientByPeriod(string clientId, DateTime fromDate, DateTime toDate)
|
||||
public List<SaleDataModel> GetAllSalesByCustomerByPeriod(string customerId,
|
||||
DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSales params: {buyerId}, {fromDate}, {toDate}", clientId, fromDate, toDate);
|
||||
_logger.LogInformation("GetAllSales params: {customerId}, {fromDate}, {toDate}", customerId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (clientId.IsEmpty())
|
||||
if (customerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(clientId));
|
||||
throw new ArgumentNullException(nameof(customerId));
|
||||
}
|
||||
if (!clientId.IsGuid())
|
||||
if (!customerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field clientId is not a unique identifier.");
|
||||
throw new ValidationException("The value in the field customerId is not a unique identifier.");
|
||||
}
|
||||
return _saleStorageContract.GetList(fromDate, toDate, clientId: clientId) ?? throw new NullListException();
|
||||
return _saleStorageContract.GetList(fromDate, toDate, customerId:
|
||||
customerId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate)
|
||||
@@ -94,18 +92,22 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
return _saleStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
return _saleStorageContract.GetElementById(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertSale(SaleDataModel saleDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(saleDataModel));
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(saleDataModel));
|
||||
ArgumentNullException.ThrowIfNull(saleDataModel);
|
||||
saleDataModel.Validate();
|
||||
if (!_storageStorageContract.CheckComponents(saleDataModel))
|
||||
|
||||
if (!_storageStorageContract.CheckAndWriteOffСomponentsFromStorage(saleDataModel))
|
||||
{
|
||||
throw new InsufficientException("Dont have product in storage");
|
||||
throw new InsufficientStockException();
|
||||
}
|
||||
|
||||
_saleStorageContract.AddElement(saleDataModel);
|
||||
}
|
||||
|
||||
@@ -122,4 +124,46 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
}
|
||||
_saleStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
|
||||
public double CalculateSalesRevenue(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
if (fromDate > toDate)
|
||||
throw new ValidationException("fromDate cannot be later than toDate");
|
||||
|
||||
_logger.LogInformation("Calculating sales revenue from {fromDate} to {toDate}", fromDate, toDate);
|
||||
|
||||
var sales = GetAllSalesByPeriod(fromDate, toDate);
|
||||
if (sales == null || !sales.Any())
|
||||
{
|
||||
_logger.LogWarning("No sales found for the period {fromDate} to {toDate}", fromDate, toDate);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double totalRevenue = 0.0;
|
||||
object lockObject = new object();
|
||||
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
|
||||
|
||||
try
|
||||
{
|
||||
Parallel.ForEach(sales, parallelOptions, sale =>
|
||||
{
|
||||
if (!sale.IsCancel)
|
||||
{
|
||||
double saleRevenue = sale.Sum - sale.Discount;
|
||||
lock (lockObject)
|
||||
{
|
||||
totalRevenue += saleRevenue;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (AggregateException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error occurred while calculating sales revenue");
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Total sales revenue: {totalRevenue}", totalRevenue);
|
||||
return totalRevenue;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,182 @@
|
||||
using CandyHouseContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
public class StorageBusinessLogicContract(IStorageStorageContract storageStorageContract, ILogger logger) : IStorageBusinessLogicContract
|
||||
public class StorageBusinessLogicContract : IStorageBusinessLogicContract
|
||||
{
|
||||
private readonly IStorageStorageContract _storageStorageContract = storageStorageContract;
|
||||
private readonly ILogger _logger = logger;
|
||||
public List<StorageDataModel> GetAllComponents()
|
||||
{
|
||||
_logger.LogInformation("GetAllComponents");
|
||||
return _storageStorageContract.GetList() ?? throw new NullListException();
|
||||
private readonly IStorageContract _storageContract;
|
||||
private readonly ISupplyStorageContract _supplyStorageContract;
|
||||
private readonly ILogger<StorageBusinessLogicContract> _logger;
|
||||
|
||||
return [];
|
||||
public StorageBusinessLogicContract(IStorageContract storageContract, ISupplyStorageContract supplyStorageContract, ILogger<StorageBusinessLogicContract> logger)
|
||||
{
|
||||
_storageContract = storageContract ?? throw new ArgumentNullException(nameof(storageContract));
|
||||
_supplyStorageContract = supplyStorageContract ?? throw new ArgumentNullException(nameof(supplyStorageContract));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public StorageDataModel GetComponentByData(string data)
|
||||
public List<StorageDataModel> GetAllStorages()
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
var storages = _storageContract.GetAllStorages();
|
||||
if (storages == null || !storages.Any()) // Добавляем проверку на пустой список
|
||||
throw new NullListException("No storages found");
|
||||
return storages;
|
||||
}
|
||||
|
||||
public void CreateStorage(string id, string address, int count, List<StorageIngredientDataModel> ingredients)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(address))
|
||||
throw new ValidationException("Id and Address must not be empty");
|
||||
|
||||
var storage = new StorageDataModel(id, address, count, ingredients ?? new List<StorageIngredientDataModel>());
|
||||
storage.Validate();
|
||||
_storageContract.AddStorage(storage);
|
||||
}
|
||||
|
||||
public void UpdateStorage(StorageDataModel storage)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(storage));
|
||||
ArgumentNullException.ThrowIfNull(storage);
|
||||
storage.Validate();
|
||||
var existingStorage = _storageContract.GetStorageById(storage.Id);
|
||||
if (existingStorage == null)
|
||||
throw new ElementNotFoundException($"Storage with ID {storage.Id} not found");
|
||||
|
||||
_storageContract.UpdateStorage(storage);
|
||||
}
|
||||
|
||||
public void AddIngredientToStorage(string storageId, StorageIngredientDataModel ingredient)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageId) || ingredient == null)
|
||||
throw new ValidationException("StorageId and ingredient must not be null or empty");
|
||||
|
||||
var storage = _storageContract.GetStorageById(storageId);
|
||||
if (storage == null)
|
||||
throw new ValidationException($"Storage with ID {storageId} not found");
|
||||
|
||||
ingredient.Validate();
|
||||
var existingIngredient = _storageContract.GetIngredientOnStorage(storageId, ingredient.IngredientId);
|
||||
var updatedCount = existingIngredient?.Count + ingredient.Count ?? ingredient.Count;
|
||||
var updatedIngredient = new StorageIngredientDataModel(storageId, ingredient.IngredientId, updatedCount);
|
||||
_storageContract.AddOrUpdateIngredientOnStorage(updatedIngredient);
|
||||
}
|
||||
|
||||
public void UpdateIngredientCount(string storageId, string ingredientId, int newCount)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageId) || string.IsNullOrEmpty(ingredientId) || newCount < 0)
|
||||
throw new ValidationException("Invalid parameters for updating ingredient count");
|
||||
|
||||
var storage = _storageContract.GetStorageById(storageId);
|
||||
if (storage == null)
|
||||
throw new ValidationException($"Storage with ID {storageId} not found");
|
||||
|
||||
_storageContract.UpdateIngredientCount(storageId, ingredientId, newCount);
|
||||
}
|
||||
|
||||
public int GetIngredientCountFromStorage(string storageId, string ingredientId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageId) || string.IsNullOrEmpty(ingredientId))
|
||||
throw new ValidationException("StorageId and IngredientId must not be empty");
|
||||
|
||||
var ingredient = _storageContract.GetIngredientOnStorage(storageId, ingredientId);
|
||||
if (ingredient == null)
|
||||
throw new ValidationException($"Ingredient with ID {ingredientId} not found in storage {storageId}");
|
||||
|
||||
return ingredient.Count;
|
||||
}
|
||||
|
||||
public List<StorageIngredientDataModel> GetIngredientsFromStorage(string storageId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageId))
|
||||
throw new ValidationException("StorageId must not be empty");
|
||||
|
||||
var storage = _storageContract.GetStorageById(storageId);
|
||||
if (storage == null)
|
||||
throw new ValidationException($"Storage with ID {storageId} not found");
|
||||
|
||||
return _storageContract.GetIngredientsOnStorage(storageId);
|
||||
}
|
||||
|
||||
public StorageDataModel GetStorageById(string storageId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageId))
|
||||
throw new ValidationException("StorageId must not be empty");
|
||||
|
||||
var storage = _storageContract.GetStorageById(storageId);
|
||||
if (storage == null)
|
||||
throw new ValidationException($"Storage with ID {storageId} not found");
|
||||
|
||||
return storage;
|
||||
}
|
||||
|
||||
public Dictionary<string, int> CalculateRemainingIngredients(string storageId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageId))
|
||||
throw new ValidationException("StorageId must not be empty");
|
||||
|
||||
var storage = _storageContract.GetStorageById(storageId);
|
||||
if (storage == null)
|
||||
throw new ValidationException($"Storage with ID {storageId} not found");
|
||||
|
||||
_logger.LogInformation("Calculating remaining ingredients for storage {storageId}", storageId);
|
||||
|
||||
var remainingIngredients = new Dictionary<string, int>();
|
||||
|
||||
try
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
var supplyTask = Task.Run(() =>
|
||||
{
|
||||
var supplies = _supplyStorageContract.GetSuppliesByStorageId(storageId);
|
||||
var suppliedIngredients = new Dictionary<string, int>();
|
||||
foreach (var supply in supplies)
|
||||
{
|
||||
if (supply.Ingredients != null)
|
||||
{
|
||||
foreach (var ingredient in supply.Ingredients)
|
||||
{
|
||||
if (suppliedIngredients.ContainsKey(ingredient.IngredientId))
|
||||
suppliedIngredients[ingredient.IngredientId] += ingredient.Count;
|
||||
else
|
||||
suppliedIngredients[ingredient.IngredientId] = ingredient.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
return suppliedIngredients;
|
||||
});
|
||||
|
||||
var writeOffTask = Task.Run(() =>
|
||||
{
|
||||
return _storageContract.GetWrittenOffIngredientsByStorageId(storageId);
|
||||
});
|
||||
|
||||
Task.WhenAll(supplyTask, writeOffTask).GetAwaiter().GetResult();
|
||||
|
||||
var suppliedIngredients = supplyTask.Result;
|
||||
var writtenOffIngredients = writeOffTask.Result;
|
||||
|
||||
foreach (var ingredient in suppliedIngredients)
|
||||
{
|
||||
int writtenOffCount = writtenOffIngredients.ContainsKey(ingredient.Key) ? writtenOffIngredients[ingredient.Key] : 0;
|
||||
int remainingCount = ingredient.Value - writtenOffCount;
|
||||
if (remainingCount > 0)
|
||||
{
|
||||
remainingIngredients[ingredient.Key] = remainingCount;
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Remaining ingredients calculated for storage {storageId}: {count} ingredients", storageId, remainingIngredients.Count);
|
||||
}
|
||||
if (!data.IsGuid())
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ElementNotFoundException(data);
|
||||
_logger.LogError(ex, "Error occurred while calculating remaining ingredients for storage {storageId}", storageId);
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
return _storageStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
|
||||
return new("", ProductType.None, 0, []);
|
||||
return remainingIngredients;
|
||||
}
|
||||
|
||||
public void InsertComponent(StorageDataModel storageDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(storageDataModel));
|
||||
ArgumentNullException.ThrowIfNull(storageDataModel);
|
||||
storageDataModel.Validate();
|
||||
_storageStorageContract.AddElement(storageDataModel);
|
||||
}
|
||||
|
||||
public void UpdateComponent(StorageDataModel storageDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(storageDataModel));
|
||||
ArgumentNullException.ThrowIfNull(storageDataModel);
|
||||
storageDataModel.Validate();
|
||||
_storageStorageContract.UpdElement(storageDataModel);
|
||||
}
|
||||
|
||||
public void DeleteComponent(string id)
|
||||
{
|
||||
logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_storageStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
using CandyHouseContracts.BusinessLogicContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
public class SuppliesBusinessLogicContract(ISuppliesStorageContract suppliesStorageContract, ILogger logger) : ISuppliesBusinessLogicContract
|
||||
{
|
||||
private readonly ISuppliesStorageContract _suppliesStorageContract = suppliesStorageContract;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public List<SuppliesDataModel> GetAllComponents()
|
||||
{
|
||||
_logger.LogInformation("GetAllComponents");
|
||||
return _suppliesStorageContract.GetList() ?? throw new NullListException();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public SuppliesDataModel GetComponentByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (!data.IsGuid())
|
||||
{
|
||||
throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _suppliesStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
|
||||
return new("", ProductType.None, DateTime.UtcNow, 0, []);
|
||||
}
|
||||
|
||||
public void InsertComponent(SuppliesDataModel suppliesDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(suppliesDataModel));
|
||||
ArgumentNullException.ThrowIfNull(suppliesDataModel);
|
||||
suppliesDataModel.Validate();
|
||||
_suppliesStorageContract.AddElement(suppliesDataModel);
|
||||
}
|
||||
|
||||
public void UpdateComponent(SuppliesDataModel suppliesDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(suppliesDataModel));
|
||||
ArgumentNullException.ThrowIfNull(suppliesDataModel);
|
||||
suppliesDataModel.Validate();
|
||||
_suppliesStorageContract.UpdElement(suppliesDataModel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
public class SupplyBusinessLogicContract : ISupplyBusinessLogicContract
|
||||
{
|
||||
private readonly ISupplyStorageContract _supplyStorageContract;
|
||||
private readonly IStorageContract _storageContract;
|
||||
|
||||
public SupplyBusinessLogicContract(ISupplyStorageContract supplyStorageContract, IStorageContract storageContract)
|
||||
{
|
||||
_supplyStorageContract = supplyStorageContract ?? throw new ArgumentNullException(nameof(supplyStorageContract));
|
||||
_storageContract = storageContract ?? throw new ArgumentNullException(nameof(storageContract));
|
||||
}
|
||||
|
||||
public void CreateSupply(SupplyDataModel supply)
|
||||
{
|
||||
if (supply == null)
|
||||
throw new ValidationException("Supply cannot be null");
|
||||
|
||||
supply.Validate();
|
||||
var storage = _storageContract.GetStorageById(supply.StorageId);
|
||||
if (storage == null)
|
||||
throw new ValidationException($"Storage with ID {supply.StorageId} not found");
|
||||
|
||||
foreach (var ingredient in supply.Ingredients)
|
||||
{
|
||||
ingredient.Validate();
|
||||
}
|
||||
|
||||
_supplyStorageContract.AddSupply(supply);
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var ingredient in supply.Ingredients)
|
||||
{
|
||||
var storageIngredient = _storageContract.GetIngredientOnStorage(supply.StorageId, ingredient.IngredientId)
|
||||
?? new StorageIngredientDataModel(supply.StorageId, ingredient.IngredientId, 0);
|
||||
var updatedIngredient = new StorageIngredientDataModel(
|
||||
storageIngredient.StorageId,
|
||||
storageIngredient.IngredientId,
|
||||
storageIngredient.Count + ingredient.Count
|
||||
);
|
||||
_storageContract.AddOrUpdateIngredientOnStorage(updatedIngredient);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_supplyStorageContract.RemoveSupply(supply.Id);
|
||||
throw new ValidationException($"Failed to update storage: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public List<SupplyDataModel> GetAllSupplies()
|
||||
{
|
||||
var supplies = _supplyStorageContract.GetAllSupplies();
|
||||
if (supplies == null || !supplies.Any())
|
||||
throw new NullListException("No supplies found");
|
||||
return supplies;
|
||||
}
|
||||
|
||||
public SupplyDataModel GetSupplyById(string supplyId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(supplyId))
|
||||
throw new ValidationException("SupplyId must not be empty");
|
||||
|
||||
var supply = _supplyStorageContract.GetSupplyById(supplyId);
|
||||
if (supply == null)
|
||||
throw new ValidationException($"Supply with ID {supplyId} not found");
|
||||
|
||||
return supply;
|
||||
}
|
||||
|
||||
public List<SupplyDataModel> GetSuppliesByStorageId(string storageId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storageId))
|
||||
throw new ValidationException("StorageId must not be empty");
|
||||
|
||||
var storage = _storageContract.GetStorageById(storageId);
|
||||
if (storage == null)
|
||||
throw new ValidationException($"Storage with ID {storageId} not found");
|
||||
|
||||
return _supplyStorageContract.GetSuppliesByStorageId(storageId);
|
||||
}
|
||||
|
||||
public void AddOrUpdateIngredientInSupply(SupplyIngredientDataModel ingredient)
|
||||
{
|
||||
if (ingredient == null)
|
||||
throw new ValidationException("Ingredient cannot be null");
|
||||
|
||||
ingredient.Validate();
|
||||
_supplyStorageContract.AddOrUpdateIngredientInSupply(ingredient);
|
||||
}
|
||||
|
||||
public void UpdateIngredientCountInSupply(string supplyId, string ingredientId, int newCount)
|
||||
{
|
||||
if (string.IsNullOrEmpty(supplyId) || string.IsNullOrEmpty(ingredientId) || newCount <= 0)
|
||||
throw new ValidationException("Invalid parameters for updating ingredient count");
|
||||
|
||||
var supply = _supplyStorageContract.GetSupplyById(supplyId);
|
||||
if (supply == null)
|
||||
throw new ValidationException($"Supply with ID {supplyId} not found");
|
||||
|
||||
_supplyStorageContract.UpdateIngredientCountInSupply(supplyId, ingredientId, newCount);
|
||||
}
|
||||
|
||||
public void RemoveIngredientFromSupply(string supplyId, string ingredientId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(supplyId) || string.IsNullOrEmpty(ingredientId))
|
||||
throw new ValidationException("SupplyId and IngredientId must not be empty");
|
||||
|
||||
var supply = _supplyStorageContract.GetSupplyById(supplyId);
|
||||
if (supply == null)
|
||||
throw new ValidationException($"Supply with ID {supplyId} not found");
|
||||
|
||||
_supplyStorageContract.RemoveIngredientFromSupply(supplyId, ingredientId);
|
||||
}
|
||||
|
||||
public int CalculateSuppliedIngredientsCount(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
if (fromDate > toDate)
|
||||
throw new ValidationException("fromDate cannot be later than toDate");
|
||||
|
||||
var supplies = _supplyStorageContract.GetSuppliesByPeriod(fromDate, toDate);
|
||||
if (supplies == null || !supplies.Any())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int totalCount = 0;
|
||||
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
|
||||
|
||||
try
|
||||
{
|
||||
Parallel.ForEach(supplies, parallelOptions, supply =>
|
||||
{
|
||||
if (supply.Ingredients != null)
|
||||
{
|
||||
int supplyCount = supply.Ingredients.Sum(c => c.Count);
|
||||
Interlocked.Add(ref totalCount, supplyCount);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (AggregateException ex)
|
||||
{
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
|
||||
return totalCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using CandyHouseContracts.BusinessLogicsContracts;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract workerStorage, ILogger<WorkerBusinessLogicContract> logger) : IWorkerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger<WorkerBusinessLogicContract> _logger = logger;
|
||||
private readonly IWorkerStorageContract _workerStorage = workerStorage;
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}", onlyActive);
|
||||
return _workerStorage.GetList(onlyActive, null, null, null, null, null) ?? throw new NullListException(); // Явно указал все параметры
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {postId}, {onlyActive}", postId, onlyActive);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _workerStorage.GetList(onlyActive, postId, null, null, null, null) ?? throw new NullListException(); // Явно указал все параметры
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorage.GetList(onlyActive, null, fromDate, toDate, null, null) ?? throw new NullListException(); // Явно указал все параметры
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorage.GetList(onlyActive, null, null, null, fromDate, toDate) ?? throw new NullListException(); // Явно указал все параметры
|
||||
}
|
||||
|
||||
public WorkerDataModel GetWorkerByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _workerStorage.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _workerStorage.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorage.AddElement(workerDataModel);
|
||||
}
|
||||
|
||||
public void UpdateWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorage.UpdateElement(workerDataModel);
|
||||
}
|
||||
|
||||
public void DeleteWorker(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_workerStorage.DeleteElement(id);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IClientAdapter
|
||||
{
|
||||
ClientOperationResponse GetList();
|
||||
|
||||
ClientOperationResponse GetElement(string data);
|
||||
|
||||
ClientOperationResponse RegisterClient(ClientBindingModel clientModel);
|
||||
|
||||
ClientOperationResponse ChangeClientInfo(ClientBindingModel clientModel);
|
||||
|
||||
ClientOperationResponse RemoveClient(string id);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IIngredientAdapter
|
||||
{
|
||||
IngredientOperationResponse GetList(bool includeDeleted);
|
||||
|
||||
IngredientOperationResponse GetManufacturerList(string id, bool includeDeleted);
|
||||
|
||||
IngredientOperationResponse GetHistory(string id);
|
||||
|
||||
IngredientOperationResponse GetElement(string data);
|
||||
|
||||
IngredientOperationResponse RegisterIngredient(IngredientBindingModel productModel);
|
||||
|
||||
IngredientOperationResponse ChangeIngredientInfo(IngredientBindingModel productModel);
|
||||
|
||||
IngredientOperationResponse RemoveIngredient(string id);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface ICustomerAdapter
|
||||
{
|
||||
CustomerOperationResponse GetList();
|
||||
|
||||
CustomerOperationResponse GetElement(string data);
|
||||
|
||||
CustomerOperationResponse RegisterCustomer(CustomerBindingModel customerModel);
|
||||
|
||||
CustomerOperationResponse ChangeCustomerInfo(CustomerBindingModel customerModel);
|
||||
|
||||
CustomerOperationResponse RemoveCustomer(string id);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IEmployeeAdapter
|
||||
{
|
||||
EmployeeOperationResponse GetList(bool includeDeleted);
|
||||
|
||||
EmployeeOperationResponse GetPostList(string id, bool includeDeleted);
|
||||
|
||||
EmployeeOperationResponse GetListByBirthDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
|
||||
|
||||
EmployeeOperationResponse GetListByEmploymentDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
|
||||
|
||||
EmployeeOperationResponse GetElement(string data);
|
||||
|
||||
EmployeeOperationResponse RegisterEmployee(EmployeeBindingModel employeeModel);
|
||||
|
||||
EmployeeOperationResponse ChangeEmployeeInfo(EmployeeBindingModel employeeModel);
|
||||
|
||||
EmployeeOperationResponse RemoveEmployee(string id);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IManufacturerAdapter
|
||||
{
|
||||
ManufacturerOperationResponse GetList();
|
||||
|
||||
ManufacturerOperationResponse GetElement(string data);
|
||||
|
||||
ManufacturerOperationResponse RegisterManufacturer(ManufacturerBindingModel manufacturerModel);
|
||||
|
||||
ManufacturerOperationResponse ChangeManufacturerInfo(ManufacturerBindingModel manufacturerModel);
|
||||
|
||||
ManufacturerOperationResponse RemoveManufacturer(string id);
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
@@ -23,4 +18,4 @@ public interface IPostAdapter
|
||||
PostOperationResponse RemovePost(string id);
|
||||
|
||||
PostOperationResponse RestorePost(string id);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,12 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CandyHouseContracts.DataModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IProductAdapter
|
||||
{
|
||||
ProductOperationResponse GetList(bool includeDeleted);
|
||||
|
||||
ProductOperationResponse GetHistory(string id);
|
||||
ProductOperationResponse GetList(bool onlyActive = true);
|
||||
|
||||
ProductOperationResponse GetElement(string data);
|
||||
|
||||
@@ -21,4 +15,10 @@ public interface IProductAdapter
|
||||
ProductOperationResponse ChangeProductInfo(ProductBindingModel productModel);
|
||||
|
||||
ProductOperationResponse RemoveProduct(string id);
|
||||
}
|
||||
|
||||
ProductOperationResponse GetIngredientsList(string id);
|
||||
|
||||
ProductOperationResponse AddIngredient(string productId, IngredientBindingModel ingredient);
|
||||
|
||||
ProductOperationResponse RemoveIngredient(string productId, string ingredientId);
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface ISalaryAdapter
|
||||
{
|
||||
SalaryOperationResponse GetListByPeriod(DateTime fromDate, DateTime toDate);
|
||||
SalaryOperationResponse GetListByPeriodByEmployee(DateTime fromDate, DateTime toDate, string employeeId);
|
||||
|
||||
SalaryOperationResponse GetListByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId);
|
||||
|
||||
SalaryOperationResponse CalculateSalary(DateTime date);
|
||||
}
|
||||
@@ -1,26 +1,15 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface ISaleAdapter
|
||||
{
|
||||
SaleOperationResponse GetList(DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleOperationResponse GetEmployeeList(string id, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleOperationResponse GetClientList(string id, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleOperationResponse GetWorkerList(string id, DateTime fromDate, DateTime toDate);
|
||||
SaleOperationResponse GetCustomerList(string id, DateTime fromDate, DateTime toDate);
|
||||
SaleOperationResponse GetProductList(string id, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleOperationResponse GetElement(string id);
|
||||
|
||||
SaleOperationResponse MakeSale(SaleBindingModel saleModel);
|
||||
|
||||
SaleOperationResponse CancelSale(string id);
|
||||
}
|
||||
@@ -1,18 +1,13 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IStorageAdapter
|
||||
{
|
||||
StorageOperationResponse GetAllComponents();
|
||||
StorageOperationResponse GetComponentByData(string data);
|
||||
StorageOperationResponse InsertComponent(StorageBindingModel warehouseDataModel);
|
||||
StorageOperationResponse UpdateComponent(StorageBindingModel warehouseDataModel);
|
||||
StorageOperationResponse DeleteComponent(string id);
|
||||
}
|
||||
StorageOperationResponse GetList();
|
||||
StorageOperationResponse GetElement(string id);
|
||||
StorageOperationResponse RegisterStorage(StorageBindingModel storageModel);
|
||||
StorageOperationResponse UpdateStorage(StorageBindingModel storageModel);
|
||||
StorageOperationResponse AddOrUpdateIngredient(StorageIngredientBindingModel ingredientModel);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface ISuppliesAdapter
|
||||
{
|
||||
SuppliesOperationResponse GetAllComponents();
|
||||
SuppliesOperationResponse GetComponentByData(string data);
|
||||
SuppliesOperationResponse InsertComponent(SuppliesBindingModel componentDataModel);
|
||||
SuppliesOperationResponse UpdateComponent(SuppliesBindingModel componentDataModel);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface ISupplyAdapter
|
||||
{
|
||||
SupplyOperationResponse GetList();
|
||||
SupplyOperationResponse GetElement(string id);
|
||||
SupplyOperationResponse RegisterSupply(SupplyBindingModel supplyModel);
|
||||
SupplyOperationResponse GetSuppliesByStorage(string storageId);
|
||||
SupplyOperationResponse AddOrUpdateIngredient(SupplyIngredientBindingModel ingredientModel);
|
||||
SupplyOperationResponse UpdateIngredientCount(string supplyId, string ingredientId, int newCount);
|
||||
SupplyOperationResponse RemoveIngredient(string supplyId, string ingredientId);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IWorkerAdapter
|
||||
{
|
||||
WorkerOperationResponse GetList(bool includeDeleted);
|
||||
|
||||
WorkerOperationResponse GetPostList(string id, bool includeDeleted);
|
||||
|
||||
WorkerOperationResponse GetListByBirthDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
|
||||
|
||||
WorkerOperationResponse GetListByEmploymentDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
|
||||
|
||||
WorkerOperationResponse GetElement(string data);
|
||||
|
||||
WorkerOperationResponse RegisterWorker(WorkerBindingModel workerModel);
|
||||
|
||||
WorkerOperationResponse ChangeWorkerInfo(WorkerBindingModel workerModel);
|
||||
|
||||
WorkerOperationResponse RemoveWorker(string id);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ClientOperationResponse : OperationResponse
|
||||
{
|
||||
public static ClientOperationResponse OK(List<ClientViewModel> data) => OK<ClientOperationResponse, List<ClientViewModel>>(data);
|
||||
|
||||
public static ClientOperationResponse OK(ClientViewModel data) => OK<ClientOperationResponse, ClientViewModel>(data);
|
||||
|
||||
public static ClientOperationResponse NoContent() => NoContent<ClientOperationResponse>();
|
||||
|
||||
public static ClientOperationResponse BadRequest(string message) => BadRequest<ClientOperationResponse>(message);
|
||||
|
||||
public static ClientOperationResponse NotFound(string message) => NotFound<ClientOperationResponse>(message);
|
||||
|
||||
public static ClientOperationResponse InternalServerError(string message) => InternalServerError<ClientOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class CustomerOperationResponse : OperationResponse
|
||||
{
|
||||
public static CustomerOperationResponse OK(List<CustomerViewModel> data) => OK<CustomerOperationResponse, List<CustomerViewModel>>(data);
|
||||
|
||||
public static CustomerOperationResponse OK(CustomerViewModel data) => OK<CustomerOperationResponse, CustomerViewModel>(data);
|
||||
|
||||
public static CustomerOperationResponse NoContent() => NoContent<CustomerOperationResponse>();
|
||||
|
||||
public static CustomerOperationResponse BadRequest(string message) => BadRequest<CustomerOperationResponse>(message);
|
||||
|
||||
public static CustomerOperationResponse NotFound(string message) => NotFound<CustomerOperationResponse>(message);
|
||||
|
||||
public static CustomerOperationResponse InternalServerError(string message) => InternalServerError<CustomerOperationResponse>(message);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class EmployeeOperationResponse : OperationResponse
|
||||
{
|
||||
public static EmployeeOperationResponse OK(List<EmployeeViewModel> data) => OK<EmployeeOperationResponse, List<EmployeeViewModel>>(data);
|
||||
|
||||
public static EmployeeOperationResponse OK(EmployeeViewModel data) => OK<EmployeeOperationResponse, EmployeeViewModel>(data);
|
||||
|
||||
public static EmployeeOperationResponse NoContent() => NoContent<EmployeeOperationResponse>();
|
||||
|
||||
public static EmployeeOperationResponse NotFound(string message) => NotFound<EmployeeOperationResponse>(message);
|
||||
|
||||
public static EmployeeOperationResponse BadRequest(string message) => BadRequest<EmployeeOperationResponse>(message);
|
||||
|
||||
public static EmployeeOperationResponse InternalServerError(string message) => InternalServerError<EmployeeOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class IngredientOperationResponse : OperationResponse
|
||||
{
|
||||
public static IngredientOperationResponse OK(List<IngredientViewModel> data) => OK<IngredientOperationResponse, List<IngredientViewModel>>(data);
|
||||
|
||||
public static IngredientOperationResponse OK(List<IngredientHistoryViewModel> data) => OK<IngredientOperationResponse, List<IngredientHistoryViewModel>>(data);
|
||||
|
||||
public static IngredientOperationResponse OK(IngredientViewModel data) => OK<IngredientOperationResponse, IngredientViewModel>(data);
|
||||
|
||||
public static IngredientOperationResponse NoContent() => NoContent<IngredientOperationResponse>();
|
||||
|
||||
public static IngredientOperationResponse NotFound(string message) => NotFound<IngredientOperationResponse>(message);
|
||||
|
||||
public static IngredientOperationResponse BadRequest(string message) => BadRequest<IngredientOperationResponse>(message);
|
||||
|
||||
public static IngredientOperationResponse InternalServerError(string message) => InternalServerError<IngredientOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ManufacturerOperationResponse : OperationResponse
|
||||
{
|
||||
public static ManufacturerOperationResponse OK(List<ManufacturerViewModel> data) => OK<ManufacturerOperationResponse, List<ManufacturerViewModel>>(data);
|
||||
|
||||
public static ManufacturerOperationResponse OK(ManufacturerViewModel data) => OK<ManufacturerOperationResponse, ManufacturerViewModel>(data);
|
||||
|
||||
public static ManufacturerOperationResponse NoContent() => NoContent<ManufacturerOperationResponse>();
|
||||
|
||||
public static ManufacturerOperationResponse NotFound(string message) => NotFound<ManufacturerOperationResponse>(message);
|
||||
|
||||
public static ManufacturerOperationResponse BadRequest(string message) => BadRequest<ManufacturerOperationResponse>(message);
|
||||
|
||||
public static ManufacturerOperationResponse InternalServerError(string message) => InternalServerError<ManufacturerOperationResponse>(message);
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
@@ -21,4 +16,4 @@ public class PostOperationResponse : OperationResponse
|
||||
public static PostOperationResponse BadRequest(string message) => BadRequest<PostOperationResponse>(message);
|
||||
|
||||
public static PostOperationResponse InternalServerError(string message) => InternalServerError<PostOperationResponse>(message);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,28 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ProductOperationResponse : OperationResponse
|
||||
{
|
||||
public static ProductOperationResponse OK(List<ProductViewModel> data) => OK<ProductOperationResponse, List<ProductViewModel>>(data);
|
||||
public static ProductOperationResponse OK(List<ProductViewModel> data)
|
||||
=> OK<ProductOperationResponse, List<ProductViewModel>>(data);
|
||||
|
||||
public static ProductOperationResponse OK(List<ProductHistoryViewModel> data) => OK<ProductOperationResponse, List<ProductHistoryViewModel>>(data);
|
||||
public static ProductOperationResponse OK(List<IngredientViewModel> data)
|
||||
=> OK<ProductOperationResponse, List<IngredientViewModel>>(data);
|
||||
|
||||
public static ProductOperationResponse OK(ProductViewModel data) => OK<ProductOperationResponse, ProductViewModel>(data);
|
||||
public static ProductOperationResponse OK(ProductViewModel data)
|
||||
=> OK<ProductOperationResponse, ProductViewModel>(data);
|
||||
|
||||
public static ProductOperationResponse NoContent() => NoContent<ProductOperationResponse>();
|
||||
public static ProductOperationResponse NoContent()
|
||||
=> NoContent<ProductOperationResponse>();
|
||||
|
||||
public static ProductOperationResponse NotFound(string message) => NotFound<ProductOperationResponse>(message);
|
||||
public static ProductOperationResponse NotFound(string message)
|
||||
=> NotFound<ProductOperationResponse>(message);
|
||||
|
||||
public static ProductOperationResponse BadRequest(string message) => BadRequest<ProductOperationResponse>(message);
|
||||
public static ProductOperationResponse BadRequest(string message)
|
||||
=> BadRequest<ProductOperationResponse>(message);
|
||||
|
||||
public static ProductOperationResponse InternalServerError(string message) => InternalServerError<ProductOperationResponse>(message);
|
||||
}
|
||||
public static ProductOperationResponse InternalServerError(string message)
|
||||
=> InternalServerError<ProductOperationResponse>(message);
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class SalaryOperationResponse : OperationResponse
|
||||
{
|
||||
public static SalaryOperationResponse OK(List<SalaryViewModel> data) => OK<SalaryOperationResponse, List<SalaryViewModel>>(data);
|
||||
|
||||
public static SalaryOperationResponse NoContent() => NoContent<SalaryOperationResponse>();
|
||||
|
||||
public static SalaryOperationResponse NotFound(string message) => NotFound<SalaryOperationResponse>(message);
|
||||
|
||||
public static SalaryOperationResponse BadRequest(string message) => BadRequest<SalaryOperationResponse>(message);
|
||||
|
||||
public static SalaryOperationResponse InternalServerError(string message) => InternalServerError<SalaryOperationResponse>(message);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,25 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class SaleOperationResponse : OperationResponse
|
||||
{
|
||||
public static SaleOperationResponse OK(List<SaleViewModel> data) => OK<SaleOperationResponse, List<SaleViewModel>>(data);
|
||||
public static SaleOperationResponse OK(List<SaleViewModel> data) =>
|
||||
OK<SaleOperationResponse, List<SaleViewModel>>(data);
|
||||
|
||||
public static SaleOperationResponse OK(SaleViewModel data) => OK<SaleOperationResponse, SaleViewModel>(data);
|
||||
public static SaleOperationResponse OK(SaleViewModel data) =>
|
||||
OK<SaleOperationResponse, SaleViewModel>(data);
|
||||
|
||||
public static SaleOperationResponse NoContent() => NoContent<SaleOperationResponse>();
|
||||
public static SaleOperationResponse NoContent() =>
|
||||
NoContent<SaleOperationResponse>();
|
||||
|
||||
public static SaleOperationResponse NotFound(string message) => NotFound<SaleOperationResponse>(message);
|
||||
public static SaleOperationResponse NotFound(string message) =>
|
||||
NotFound<SaleOperationResponse>(message);
|
||||
|
||||
public static SaleOperationResponse BadRequest(string message) => BadRequest<SaleOperationResponse>(message);
|
||||
public static SaleOperationResponse BadRequest(string message) =>
|
||||
BadRequest<SaleOperationResponse>(message);
|
||||
|
||||
public static SaleOperationResponse InternalServerError(string message) => InternalServerError<SaleOperationResponse>(message);
|
||||
}
|
||||
public static SaleOperationResponse InternalServerError(string message) =>
|
||||
InternalServerError<SaleOperationResponse>(message);
|
||||
}
|
||||
@@ -1,26 +1,14 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class StorageOperationResponse : OperationResponse
|
||||
{
|
||||
public static StorageOperationResponse OK(List<StorageViewModel> data) => OK<StorageOperationResponse, List<StorageViewModel>>(data);
|
||||
|
||||
public static StorageOperationResponse OK(StorageViewModel data) => OK<StorageOperationResponse, StorageViewModel>(data);
|
||||
|
||||
public static StorageOperationResponse NoContent() => NoContent<StorageOperationResponse>();
|
||||
|
||||
public static StorageOperationResponse NotFound(string message) => NotFound<StorageOperationResponse>(message);
|
||||
|
||||
public static StorageOperationResponse BadRequest(string message) => BadRequest<StorageOperationResponse>(message);
|
||||
|
||||
public static StorageOperationResponse InternalServerError(string message) => InternalServerError<StorageOperationResponse>(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class SuppliesOperationResponse : OperationResponse
|
||||
{
|
||||
public static SuppliesOperationResponse OK(List<SuppliesViewModel> data) => OK<SuppliesOperationResponse, List<SuppliesViewModel>>(data);
|
||||
|
||||
public static SuppliesOperationResponse OK(SuppliesViewModel data) => OK<SuppliesOperationResponse, SuppliesViewModel>(data);
|
||||
|
||||
public static SuppliesOperationResponse NoContent() => NoContent<SuppliesOperationResponse>();
|
||||
|
||||
public static SuppliesOperationResponse NotFound(string message) => NotFound<SuppliesOperationResponse>(message);
|
||||
|
||||
public static SuppliesOperationResponse BadRequest(string message) => BadRequest<SuppliesOperationResponse>(message);
|
||||
|
||||
public static SuppliesOperationResponse InternalServerError(string message) => InternalServerError<SuppliesOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class SupplyOperationResponse : OperationResponse
|
||||
{
|
||||
public static SupplyOperationResponse OK(List<SupplyViewModel> data) => OK<SupplyOperationResponse, List<SupplyViewModel>>(data);
|
||||
public static SupplyOperationResponse OK(SupplyViewModel data) => OK<SupplyOperationResponse, SupplyViewModel>(data);
|
||||
public static SupplyOperationResponse NoContent() => NoContent<SupplyOperationResponse>();
|
||||
public static SupplyOperationResponse NotFound(string message) => NotFound<SupplyOperationResponse>(message);
|
||||
public static SupplyOperationResponse BadRequest(string message) => BadRequest<SupplyOperationResponse>(message);
|
||||
public static SupplyOperationResponse InternalServerError(string message) => InternalServerError<SupplyOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class WorkerOperationResponse : OperationResponse
|
||||
{
|
||||
public static WorkerOperationResponse OK(List<WorkerViewModel> data) => OK<WorkerOperationResponse, List<WorkerViewModel>>(data);
|
||||
|
||||
public static WorkerOperationResponse OK(WorkerViewModel data) => OK<WorkerOperationResponse, WorkerViewModel>(data);
|
||||
|
||||
public static WorkerOperationResponse NoContent() => NoContent<WorkerOperationResponse>();
|
||||
|
||||
public static WorkerOperationResponse NotFound(string message) => NotFound<WorkerOperationResponse>(message);
|
||||
|
||||
public static WorkerOperationResponse BadRequest(string message) => BadRequest<WorkerOperationResponse>(message);
|
||||
|
||||
public static WorkerOperationResponse InternalServerError(string message) => InternalServerError<WorkerOperationResponse>(message);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ClientBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? FIO { get; set; }
|
||||
|
||||
public string? PhoneNumber { get; set; }
|
||||
|
||||
public double DiscountSize { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class CustomerBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? FIO { get; set; }
|
||||
public string? Phone { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public double DiscountSize { get; set; }
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class EmployeeBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? FIO { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public string? PostId { get; set; }
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class IngredientBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? IngredientName { get; set; }
|
||||
|
||||
public string? IngredientType { get; set; }
|
||||
|
||||
public string? ManufacturerId { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ManufacturerBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? ManufacturerName { get; set; }
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CandyHouseContracts.Enums;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
@@ -16,5 +12,5 @@ public class PostBindingModel
|
||||
|
||||
public string? PostType { get; set; }
|
||||
|
||||
public double Salary { get; set; }
|
||||
}
|
||||
public string? ConfigurationJson { get; set; }
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CandyHouseContracts.Enums;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ProductBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? ProductName { get; set; }
|
||||
public string? ProductDescription { get; set; }
|
||||
public double Price { get; set; }
|
||||
public string? ProductType { get; set; }
|
||||
|
||||
public int? Count { get; set; }
|
||||
|
||||
public double? TotalPrice { get; set; }
|
||||
|
||||
public List<ProductIngredientBindingModel>? Ingredients { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ProductIngredientBindingModel
|
||||
{
|
||||
public string? ProductId { get; set; }
|
||||
public string? IngredientId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ProductStorageBindingModel
|
||||
{
|
||||
public string? StorageId { get; set; }
|
||||
public string? ProductId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ProductSuppliesBindingModel
|
||||
{
|
||||
public string? SuppliesId { get; set; }
|
||||
public string? ProductId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
@@ -10,11 +7,11 @@ public class SaleBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? EmployeeId { get; set; }
|
||||
public string? WorkerId { get; set; }
|
||||
|
||||
public string? ClientId { get; set; }
|
||||
public string? CustomerId { get; set; }
|
||||
|
||||
public int DiscountType { get; set; }
|
||||
|
||||
public List<SaleProductBindingModel>? Products { get; set; }
|
||||
}
|
||||
public ProductBindingModel? Product { get; set; }
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class SaleProductBindingModel
|
||||
{
|
||||
public string? SaleId { get; set; }
|
||||
|
||||
public string? ProductId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
}
|
||||
@@ -1,16 +1,9 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class StorageBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public ProductType? ProductType { get; set; }
|
||||
public required string Address { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<ProductStorageBindingModel>? Products { get; set; }
|
||||
}
|
||||
public List<StorageIngredientBindingModel> Ingredients { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class StorageIngredientBindingModel
|
||||
{
|
||||
public required string StorageId { get; set; }
|
||||
public required string IngredientId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class SuppliesBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public ProductType? ProductType { get; set; }
|
||||
public DateTime ProductuionDate { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<ProductSuppliesBindingModel>? Products { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class SupplyBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public required string StorageId { get; set; }
|
||||
public DateTime DeliveryDate { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<SupplyIngredientBindingModel> Ingredients { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class SupplyIngredientBindingModel
|
||||
{
|
||||
public required string SupplyId { get; set; }
|
||||
public required string IngredientId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class WorkerBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? FIO { get; set; }
|
||||
|
||||
public string? PostId { get; set; }
|
||||
|
||||
public DateTime? BirthDate { get; set; }
|
||||
|
||||
public DateTime? EmploymentDate { get; set; }
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BuisnessLogicContracts;
|
||||
|
||||
public interface IClientBusinessLogicContract
|
||||
{
|
||||
List<ClientDataModel> GetAllClients();
|
||||
|
||||
ClientDataModel GetClientByData(string data);
|
||||
|
||||
void InsertClient(ClientDataModel clientDataModel);
|
||||
|
||||
void UpdateClient(ClientDataModel clientDataModel);
|
||||
|
||||
void DeleteClient(string id);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BuisnessLogicContracts;
|
||||
|
||||
public interface IEmployeeBusinessLogicContract
|
||||
{
|
||||
List<EmployeeDataModel> GetAllEmployees(bool onlyActive = true);
|
||||
|
||||
List<EmployeeDataModel> GetAllEmployeesByPost(string employeeId, bool onlyActive = true);
|
||||
|
||||
List<EmployeeDataModel> GetAllEmployeesByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
||||
|
||||
List<EmployeeDataModel> GetAllEmployeesByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
||||
|
||||
EmployeeDataModel GetEmployeeByData(string data);
|
||||
|
||||
void InsertEmployee(EmployeeDataModel employeeDataModel);
|
||||
|
||||
void UpdateEmployee(EmployeeDataModel employeeDataModel);
|
||||
|
||||
void DeleteEmployee(string id);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BuisnessLogicContracts;
|
||||
|
||||
public interface IProductBusinessLogicContract
|
||||
{
|
||||
List<ProductDataModel> GetAllProducts();
|
||||
|
||||
List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId);
|
||||
|
||||
ProductDataModel GetProductByData(string data);
|
||||
|
||||
void InsertProduct(ProductDataModel productDataModel);
|
||||
|
||||
void UpdateProduct(ProductDataModel productDataModel);
|
||||
|
||||
void DeleteProduct(string id);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BuisnessLogicContracts;
|
||||
|
||||
public interface ISalaryBusinessLogicContract
|
||||
{
|
||||
List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
List<SalaryDataModel> GetAllSalariesByPeriodByEmployee(DateTime fromDate, DateTime toDate, string employeeId);
|
||||
|
||||
void CalculateSalaryByMounth(DateTime date);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicContracts;
|
||||
|
||||
public interface IStorageBusinessLogicContract
|
||||
{
|
||||
List<StorageDataModel> GetAllComponents();
|
||||
StorageDataModel GetComponentByData(string data);
|
||||
void InsertComponent(StorageDataModel storageDataModel);
|
||||
void UpdateComponent(StorageDataModel storageDataModel);
|
||||
void DeleteComponent(string id);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicContracts;
|
||||
|
||||
public interface ISuppliesBusinessLogicContract
|
||||
{
|
||||
List<SuppliesDataModel> GetAllComponents();
|
||||
SuppliesDataModel GetComponentByData(string data);
|
||||
void InsertComponent(SuppliesDataModel componentDataModel);
|
||||
void UpdateComponent(SuppliesDataModel componentDataModel);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IIngredientBusinessLogicContract
|
||||
{
|
||||
List<IngredientDataModel> GetAllIngredients(bool onlyActive = true);
|
||||
List<IngredientDataModel> GetAllIngredientsByManufacturer(string manufacturerId, bool onlyActive = true);
|
||||
List<IngredientHistoryDataModel> GetIngredientHistory(string ingredientId);
|
||||
IngredientDataModel GetIngredientByData(string data);
|
||||
void InsertIngredient(IngredientDataModel ingredientDataModel);
|
||||
void UpdateIngredient(IngredientDataModel ingredientDataModel);
|
||||
void DeleteIngredient(string id);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface ICustomerBusinessLogicContract
|
||||
{
|
||||
List<CustomerDataModel> GetAllCustomers();
|
||||
CustomerDataModel GetCustomerByData(string data);
|
||||
void InsertCustomer(CustomerDataModel customerDataModel);
|
||||
void UpdateCustomer(CustomerDataModel customerDataModel);
|
||||
void DeleteCustomer(string id);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IManufacturerBusinessLogicContract
|
||||
{
|
||||
List<ManufacturerDataModel> GetAllManufacturers();
|
||||
ManufacturerDataModel GetManufacturerByData(string data);
|
||||
void InsertManufacturer(ManufacturerDataModel manufacturerDataModel);
|
||||
void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel);
|
||||
void DeleteManufacturer(string id);
|
||||
}
|
||||
@@ -1,25 +1,15 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BuisnessLogicContracts;
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IPostBusinessLogicContract
|
||||
{
|
||||
List<PostDataModel> GetAllPosts();
|
||||
|
||||
List<PostDataModel> GetAllDataOfPost(string postId);
|
||||
|
||||
List<PostDataModel> GetPostHistory(string postId);
|
||||
PostDataModel GetPostByData(string data);
|
||||
|
||||
void InsertPost(PostDataModel postDataModel);
|
||||
|
||||
void UpdatePost(PostDataModel postDataModel);
|
||||
|
||||
void DeletePost(string id);
|
||||
|
||||
void RestorePost(string id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс бизнес-логики
|
||||
/// </summary>
|
||||
public interface IProductBusinessLogicContract
|
||||
{
|
||||
List<ProductDataModel> GetAllProducts(bool onlyActive = true);
|
||||
ProductDataModel GetProductById(string id);
|
||||
void InsertProduct(ProductDataModel saleProductDataModel);
|
||||
void UpdateProduct(ProductDataModel saleProductDataModel);
|
||||
void DeleteProduct(string id);
|
||||
List<ProductIngredientDataModel> GetIngredientsByProductId(string saleProductId);
|
||||
void AddIngredientToProduct(ProductIngredientDataModel ProductIngredient);
|
||||
void RemoveIngredientFromProduct(string ingredientId, string productId);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface ISalaryBusinessLogicContract
|
||||
{
|
||||
List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId);
|
||||
void CalculateSalaryByMonth(DateTime date);
|
||||
}
|
||||
@@ -1,25 +1,15 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BuisnessLogicContracts;
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface ISaleBusinessLogicContract
|
||||
{
|
||||
List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
List<SaleDataModel> GetAllSalesByEmployeeByPeriod(string employeeId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
List<SaleDataModel> GetAllSalesByClientByPeriod(string clientId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
List<SaleDataModel> GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate);
|
||||
List<SaleDataModel> GetAllSalesByCustomerByPeriod(string customerId, DateTime fromDate, DateTime toDate);
|
||||
List<SaleDataModel> GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleDataModel GetSaleByData(string data);
|
||||
|
||||
void InsertSale(SaleDataModel saleDataModel);
|
||||
|
||||
void CancelSale(string id);
|
||||
}
|
||||
double CalculateSalesRevenue(DateTime fromDate, DateTime toDate);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IStorageBusinessLogicContract
|
||||
{
|
||||
List<StorageDataModel> GetAllStorages();
|
||||
void CreateStorage(string id, string address, int count, List<StorageIngredientDataModel> ingredients);
|
||||
void UpdateStorage(StorageDataModel storage);
|
||||
void AddIngredientToStorage(string storageId, StorageIngredientDataModel ingredient);
|
||||
void UpdateIngredientCount(string storageId, string ingredientId, int newCount);
|
||||
int GetIngredientCountFromStorage(string storageId, string ingredientId);
|
||||
List<StorageIngredientDataModel> GetIngredientsFromStorage(string storageId);
|
||||
StorageDataModel GetStorageById(string storageId);
|
||||
Dictionary<string, int> CalculateRemainingIngredients(string storageId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface ISupplyBusinessLogicContract
|
||||
{
|
||||
List<SupplyDataModel> GetAllSupplies();
|
||||
void CreateSupply(SupplyDataModel supply);
|
||||
SupplyDataModel GetSupplyById(string supplyId);
|
||||
List<SupplyDataModel> GetSuppliesByStorageId(string storageId);
|
||||
void AddOrUpdateIngredientInSupply(SupplyIngredientDataModel ingredient);
|
||||
void UpdateIngredientCountInSupply(string supplyId, string ingredientId, int newCount);
|
||||
void RemoveIngredientFromSupply(string supplyId, string ingredientId);
|
||||
int CalculateSuppliedIngredientsCount(DateTime fromDate, DateTime toDate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
|
||||
namespace CandyHouseContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IWorkerBusinessLogicContract
|
||||
{
|
||||
List<WorkerDataModel> GetAllWorkers(bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
||||
WorkerDataModel GetWorkerByData(string data);
|
||||
void InsertWorker(WorkerDataModel workerDataModel);
|
||||
void UpdateWorker(WorkerDataModel workerDataModel);
|
||||
void DeleteWorker(string id);
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using ValidationException = CandyHouseContracts.Exceptions.ValidationException;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class ClientDataModel(string id, string fIO, string phoneNumber, double discountSize) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fIO;
|
||||
|
||||
public string PhoneNumber { get; private set; } = phoneNumber;
|
||||
|
||||
public double DiscountSize { get; private set; } = discountSize;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
|
||||
if (PhoneNumber.IsEmpty())
|
||||
throw new ValidationException("Field PhoneNumber is empty");
|
||||
|
||||
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System.Text.RegularExpressions;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class CustomerDataModel(string id, string fio, string phone, string email, double discountSize) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string Phone { get; private set; } = phone;
|
||||
public string Email { get; private set; } = email;
|
||||
public double DiscountSize { get; private set; } = discountSize;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty");
|
||||
if (Phone.IsEmpty()) throw new ValidationException("Field Phone is empty");
|
||||
|
||||
var phoneRegex = new Regex(@"^\+7\d{10}$");
|
||||
if (!phoneRegex.IsMatch(Phone)) throw new ValidationException("Invalid phone format");
|
||||
|
||||
if (Email.IsEmpty() || !Email.Contains("@")) throw new ValidationException("Invalid email format");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class EmployeeDataModel(string id, string fio, string email, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
private readonly PostDataModel? _post;
|
||||
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
|
||||
public string Email { get; private set; } = email;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
|
||||
public DateTime BirthDate { get; private set; } = birthDate;
|
||||
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
public string PostName => _post?.PostName ?? string.Empty;
|
||||
|
||||
public EmployeeDataModel(string id, string fio, string email, string postId, DateTime birthDate, DateTime employmentDate,
|
||||
bool isDeleted, PostDataModel post) : this(id, fio, email, postId, birthDate, employmentDate, isDeleted)
|
||||
{
|
||||
_post = post;
|
||||
}
|
||||
|
||||
public EmployeeDataModel(string id, string fio, string email, string postId, DateTime birthDate,
|
||||
DateTime employmentDate) : this(id, fio, email, postId, birthDate, employmentDate, false) { }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
|
||||
if (Email.IsEmpty())
|
||||
throw new ValidationException("Field Email is empty");
|
||||
|
||||
if (!Regex.IsMatch(Email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
||||
throw new ValidationException("Field Email is not a valid email address");
|
||||
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-18).Date)
|
||||
throw new ValidationException($"Only adults can be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||
|
||||
if (EmploymentDate.Date < BirthDate.Date)
|
||||
throw new ValidationException("The date of employment cannot be less than the date of birth");
|
||||
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 18)
|
||||
throw new ValidationException($"Only adults can be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class IngredientDataModel(string id, string ingredientName, IngredientType ingredientType, string manufacturerId, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string IngredientName { get; private set; } = ingredientName;
|
||||
|
||||
public IngredientType IngredientType { get; private set; } = ingredientType;
|
||||
|
||||
public string ManufacturerId { get; private set; } = manufacturerId;
|
||||
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
private readonly ManufacturerDataModel? _manufacturer;
|
||||
|
||||
public string ManufacturerName => _manufacturer?.ManufacturerName ?? string.Empty;
|
||||
|
||||
public IngredientDataModel(string id, string ingredientName, IngredientType ingredientType, string manufacturerId, double price, bool isDeleted, ManufacturerDataModel manufacturer) : this(id, ingredientName, ingredientType, manufacturerId, price, isDeleted)
|
||||
{
|
||||
_manufacturer = manufacturer;
|
||||
}
|
||||
public IngredientDataModel(string id, string ingredientName, IngredientType ingredientType, string manufacturerId, double price) : this(id, ingredientName, ingredientType, manufacturerId, price, false) { }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (IngredientName.IsEmpty())
|
||||
throw new ValidationException("Field IngredientName is empty");
|
||||
if (IngredientType == IngredientType.None)
|
||||
throw new ValidationException("Field IngredientType is empty");
|
||||
if (ManufacturerId.IsEmpty())
|
||||
throw new ValidationException("Field ManufacturerId is empty");
|
||||
if (!ManufacturerId.IsGuid())
|
||||
throw new ValidationException("The value in the field ManufacturerId is not a unique identifier");
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class IngredientHistoryDataModel(string ingredientId, double oldPrice) : IValidation
|
||||
{
|
||||
private readonly IngredientDataModel? _ingredient;
|
||||
|
||||
public string IngredientId { get; private set; } = ingredientId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice; // олд спайс
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow; // дата изменения цены
|
||||
|
||||
public string IngredientName => _ingredient?.IngredientName ?? string.Empty;
|
||||
|
||||
public IngredientHistoryDataModel(string ingredientId, double oldPrice, DateTime changeDate, IngredientDataModel ingredient) : this(ingredientId, oldPrice)
|
||||
{
|
||||
ChangeDate = changeDate;
|
||||
_ingredient = ingredient;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (IngredientId.IsEmpty())
|
||||
throw new ValidationException("Field IngredientId is empty");
|
||||
if (!IngredientId.IsGuid())
|
||||
throw new ValidationException("The value in the field IngredientId is not a unique identifier");
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class ManufacturerDataModel(string id, string manufacturerName, string?
|
||||
prevManufacturerName, string? prevPrevManufacturerName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string ManufacturerName { get; private set; } = manufacturerName;
|
||||
public string? PrevManufacturerName { get; private set; } =
|
||||
prevManufacturerName;
|
||||
public string? PrevPrevManufacturerName { get; private set; } =
|
||||
prevPrevManufacturerName;
|
||||
|
||||
public ManufacturerDataModel(string id, string manufacturerName) : this(id, manufacturerName, null, null) { }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (ManufacturerName.IsEmpty())
|
||||
throw new ValidationException("Field ManufacturerName isempty");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,36 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CandyHouseContracts.Infrastructure.PostConfigurations;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class PostDataModel(string postId, string postName, PostType postType, double salary) : IValidation
|
||||
public class PostDataModel(string postid, string postName, PostType postType, PostConfiguration configuration) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = postId;
|
||||
public string Id { get; private set; } = postid;
|
||||
|
||||
public string PostName { get; private set; } = postName;
|
||||
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
public double Salary { get; private set; } = salary;
|
||||
|
||||
public PostConfiguration ConfigurationModel { get; private set; } = configuration;
|
||||
|
||||
public PostDataModel(string postId, string postName, PostType postType, string configurationJson) : this(postId, postName, postType, (PostConfiguration)null)
|
||||
{
|
||||
var obj = JToken.Parse(configurationJson);
|
||||
if (obj is not null)
|
||||
{
|
||||
ConfigurationModel = obj.Value<string>("Type") switch
|
||||
{
|
||||
nameof(CashierPostConfiguration) => JsonConvert.DeserializeObject<CashierPostConfiguration>(configurationJson)!,
|
||||
nameof(SupervisorPostConfiguration) => JsonConvert.DeserializeObject<SupervisorPostConfiguration>(configurationJson)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(configurationJson)!,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
@@ -26,8 +41,10 @@ public class PostDataModel(string postId, string postName, PostType postType, do
|
||||
if (PostName.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
if (ConfigurationModel is null)
|
||||
throw new ValidationException("Field ConfigurationModel is not initialized");
|
||||
if (ConfigurationModel!.Rate <= 0)
|
||||
throw new ValidationException("Field Rate is less or equal zero");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class ProductSuppliesDataModel(string suppliesId, string productId, int count) : IValidation
|
||||
public class ProductIngredientDataModel(string ingredientId, string productId, int count) : IValidation
|
||||
{
|
||||
public string SuppliesId { get; private set; } = suppliesId;
|
||||
public string IngredientId { get; private set; } = ingredientId;
|
||||
public string ProductId { get; private set; } = productId;
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public int Count { get; private set; } = count; //Например для плашек оперативки
|
||||
public void Validate()
|
||||
{
|
||||
if (SuppliesId.IsEmpty())
|
||||
throw new ValidationException("Field SuppliesId is empty");
|
||||
if (!SuppliesId.IsGuid())
|
||||
throw new ValidationException("The value in the field SuppliesId is not a unique identifier");
|
||||
if (IngredientId.IsEmpty())
|
||||
throw new ValidationException("Field IngredientId is empty");
|
||||
|
||||
if (!IngredientId.IsGuid())
|
||||
throw new ValidationException("The value in the field IngredientId is not a unique identifier");
|
||||
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field BlandId is not a unique identifier");
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
@@ -1,25 +1,17 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class ProductDataModel(string id, string productName, string productDescription, double price, ProductType productType) : IValidation
|
||||
public class ProductDataModel(string id, string productName, int count, double totalPrice, List<ProductIngredientDataModel> ingredients, bool isDeleted = false) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string ProductName { get; private set; } = productName;
|
||||
public string ProductDescription { get; private set; } = productDescription;
|
||||
public double Price { get; private set; } = price;
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
|
||||
public string Id { get; private set; } = id; // Id товара, т.к. в этой сущности хранится готовый к продаже ПК
|
||||
public string ProductName { get; private set; } = productName; // Теперь тут название ПК, а не ProductID (ID выше добавил)
|
||||
public int Count { get; private set; } = count;
|
||||
public double TotalPrice { get; private set; } = totalPrice;
|
||||
public List<ProductIngredientDataModel> Ingredients { get; private set; } = ingredients;
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
@@ -28,11 +20,11 @@ public class ProductDataModel(string id, string productName, string productDescr
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (ProductName.IsEmpty())
|
||||
throw new ValidationException("Field ProductName is empty");
|
||||
if (ProductDescription.IsEmpty())
|
||||
throw new ValidationException("Field ProductDescription is empty");
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
if (TotalPrice <= 0)
|
||||
throw new ValidationException("Field TotalPrice is less than or equal to 0");
|
||||
if (Ingredients == null || Ingredients.Count == 0)
|
||||
throw new ValidationException("Product must contain at least one ingredient");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class ProductHistoryDataModel(string productId, double oldPrice) : IValidation
|
||||
{
|
||||
private readonly ProductDataModel? _product;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public string ProductName => _product?.ProductName ?? string.Empty;
|
||||
|
||||
public ProductHistoryDataModel(string productId, double oldPrice, DateTime changeDate, ProductDataModel product) : this(productId, oldPrice)
|
||||
{
|
||||
ChangeDate = changeDate;
|
||||
_product = product;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,32 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary) : IValidation
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
|
||||
{
|
||||
private readonly EmployeeDataModel? _employee;
|
||||
public string EmployeeId { get; private set; } = employeeId;
|
||||
private readonly WorkerDataModel? _worker;
|
||||
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = employeeSalary;
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
|
||||
public string EmployeeFIO => _employee?.FIO ?? string.Empty;
|
||||
public string WorkerFIO => _worker?.FIO ?? string.Empty;
|
||||
|
||||
public SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary, EmployeeDataModel employee) : this(employeeId, salaryDate, employeeSalary)
|
||||
public SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary, WorkerDataModel worker) : this(workerId, salaryDate, workerSalary)
|
||||
{
|
||||
_employee = employee;
|
||||
_worker = worker;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (EmployeeId.IsEmpty())
|
||||
throw new ValidationException("Field EmployeeId is empty");
|
||||
|
||||
if (!EmployeeId.IsGuid())
|
||||
throw new ValidationException("The value in the field EmployeeId is not a unique identifier");
|
||||
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,50 +2,38 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SaleDataModel : IValidation
|
||||
{
|
||||
private readonly ClientDataModel? _client;
|
||||
private readonly CustomerDataModel? _customer;
|
||||
|
||||
private readonly EmployeeDataModel? _employee;
|
||||
private readonly WorkerDataModel? _worker;
|
||||
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string EmployeeId { get; private set; }
|
||||
|
||||
public string? ClientId { get; private set; }
|
||||
|
||||
public string WorkerId { get; private set; }
|
||||
public string? CustomerId { get; private set; }
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public DiscountType DiscountType { get; private set; }
|
||||
|
||||
public double Discount { get; private set; }
|
||||
|
||||
public bool IsCancel { get; private set; }
|
||||
public ProductDataModel? Product { get; private set; }
|
||||
|
||||
public List<SaleProductDataModel>? Products { get; private set; }
|
||||
public string CustomerFIO => _customer?.FIO ?? string.Empty;
|
||||
|
||||
public string ClientFIO => _client?.FIO ?? string.Empty;
|
||||
public string WorkerFIO => _worker?.FIO ?? string.Empty;
|
||||
|
||||
public string EmployeeFIO => _employee?.FIO ?? string.Empty;
|
||||
|
||||
public SaleDataModel(string id, string employeeId, string? clientId, DiscountType discountType, bool isCancel, List<SaleProductDataModel> saleProducts)
|
||||
public SaleDataModel(string id, string workerId, string? customerId, DiscountType discountType, bool isCancel, ProductDataModel product)
|
||||
{
|
||||
Id = id;
|
||||
EmployeeId = employeeId;
|
||||
ClientId = clientId;
|
||||
WorkerId = workerId;
|
||||
CustomerId = customerId;
|
||||
DiscountType = discountType;
|
||||
IsCancel = isCancel;
|
||||
Products = saleProducts;
|
||||
Product = product;
|
||||
var percent = 0.0;
|
||||
foreach (DiscountType elem in Enum.GetValues<DiscountType>())
|
||||
{
|
||||
@@ -67,43 +55,41 @@ public class SaleDataModel : IValidation
|
||||
}
|
||||
}
|
||||
}
|
||||
Sum = Products?.Sum(x => x.Price * x.Count) ?? 0;
|
||||
|
||||
// Рассчитываем Sum и Discount
|
||||
Sum = Product != null ? Product.TotalPrice * Product.Count : 0;
|
||||
Discount = Sum * percent;
|
||||
}
|
||||
|
||||
public SaleDataModel(string id, string employeeId, string? clientId, double sum, DiscountType discountType, double discount, bool isCancel,
|
||||
List<SaleProductDataModel> saleProducts, EmployeeDataModel employee, ClientDataModel? client) : this(id, employeeId, clientId, discountType, isCancel, saleProducts)
|
||||
public SaleDataModel(string id, string workerId, string? customerId, double sum, DiscountType discountType, double discount, bool isCancel, ProductDataModel Product, WorkerDataModel worker, CustomerDataModel? customer) : this(id, workerId, customerId, discountType, isCancel, Product)
|
||||
{
|
||||
Sum = sum;
|
||||
Discount = discount;
|
||||
_employee = employee;
|
||||
_client = client;
|
||||
_worker = worker;
|
||||
_customer = customer;
|
||||
}
|
||||
|
||||
public SaleDataModel(string id, string employeeId, string? clientId, int discountType,
|
||||
List<SaleProductDataModel> products) : this(id, employeeId, clientId, (DiscountType)discountType, false, products) { }
|
||||
public SaleDataModel(string id, string workerId, string? customerId, int discountType, ProductDataModel product) : this(id, workerId, customerId, (DiscountType)discountType, false, product) { }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (EmployeeId.IsEmpty())
|
||||
throw new ValidationException("Field EmployeeId is empty");
|
||||
|
||||
if (!EmployeeId.IsGuid())
|
||||
throw new ValidationException("The value in the field EmployeeId is not a unique identifier");
|
||||
|
||||
if (!ClientId?.IsGuid() ?? !ClientId?.IsEmpty() ?? false)
|
||||
throw new ValidationException("The value in the field BuyerId is not a unique identifier");
|
||||
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
if (CustomerId != null && (!CustomerId.IsGuid() || CustomerId.IsEmpty()))
|
||||
throw new ValidationException("The value in the field CustomerId is not a unique identifier");
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
if (Product == null)
|
||||
throw new ValidationException("Products cannot be null or empty");
|
||||
if (Product.Count <= 0)
|
||||
throw new ValidationException("The sale must include at least one product (Product.Count must be greater than 0)");
|
||||
if (!Product.Id.IsGuid()) // Добавлена проверка Product.Id
|
||||
throw new ValidationException("The value in the field Product.Id is not a unique identifier");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SaleProductDataModel(string saleId, string productId, int count, double price) : IValidation
|
||||
{
|
||||
private readonly ProductDataModel? _product;
|
||||
|
||||
public string SaleId { get; private set; } = saleId;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public string ProductName => _product?.ProductName ?? string.Empty;
|
||||
|
||||
public SaleProductDataModel(string saleId, string productId, int count, double price, ProductDataModel product) : this(saleId, productId, count, price)
|
||||
{
|
||||
_product = product;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SaleId.IsEmpty())
|
||||
throw new ValidationException("Field SaleId is empty");
|
||||
|
||||
if (!SaleId.IsGuid())
|
||||
throw new ValidationException("The value in the field SaleId is not a unique identifier");
|
||||
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,30 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class ProductStorageDataModel(string storageId, string productId, int count) : IValidation
|
||||
public class StorageIngredientDataModel(string storageId, string ingredientId, int count) : IValidation
|
||||
{
|
||||
public string StorageId { get; private set; } = storageId;
|
||||
public string ProductId { get; private set; } = productId;
|
||||
public string IngredientId { get; private set; } = ingredientId;
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (StorageId.IsEmpty())
|
||||
throw new ValidationException("Field StorageId is empty");
|
||||
|
||||
if (!StorageId.IsGuid())
|
||||
throw new ValidationException("The value in the field StorageId is not a unique identifier");
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (IngredientId.IsEmpty())
|
||||
throw new ValidationException("Field IngredientId is empty");
|
||||
|
||||
if (!IngredientId.IsGuid())
|
||||
throw new ValidationException("The value in the field IngredientId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,28 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class StorageDataModel(string id, ProductType productType, int count, List<ProductStorageDataModel> products) : IValidation
|
||||
public class StorageDataModel(string id, string address, int count, List<StorageIngredientDataModel> ingredients) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
public string Address { get; private set; } = address;
|
||||
public int Count { get; private set; } = count;
|
||||
public List<ProductStorageDataModel> Products { get; private set; } = products;
|
||||
public List<StorageIngredientDataModel> Ingredients { get; private set; } = ingredients;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
|
||||
if (Address.IsEmpty())
|
||||
throw new ValidationException("Field Address is empty");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SuppliesDataModel(string id, ProductType productType, DateTime productuionDate, int count, List<ProductSuppliesDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
public DateTime ProductuionDate { get; private set; } = productuionDate;
|
||||
public int Count { get; private set; } = count;
|
||||
public List<ProductSuppliesDataModel> Products { get; private set; } = products;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SupplyIngredientDataModel(string supplyId, string ingredientId, int count) : IValidation
|
||||
{
|
||||
public string SupplyId { get; private set; } = supplyId;
|
||||
public string IngredientId { get; private set; } = ingredientId;
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SupplyId.IsEmpty())
|
||||
throw new ValidationException("Field SupplyId is empty");
|
||||
|
||||
if (!SupplyId.IsGuid())
|
||||
throw new ValidationException("The value in the field SupplyId is not a unique identifier");
|
||||
|
||||
if (IngredientId.IsEmpty())
|
||||
throw new ValidationException("Field IngredientId is empty");
|
||||
|
||||
if (!IngredientId.IsGuid())
|
||||
throw new ValidationException("The value in the field IngredientId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SupplyDataModel(string id, string storageId, DateTime deliveryDate, int count, List<SupplyIngredientDataModel> ingredients) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string StorageId { get; private set; } = storageId;
|
||||
public DateTime DeliveryDate { get; private set; } = deliveryDate;
|
||||
public int Count { get; private set; } = count;
|
||||
public List<SupplyIngredientDataModel> Ingredients { get; private set; } = ingredients;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (StorageId.IsEmpty())
|
||||
throw new ValidationException("Field StorageId is empty");
|
||||
|
||||
if (!StorageId.IsGuid())
|
||||
throw new ValidationException("The value in the field StorageId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
|
||||
if ((Ingredients?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The supplies must include ingredients");
|
||||
|
||||
if (DeliveryDate > DateTime.UtcNow)
|
||||
throw new ValidationException("Delivery date cannot be in the future");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.Infrastructure.PostConfigurations;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
private readonly PostDataModel? _post;
|
||||
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
|
||||
public DateTime BirthDate { get; private set; } = birthDate;
|
||||
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted; // признак уволился или нет
|
||||
|
||||
public string PostName => _post?.PostName ?? string.Empty;
|
||||
|
||||
public PostConfiguration Configuration => _post?.ConfigurationModel ?? new() { Rate = 0 };
|
||||
|
||||
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, PostDataModel post) : this(id, fio, postId, birthDate, employmentDate, isDeleted)
|
||||
{
|
||||
_post = post;
|
||||
}
|
||||
|
||||
public WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate) : this(id, fio, postId, birthDate, employmentDate, false) { }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
|
||||
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||
if (EmploymentDate.Date < BirthDate.Date)
|
||||
throw new ValidationException("The date of employment caanot be less than the date of birth");
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace CandyHouseContracts.Enums;
|
||||
|
||||
|
||||
namespace CandyHouseContracts.Enums;
|
||||
[Flags]
|
||||
public enum DiscountType
|
||||
{
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace CandyHouseContracts.Enums;
|
||||
|
||||
public enum IngredientType
|
||||
{
|
||||
None = 0, // Не указано
|
||||
Motherboard = 1, // Мать
|
||||
Processor = 2, // Процессор
|
||||
Ram = 3, // Оперативка
|
||||
PowerUnit = 4, // БП
|
||||
GraphicsCard = 5, // Видюха
|
||||
SVO = 6, // Система Воздушного Охлаждения (кулеры)
|
||||
SJO = 7, // Система ЖИДкостного Охлаждения
|
||||
Case = 8, // Кейс
|
||||
Storage = 9, // Накопитель (SSD и HDD)
|
||||
Monitor = 10, // Монитор
|
||||
Peripheral = 11 // Периферия (мышки клавы уши, крч I/O Devices)
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.Enums;
|
||||
namespace CandyHouseContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Manager = 1,
|
||||
TravelAgent = 2,
|
||||
Сhief = 3,
|
||||
}
|
||||
None = 0, // Не указано
|
||||
Manager = 1, // Менеджер (административная должность)
|
||||
SalesSpecialist = 2, // Специалист по продажам
|
||||
TechnicalSpecialist = 3, // Технический специалист
|
||||
StockmanDNS = 4, // Кладовщик
|
||||
Boss = 5 // НАЧАААЛЬНИК
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.Enums;
|
||||
|
||||
public enum ProductType
|
||||
{
|
||||
None = 0,
|
||||
Candy = 1,
|
||||
Cake = 2,
|
||||
Chocolate = 3,
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.Exceptions;
|
||||
namespace CandyHouseContracts.Exceptions;
|
||||
|
||||
public class ElementDeletedException : Exception
|
||||
{
|
||||
public ElementDeletedException(string id) : base($"Cannot modify a deleted item (id: {id})") { }
|
||||
public ElementDeletedException(string id) : base($"Cannot modify a deleted item(id: {id})") { }
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user