Compare commits
13 Commits
Task_3Hard
...
Task_5Hard
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36ace5c8ef | ||
|
|
7858a8c491 | ||
|
|
9d12ff2500 | ||
| c28acf5bd5 | |||
| b2cf602602 | |||
|
|
0eda3b21b0 | ||
|
|
957d5adc0d | ||
|
|
45687ed29a | ||
|
|
eed08a91b2 | ||
|
|
73dee8107d | ||
|
|
bb89dd1952 | ||
|
|
5779b9695a | ||
|
|
d9d1a19ee8 |
@@ -9,7 +9,7 @@ using SquirrelContract.DataModels;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class ClientBusinessLogicContract(IClientStorageContract clientStorageContract, ILogger logger) : IClientBusinessLogicContract
|
||||
public class ClientBusinessLogicContract(IClientStorageContract clientStorageContract, ILogger logger) : IClientBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IClientStorageContract _clientStorageContract = clientStorageContract;
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class CocktailBusinessLogicContract(ICocktailStorageContract cocktailStorageContract, ILogger logger) : ICocktailBusinessLogicContract
|
||||
public class CocktailBusinessLogicContract(ICocktailStorageContract cocktailStorageContract, ILogger logger) : ICocktailBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ICocktailStorageContract _cocktailStorageContract = cocktailStorageContract;
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStorageContract, ILogger logger) : IEmployeeBusinessLogicContract
|
||||
public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStorageContract, ILogger logger) : IEmployeeBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IEmployeeStorageContract _employeeStorageContract = employeeStorageContract;
|
||||
|
||||
@@ -8,14 +8,14 @@ using System.Text.Json;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
public class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
public List<PostDataModel> GetAllPosts(bool onlyActive = true)
|
||||
public List<PostDataModel> GetAllPosts()
|
||||
{
|
||||
_logger.LogInformation("GetAllPosts params: {onlyActive}", onlyActive);
|
||||
return _postStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
||||
_logger.LogInformation("GetAllPosts");
|
||||
return _postStorageContract.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetAllDataOfPost(string postId)
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
using BarBelochkaContract.DataModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SquirrelContract.BusinessLogicContracts;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
using SquirrelContract.Infastructure.PostConfigurations;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,
|
||||
ISaleStorageContract saleStorageContract, IPostStorageContract postStorageContract, IEmployeeStorageContract employeeStorageContract, ILogger logger) : ISalaryBusinessLogicContract
|
||||
public class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,
|
||||
ISaleStorageContract saleStorageContract, IPostStorageContract postStorageContract, IEmployeeStorageContract employeeStorageContract, 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 IConfigurationSalary _salaryConfiguration = сonfiguration;
|
||||
private readonly Lock _lockObject = new();
|
||||
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
@@ -51,13 +57,70 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
||||
var employees = _employeeStorageContract.GetList() ?? throw new NullListException();
|
||||
foreach (var employee in employees)
|
||||
{
|
||||
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;
|
||||
var sales = _saleStorageContract.GetList(startDate, finishDate, employeeId: employee.Id) ?? throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(employee.PostId) ?? throw new NullListException();
|
||||
var salary = post.ConfigurationModel switch
|
||||
{
|
||||
null => 0,
|
||||
BartenderPostConfiguration cpc => CalculateSalaryForBartender(sales, startDate, finishDate, cpc),
|
||||
ManagerPostConfiguration spc => CalculateSalaryForManager(startDate, finishDate, spc),
|
||||
PostConfiguration pc => pc.Rate,
|
||||
};
|
||||
_logger.LogDebug("The employee {employeeId} was paid a salary of {salary}", employee.Id, salary);
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(employee.Id, finishDate, salary));
|
||||
}
|
||||
}
|
||||
|
||||
private double CalculateSalaryForBartender(List<SaleDataModel> sales, DateTime startDate, DateTime finishDate, BartenderPostConfiguration config)
|
||||
{
|
||||
var calcPercent = 0.0;
|
||||
var days = (finishDate - startDate).Days;
|
||||
var dates = Enumerable.Range(0, days)
|
||||
.Select(offset => startDate.AddDays(offset))
|
||||
.ToList();
|
||||
|
||||
var parallelOptions = new ParallelOptions
|
||||
{
|
||||
MaxDegreeOfParallelism = _salaryConfiguration.MaxConcurrentThreads
|
||||
};
|
||||
|
||||
Parallel.ForEach(dates, parallelOptions, date =>
|
||||
{
|
||||
var salesInDay = sales.Where(x => x.SaleDate.Date == date.Date).ToArray();
|
||||
if (salesInDay.Length == 0) return;
|
||||
|
||||
double dailySum = salesInDay.Sum(x => x.Sum);
|
||||
double averageSale = dailySum / salesInDay.Length;
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
calcPercent += averageSale * config.SalePercent;
|
||||
}
|
||||
});
|
||||
|
||||
double bonus = 0;
|
||||
try
|
||||
{
|
||||
bonus = sales.Where(x => x.Sum > _salaryConfiguration.ExtraSaleSum)
|
||||
.Sum(x => x.Sum) * config.BonusForExtraSales;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error in bonus calculation");
|
||||
}
|
||||
|
||||
return config.Rate + calcPercent + bonus;
|
||||
}
|
||||
private double CalculateSalaryForManager(DateTime startDate, DateTime finishDate, ManagerPostConfiguration config)
|
||||
{
|
||||
try
|
||||
{
|
||||
return config.Rate + config.PersonalCountTrendPremium * _employeeStorageContract.GetEmployeeTrend(startDate, finishDate);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the supervisor payroll process");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,16 @@ using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, IWarehouseStorageContract warehouseStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, IWarehouseStorageContract warehouseStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
||||
private readonly IWarehouseStorageContract _warehouseStorageContract = warehouseStorageContract;
|
||||
private readonly Lock _lockObject = new();
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
@@ -24,6 +26,46 @@ internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContrac
|
||||
return _saleStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public double CalculateTotalRevenue(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
|
||||
var sales = _saleStorageContract.GetList(fromDate, toDate);
|
||||
|
||||
var salesByDay = sales
|
||||
.Where(x => !x.IsCancel)
|
||||
.GroupBy(x => x.SaleDate.Date)
|
||||
.ToList();
|
||||
|
||||
var revenue = 0.0;
|
||||
|
||||
try
|
||||
{
|
||||
Parallel.ForEach(salesByDay, group =>
|
||||
{
|
||||
var daySum = group.Sum(x => x.Sum - x.Discount);
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
revenue += daySum;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (AggregateException agEx)
|
||||
{
|
||||
foreach (var ex in agEx.InnerExceptions)
|
||||
{
|
||||
_logger.LogError(ex, "Error in the cashier payroll process");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return revenue;
|
||||
}
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByEmployeeByPeriod(string employeeId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSales params: {employeeId}, {fromDate}, {toDate}", employeeId, fromDate, toDate);
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Text.Json;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class SupplyBusinessLogicContract(ISupplyStorageContract supplyStorageContract, IWarehouseStorageContract warehouseStorageContract, ILogger logger) : ISupplyBusinessLogicContract
|
||||
public class SupplyBusinessLogicContract(ISupplyStorageContract supplyStorageContract, IWarehouseStorageContract warehouseStorageContract, ILogger logger) : ISupplyBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISupplyStorageContract _supplyStorageContract = supplyStorageContract;
|
||||
@@ -41,6 +41,27 @@ internal class SupplyBusinessLogicContract(ISupplyStorageContract supplyStorageC
|
||||
return _supplyStorageContract.GetList(fromDate, toDate, cocktailId: cocktailId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public int CountByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
var supplies = _supplyStorageContract.GetList(fromDate, toDate);
|
||||
int count = 0;
|
||||
var lockObject = new object();
|
||||
Parallel.ForEach(supplies, supply =>
|
||||
{
|
||||
int supplyCount = supply.Cocktails.Sum(c => c.Count);
|
||||
if (supplyCount > 0)
|
||||
{
|
||||
Interlocked.Add(ref count, supplyCount);
|
||||
}
|
||||
});
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public SupplyDataModel GetSupplyByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get supply by data: {data}", data);
|
||||
|
||||
@@ -8,16 +8,38 @@ using System.Text.Json;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class WarehouseBusinessLogicContract(IWarehouseStorageContract warehouseStorageContract, ILogger logger) : IWarehouseBusinessLogicContract
|
||||
public class WarehouseBusinessLogicContract(IWarehouseStorageContract warehouseStorageContract, ISupplyStorageContract supplyStorageContract, ISaleStorageContract saleStorageContract, ILogger logger) : IWarehouseBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IWarehouseStorageContract _warehouseStorageContract = warehouseStorageContract;
|
||||
private readonly ISupplyStorageContract _supplyStorageContract = supplyStorageContract;
|
||||
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
||||
|
||||
public List<WarehouseDataModel> GetAllWarehouses()
|
||||
{
|
||||
_logger.LogInformation("GetAllWarehouses");
|
||||
return _warehouseStorageContract.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public async Task<int> GetCocktailStockCountAsync()
|
||||
{
|
||||
var incomingTask = Task.Run(() =>
|
||||
{
|
||||
var supplies = _supplyStorageContract.GetList();
|
||||
return supplies.SelectMany(x => x.Cocktails).Sum(x => x.Count);
|
||||
});
|
||||
|
||||
var outcomingTask = Task.Run(() =>
|
||||
{
|
||||
var sales = _saleStorageContract.GetList();
|
||||
return sales.SelectMany(x => x.Cocktails).Sum(x => x.Count);
|
||||
});
|
||||
|
||||
await Task.WhenAll(incomingTask, outcomingTask);
|
||||
|
||||
return incomingTask.Result - outcomingTask.Result;
|
||||
}
|
||||
|
||||
public WarehouseDataModel GetWarehouseByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SquirrelBusinessLogic", "Sq
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SquirrelDatabase", "SquirrelDatabase\SquirrelDatabase.csproj", "{A8A7A434-A278-4362-8D34-C2E3CAA938C1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SquirrelWebApi", "SquirrelWebApi\SquirrelWebApi.csproj", "{45D1F24F-AFCD-4259-88C2-3076E38254A9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -33,8 +35,15 @@ Global
|
||||
{A8A7A434-A278-4362-8D34-C2E3CAA938C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A8A7A434-A278-4362-8D34-C2E3CAA938C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A8A7A434-A278-4362-8D34-C2E3CAA938C1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{45D1F24F-AFCD-4259-88C2-3076E38254A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{45D1F24F-AFCD-4259-88C2-3076E38254A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{45D1F24F-AFCD-4259-88C2-3076E38254A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{45D1F24F-AFCD-4259-88C2-3076E38254A9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E3B65E92-8603-4ED7-8214-9DA9A305DAFF}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace SquirrelContract.AdapterContracts;
|
||||
using SquirrelContract.AdapterContracts.OperationResponses;
|
||||
using SquirrelContract.BindingModels;
|
||||
|
||||
public interface IClientAdapter
|
||||
{
|
||||
ClientOperationResponse GetList();
|
||||
|
||||
ClientOperationResponse GetElement(string data);
|
||||
|
||||
ClientOperationResponse RegisterClient(ClientBindingModel clientModel);
|
||||
|
||||
ClientOperationResponse ChangeClientInfo(ClientBindingModel clientModel);
|
||||
|
||||
ClientOperationResponse RemoveClient(string id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SquirrelContract.BindingModels;
|
||||
using SquirrelContract.AdapterContracts.OperationResponses;
|
||||
|
||||
namespace SquirrelContract.AdapterContracts;
|
||||
|
||||
public interface ICocktailAdapter
|
||||
{
|
||||
CocktailOperationResponse GetList(bool includeDeleted);
|
||||
|
||||
CocktailOperationResponse GetHistory(string id);
|
||||
|
||||
CocktailOperationResponse GetElement(string data);
|
||||
|
||||
CocktailOperationResponse RegisterCocktail(CocktailBindingModel cocktailModel);
|
||||
|
||||
CocktailOperationResponse ChangeCocktailInfo(CocktailBindingModel cocktailModel);
|
||||
|
||||
CocktailOperationResponse RemoveCocktail(string id);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using SquirrelContract.AdapterContracts.OperationResponses;
|
||||
using SquirrelContract.BindingModels;
|
||||
|
||||
namespace SquirrelContract.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,21 @@
|
||||
using SquirrelContract.AdapterContracts.OperationResponses;
|
||||
using SquirrelContract.BindingModels;
|
||||
|
||||
namespace SquirrelContract.AdapterContracts;
|
||||
|
||||
public interface IPostAdapter
|
||||
{
|
||||
PostOperationResponse GetList();
|
||||
|
||||
PostOperationResponse GetHistory(string id);
|
||||
|
||||
PostOperationResponse GetElement(string data);
|
||||
|
||||
PostOperationResponse RegisterPost(PostBindingModel postModel);
|
||||
|
||||
PostOperationResponse ChangePostInfo(PostBindingModel postModel);
|
||||
|
||||
PostOperationResponse RemovePost(string id);
|
||||
|
||||
PostOperationResponse RestorePost(string id);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using SquirrelContract.AdapterContracts.OperationResponses;
|
||||
|
||||
namespace SquirrelContract.AdapterContracts;
|
||||
|
||||
public interface ISalaryAdapter
|
||||
{
|
||||
SalaryOperationResponse GetListByPeriod(DateTime fromDate, DateTime toDate);
|
||||
SalaryOperationResponse GetListByPeriodByEmployee(DateTime fromDate, DateTime toDate, string employeeId);
|
||||
SalaryOperationResponse CalculateSalary(DateTime date);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using SquirrelContract.AdapterContracts.OperationResponses;
|
||||
using SquirrelContract.BindingModels;
|
||||
|
||||
namespace SquirrelContract.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 GetCocktailList(string id, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleOperationResponse GetElement(string id);
|
||||
|
||||
SaleOperationResponse MakeSale(SaleBindingModel saleModel);
|
||||
|
||||
SaleOperationResponse CancelSale(string id);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SquirrelContract.BindingModels;
|
||||
using SquirrelContract.AdapterContracts.OperationResponses;
|
||||
using SquirrelContract.DataModels;
|
||||
|
||||
namespace SquirrelContract.AdapterContracts;
|
||||
|
||||
public interface ISupplyAdapter
|
||||
{
|
||||
SupplyOperationResponse GetAllSuppliesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
SupplyOperationResponse GetCocktailList(string id, DateTime fromDate, DateTime toDate);
|
||||
SupplyOperationResponse GetSupplyByData(string data);
|
||||
SupplyOperationResponse InsertSupply(SupplyBindingModel supplyDataModel);
|
||||
SupplyOperationResponse UpdateSupply(SupplyBindingModel supplyDataModel);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using SquirrelContract.AdapterContracts.OperationResponses;
|
||||
using SquirrelContract.BindingModels;
|
||||
|
||||
namespace SquirrelContract.AdapterContracts;
|
||||
|
||||
public interface IWarehouseAdapter
|
||||
{
|
||||
WarehouseOperationResponse GetAllWarehouses();
|
||||
WarehouseOperationResponse GetWarehouseByData(string data);
|
||||
WarehouseOperationResponse InsertWarehouse(WarehouseBindingModel warehouseDataModel);
|
||||
WarehouseOperationResponse UpdateWarehouse(WarehouseBindingModel warehouseDataModel);
|
||||
WarehouseOperationResponse DeleteWarehouse(string id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SquirrelContract.ViewModels;
|
||||
using SquirrelContract.Infrastructure;
|
||||
|
||||
namespace SquirrelContract.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,21 @@
|
||||
using SquirrelContract.ViewModels;
|
||||
using SquirrelContract.Infrastructure;
|
||||
|
||||
namespace SquirrelContract.AdapterContracts.OperationResponses;
|
||||
|
||||
public class CocktailOperationResponse : OperationResponse
|
||||
{
|
||||
public static CocktailOperationResponse OK(List<CocktailViewModel> data) => OK<CocktailOperationResponse, List<CocktailViewModel>>(data);
|
||||
|
||||
public static CocktailOperationResponse OK(List<CocktailHistoryViewModel> data) => OK<CocktailOperationResponse, List<CocktailHistoryViewModel>>(data);
|
||||
|
||||
public static CocktailOperationResponse OK(CocktailViewModel data) => OK<CocktailOperationResponse, CocktailViewModel>(data);
|
||||
|
||||
public static CocktailOperationResponse NoContent() => NoContent<CocktailOperationResponse>();
|
||||
|
||||
public static CocktailOperationResponse NotFound(string message) => NotFound<CocktailOperationResponse>(message);
|
||||
|
||||
public static CocktailOperationResponse BadRequest(string message) => BadRequest<CocktailOperationResponse>(message);
|
||||
|
||||
public static CocktailOperationResponse InternalServerError(string message) => InternalServerError<CocktailOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SquirrelContract.ViewModels;
|
||||
using SquirrelContract.Infrastructure;
|
||||
|
||||
namespace SquirrelContract.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,19 @@
|
||||
using SquirrelContract.Infrastructure;
|
||||
using SquirrelContract.ViewModels;
|
||||
|
||||
namespace SquirrelContract.AdapterContracts.OperationResponses;
|
||||
|
||||
public class PostOperationResponse : OperationResponse
|
||||
{
|
||||
public static PostOperationResponse OK(List<PostViewModel> data) => OK<PostOperationResponse, List<PostViewModel>>(data);
|
||||
|
||||
public static PostOperationResponse OK(PostViewModel data) => OK<PostOperationResponse, PostViewModel>(data);
|
||||
|
||||
public static PostOperationResponse NoContent() => NoContent<PostOperationResponse>();
|
||||
|
||||
public static PostOperationResponse NotFound(string message) => NotFound<PostOperationResponse>(message);
|
||||
|
||||
public static PostOperationResponse BadRequest(string message) => BadRequest<PostOperationResponse>(message);
|
||||
|
||||
public static PostOperationResponse InternalServerError(string message) => InternalServerError<PostOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using SquirrelContract.Infrastructure;
|
||||
using SquirrelContract.ViewModels;
|
||||
|
||||
namespace SquirrelContract.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);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SquirrelContract.ViewModels;
|
||||
using SquirrelContract.Infrastructure;
|
||||
|
||||
namespace SquirrelContract.AdapterContracts.OperationResponses;
|
||||
|
||||
public class SaleOperationResponse : OperationResponse
|
||||
{
|
||||
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 NoContent() => NoContent<SaleOperationResponse>();
|
||||
|
||||
public static SaleOperationResponse NotFound(string message) => NotFound<SaleOperationResponse>(message);
|
||||
|
||||
public static SaleOperationResponse BadRequest(string message) => BadRequest<SaleOperationResponse>(message);
|
||||
|
||||
public static SaleOperationResponse InternalServerError(string message) => InternalServerError<SaleOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using SquirrelContract.Infrastructure;
|
||||
using SquirrelContract.ViewModels;
|
||||
|
||||
namespace SquirrelContract.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 SquirrelContract.Infrastructure;
|
||||
using SquirrelContract.ViewModels;
|
||||
|
||||
namespace SquirrelContract.AdapterContracts.OperationResponses;
|
||||
|
||||
public class WarehouseOperationResponse : OperationResponse
|
||||
{
|
||||
public static WarehouseOperationResponse OK(List<WarehouseViewModel> data) => OK<WarehouseOperationResponse, List<WarehouseViewModel>>(data);
|
||||
|
||||
public static WarehouseOperationResponse OK(WarehouseViewModel data) => OK<WarehouseOperationResponse, WarehouseViewModel>(data);
|
||||
|
||||
public static WarehouseOperationResponse NoContent() => NoContent<WarehouseOperationResponse>();
|
||||
|
||||
public static WarehouseOperationResponse NotFound(string message) => NotFound<WarehouseOperationResponse>(message);
|
||||
|
||||
public static WarehouseOperationResponse BadRequest(string message) => BadRequest<WarehouseOperationResponse>(message);
|
||||
|
||||
public static WarehouseOperationResponse InternalServerError(string message) => InternalServerError<WarehouseOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace SquirrelContract.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,9 @@
|
||||
namespace SquirrelContract.BindingModels;
|
||||
|
||||
public class CocktailBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? CocktailName { get; set; }
|
||||
public double Price { get; set; }
|
||||
public string? BaseAlcohol { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace SquirrelContract.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,14 @@
|
||||
namespace SquirrelContract.BindingModels;
|
||||
|
||||
public class PostBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? PostId => Id;
|
||||
|
||||
public string? PostName { get; set; }
|
||||
|
||||
public string? PostType { get; set; }
|
||||
|
||||
public string? ConfigurationJson { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace SquirrelContract.BindingModels;
|
||||
|
||||
public class SaleBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? EmployeeId { get; set; }
|
||||
|
||||
public string? ClientId { get; set; }
|
||||
|
||||
public int DiscountType { get; set; }
|
||||
|
||||
public List<SaleCocktailBindingModel>? Cocktails { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace SquirrelContract.BindingModels;
|
||||
|
||||
public class SaleCocktailBindingModel
|
||||
{
|
||||
public string? SaleId { get; set; }
|
||||
|
||||
public string? CocktailId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SquirrelContract.BindingModels;
|
||||
|
||||
public class SupplyBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public DateTime SupplyDate { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<SupplyCocktailBindingModel>? Cocktails { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SquirrelContract.BindingModels;
|
||||
|
||||
public class SupplyCocktailBindingModel
|
||||
{
|
||||
public string? SupplyId { get; set; }
|
||||
public string? CocktailId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SquirrelContract.BindingModels;
|
||||
|
||||
public class WarehouseBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<WarehouseCocktailBindingModel>? Cocktails { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SquirrelContract.BindingModels;
|
||||
|
||||
public class WarehouseCocktailBindingModel
|
||||
{
|
||||
public string? WarehouseId { get; set; }
|
||||
public string? CocktailId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace SquirrelContract.BusinessLogicContracts;
|
||||
|
||||
public interface IPostBusinessLogicContract
|
||||
{
|
||||
List<PostDataModel> GetAllPosts(bool onlyActive);
|
||||
List<PostDataModel> GetAllPosts();
|
||||
|
||||
List<PostDataModel> GetAllDataOfPost(string postId);
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ public interface ISaleBusinessLogicContract
|
||||
{
|
||||
List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
double CalculateTotalRevenue(DateTime fromDate, DateTime toDate);
|
||||
|
||||
List<SaleDataModel> GetAllSalesByEmployeeByPeriod(string employeeId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
List<SaleDataModel> GetAllSalesByClientByPeriod(string clientId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
@@ -8,6 +8,8 @@ public interface ISupplyBusinessLogicContract
|
||||
|
||||
List<SupplyDataModel> GetAllSuppliesByCocktailByPeriod(string cocktailId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
int CountByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
SupplyDataModel GetSupplyByData(string data);
|
||||
|
||||
void InsertSupply(SupplyDataModel supplyDataModel);
|
||||
|
||||
@@ -6,6 +6,8 @@ public interface IWarehouseBusinessLogicContract
|
||||
{
|
||||
List<WarehouseDataModel> GetAllWarehouses();
|
||||
|
||||
Task<int> GetCocktailStockCountAsync();
|
||||
|
||||
WarehouseDataModel GetWarehouseByData(string data);
|
||||
|
||||
void InsertWarehouse(WarehouseDataModel cocktailDataModel);
|
||||
|
||||
@@ -6,12 +6,22 @@ namespace SquirrelContract.DataModels;
|
||||
|
||||
public class CocktailHistoryDataModel(string cocktailId, double oldPrice) : IValidation
|
||||
{
|
||||
private readonly CocktailDataModel? _cocktail;
|
||||
|
||||
public string CocktailId { get; private set; } = cocktailId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public string CocktailName => _cocktail?.CocktailName ?? string.Empty;
|
||||
|
||||
public CocktailHistoryDataModel(string cocktailId, double oldPrice, DateTime changeDate, CocktailDataModel cocktail) : this(cocktailId, oldPrice)
|
||||
{
|
||||
ChangeDate = changeDate;
|
||||
_cocktail = cocktail;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (CocktailId.IsEmpty())
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace SquirrelContract.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;
|
||||
@@ -21,6 +23,15 @@ public class EmployeeDataModel(string id, string fio, string email, string postI
|
||||
|
||||
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())
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using SquirrelContract.Enums;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using SquirrelContract.Enums;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
using SquirrelContract.Infastructure.PostConfigurations;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class PostDataModel(string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
public class PostDataModel(string postId, string postName, PostType postType, PostConfiguration configuration) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = postId;
|
||||
|
||||
@@ -13,11 +16,21 @@ public class PostDataModel(string postId, string postName, PostType postType, do
|
||||
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
|
||||
public double Salary { get; private set; } = salary;
|
||||
public PostConfiguration ConfigurationModel { get; private set; } = configuration;
|
||||
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
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(BartenderPostConfiguration) => JsonConvert.DeserializeObject<BartenderPostConfiguration>(configurationJson)!,
|
||||
nameof(ManagerPostConfiguration) => JsonConvert.DeserializeObject<ManagerPostConfiguration>(configurationJson)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(configurationJson)!,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
@@ -33,7 +46,9 @@ public class PostDataModel(string postId, string postName, PostType postType, do
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary 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,4 +1,5 @@
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
|
||||
@@ -6,12 +7,21 @@ namespace BarBelochkaContract.DataModels;
|
||||
|
||||
public class SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary) : IValidation
|
||||
{
|
||||
private readonly EmployeeDataModel? _employee;
|
||||
|
||||
public string EmployeeId { get; private set; } = employeeId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = employeeSalary;
|
||||
|
||||
public string EmployeeFIO => _employee?.FIO ?? string.Empty;
|
||||
|
||||
public SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary, EmployeeDataModel employee) : this(employeeId, salaryDate, employeeSalary)
|
||||
{
|
||||
_employee = employee;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (EmployeeId.IsEmpty())
|
||||
|
||||
@@ -4,14 +4,25 @@ using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class SaleCocktailDataModel(string saleId, string cocktailId, int count) : IValidation
|
||||
public class SaleCocktailDataModel(string saleId, string cocktailId, int count, double price) : IValidation
|
||||
{
|
||||
private readonly CocktailDataModel? _cocktail;
|
||||
|
||||
public string SaleId { get; private set; } = saleId;
|
||||
|
||||
public string CocktailId { get; private set; } = cocktailId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public string CocktailName => _cocktail?.CocktailName ?? string.Empty;
|
||||
|
||||
public SaleCocktailDataModel(string saleId, string cocktailId, int count, double price, CocktailDataModel cocktail) : this(saleId, cocktailId, count, price)
|
||||
{
|
||||
_cocktail = cocktail;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SaleId.IsEmpty())
|
||||
@@ -21,12 +32,15 @@ public class SaleCocktailDataModel(string saleId, string cocktailId, int count)
|
||||
throw new ValidationException("The value in the field SaleId is not a unique identifier");
|
||||
|
||||
if (CocktailId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
throw new ValidationException("Field CocktailId is empty");
|
||||
|
||||
if (!CocktailId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
throw new ValidationException("The value in the field CocktailId 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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,25 +5,76 @@ using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class SaleDataModel(string id, string employeeId, string? clientId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleCocktailDataModel> saleCocktails) : IValidation
|
||||
public class SaleDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
private readonly ClientDataModel? _client;
|
||||
|
||||
public string EmployeeId { get; private set; } = employeeId;
|
||||
private readonly EmployeeDataModel? _employee;
|
||||
|
||||
public string? ClientId { get; private set; } = clientId;
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string EmployeeId { get; private set; }
|
||||
|
||||
public string? ClientId { get; private set; }
|
||||
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public double Sum { get; private set; } = sum;
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public DiscountType DiscountType { get; private set; } = discountType;
|
||||
public DiscountType DiscountType { get; private set; }
|
||||
|
||||
public double Discount { get; private set; } = discount;
|
||||
|
||||
public bool IsCancel { get; private set; } = isCancel;
|
||||
public double Discount { get; private set; }
|
||||
|
||||
public List<SaleCocktailDataModel> Cocktails { get; private set; } = saleCocktails;
|
||||
public bool IsCancel { get; private set; }
|
||||
|
||||
public List<SaleCocktailDataModel>? Cocktails { get; private set; }
|
||||
|
||||
public string ClientFIO => _client?.FIO ?? string.Empty;
|
||||
|
||||
public string EmployeeFIO => _employee?.FIO ?? string.Empty;
|
||||
|
||||
public SaleDataModel(string id, string employeeId, string? clientId, DiscountType discountType, bool isCancel, List<SaleCocktailDataModel> saleCocktails)
|
||||
{
|
||||
Id = id;
|
||||
EmployeeId = employeeId;
|
||||
ClientId = clientId;
|
||||
DiscountType = discountType;
|
||||
IsCancel = isCancel;
|
||||
Cocktails = saleCocktails;
|
||||
var percent = 0.0;
|
||||
foreach (DiscountType elem in Enum.GetValues<DiscountType>())
|
||||
{
|
||||
if ((elem & discountType) != 0)
|
||||
{
|
||||
switch (elem)
|
||||
{
|
||||
case DiscountType.None:
|
||||
break;
|
||||
case DiscountType.OnSale:
|
||||
percent += 0.1;
|
||||
break;
|
||||
case DiscountType.RegularCustomer:
|
||||
percent += 0.5;
|
||||
break;
|
||||
case DiscountType.Certificate:
|
||||
percent += 0.3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Sum = Cocktails?.Sum(x => x.Price * x.Count) ?? 0;
|
||||
Discount = Sum * percent;
|
||||
}
|
||||
|
||||
public SaleDataModel(string id, string employeeId, string? clientId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleCocktailDataModel> saleCocktails, EmployeeDataModel employee, ClientDataModel? client) : this(id, employeeId, clientId, discountType, isCancel, saleCocktails)
|
||||
{
|
||||
Sum = sum;
|
||||
Discount = discount;
|
||||
_employee = employee;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public SaleDataModel(string id, string employeeId, string? clientId, int discountType, List<SaleCocktailDataModel> cocktails) : this(id, employeeId, clientId, (DiscountType)discountType, false, cocktails) { }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
@@ -40,7 +91,7 @@ public class SaleDataModel(string id, string employeeId, string? clientId, doubl
|
||||
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");
|
||||
throw new ValidationException("The value in the field ClientId is not a unique identifier");
|
||||
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||
|
||||
@@ -4,7 +4,7 @@ using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class SupplyDataModel(string? id, DateTime supplyDate, List<SupplyCocktailDataModel> cocktails) : IValidation
|
||||
public class SupplyDataModel(string id, DateTime supplyDate, List<SupplyCocktailDataModel> cocktails) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace SquirrelContract.Infastructure;
|
||||
|
||||
public interface IConfigurationSalary
|
||||
{
|
||||
double ExtraSaleSum { get; }
|
||||
int MaxConcurrentThreads { get; }
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
|
||||
namespace SquirrelContract.Infrastructure;
|
||||
|
||||
public class OperationResponse
|
||||
{
|
||||
public HttpStatusCode StatusCode { get; set; }
|
||||
|
||||
public object? Result { get; set; }
|
||||
|
||||
public IActionResult GetResponse(HttpRequest request, HttpResponse response)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
ArgumentNullException.ThrowIfNull(response);
|
||||
|
||||
response.StatusCode = (int)StatusCode;
|
||||
|
||||
if (Result is null)
|
||||
{
|
||||
return new StatusCodeResult((int)StatusCode);
|
||||
}
|
||||
|
||||
return new ObjectResult(Result);
|
||||
}
|
||||
|
||||
protected static TResult OK<TResult, TData>(TData data) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.OK, Result = data };
|
||||
|
||||
protected static TResult NoContent<TResult>() where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.NoContent };
|
||||
|
||||
protected static TResult BadRequest<TResult>(string? errorMessage = null) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.BadRequest, Result = errorMessage };
|
||||
|
||||
protected static TResult NotFound<TResult>(string? errorMessage = null) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.NotFound, Result = errorMessage };
|
||||
|
||||
protected static TResult InternalServerError<TResult>(string? errorMessage = null) where TResult : OperationResponse, new() => new() { StatusCode = HttpStatusCode.InternalServerError, Result = errorMessage };
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace SquirrelContract.Infastructure.PostConfigurations;
|
||||
|
||||
public class BartenderPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(BartenderPostConfiguration);
|
||||
public double SalePercent { get; set; }
|
||||
public double BonusForExtraSales { get; set; }
|
||||
public BartenderPostConfiguration(IConfiguration? config = null)
|
||||
{
|
||||
if (config != null)
|
||||
{
|
||||
config.GetSection("BartenderSettings");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace SquirrelContract.Infastructure.PostConfigurations;
|
||||
|
||||
public class ManagerPostConfiguration : PostConfiguration
|
||||
{
|
||||
public override string Type => nameof(ManagerPostConfiguration);
|
||||
public double PersonalCountTrendPremium { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace SquirrelContract.Infastructure.PostConfigurations;
|
||||
|
||||
public class PostConfiguration
|
||||
{
|
||||
public virtual string Type => nameof(PostConfiguration);
|
||||
public double Rate { get; set; }
|
||||
}
|
||||
@@ -6,4 +6,9 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -17,4 +17,6 @@ public interface IEmployeeStorageContract
|
||||
void UpdElement(EmployeeDataModel employeeDataModel);
|
||||
|
||||
void DelElement(string id);
|
||||
|
||||
int GetEmployeeTrend(DateTime fromPeriod, DateTime toPeriod);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace SquirrelContract.StoragesContracts;
|
||||
|
||||
public interface IPostStorageContract
|
||||
{
|
||||
List<PostDataModel> GetList(bool onlyActual = true);
|
||||
List<PostDataModel> GetList();
|
||||
List<PostDataModel> GetPostWithHistory(string postId);
|
||||
PostDataModel? GetElementById(string id);
|
||||
PostDataModel? GetElementByName(string name);
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace SquirrelContract.StoragesContracts;
|
||||
|
||||
public interface ISalaryStorageContract
|
||||
{
|
||||
List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? employeeId = null);
|
||||
List<SalaryDataModel> GetList(DateTime? startDate, DateTime? endDate, string? employeeId = null);
|
||||
|
||||
void AddElement(SalaryDataModel salaryDataModel);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class ClientViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string FIO { get; set; }
|
||||
|
||||
public required string PhoneNumber { get; set; }
|
||||
|
||||
public double DiscountSize { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class CocktailHistoryViewModel
|
||||
{
|
||||
public required string CocktailName { get; set; }
|
||||
|
||||
public double OldPrice { get; set; }
|
||||
|
||||
public DateTime ChangeDate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class CocktailViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string CocktailName { get; set; }
|
||||
|
||||
public required string BaseAlcohol { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class EmployeeViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string FIO { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public required string PostId { get; set; }
|
||||
|
||||
public required string PostName { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class PostViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string PostName { get; set; }
|
||||
|
||||
public required string PostType { get; set; }
|
||||
|
||||
public required string Configuration { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class SalaryViewModel
|
||||
{
|
||||
public required string EmployeeId { get; set; }
|
||||
public required string EmployeeFIO { get; set; }
|
||||
public DateTime SalaryDate { get; set; }
|
||||
public double Salary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class SaleCocktailViewModel
|
||||
{
|
||||
public required string CocktailId { get; set; }
|
||||
|
||||
public required string CocktailName { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class SaleViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string EmployeeId { get; set; }
|
||||
|
||||
public required string EmployeeFIO { get; set; }
|
||||
|
||||
public string? ClientId { get; set; }
|
||||
|
||||
public string? ClientFIO { get; set; }
|
||||
|
||||
public DateTime SaleDate { get; set; }
|
||||
|
||||
public double Sum { get; set; }
|
||||
|
||||
public required string DiscountType { get; set; }
|
||||
|
||||
public double Discount { get; set; }
|
||||
|
||||
public bool IsCancel { get; set; }
|
||||
|
||||
public required List<SaleCocktailViewModel> Cocktails { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class SupplyCocktailViewModel
|
||||
{
|
||||
public required string SupplyId { get; set; }
|
||||
public required string CocktailId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class SupplyViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public DateTime SupplyDate { get; set; }
|
||||
public int Count { get; set; }
|
||||
public required List<SupplyCocktailViewModel> Cocktails { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class WarehouseCocktailViewModel
|
||||
{
|
||||
public required string WarehouseId { get; set; }
|
||||
public required string CocktailId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SquirrelContract.ViewModels;
|
||||
|
||||
public class WarehouseViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public required int Count { get; set; }
|
||||
public required List<WarehouseCocktailViewModel> Cocktails { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelDatabase;
|
||||
|
||||
class DefaultConfigurationDatabase : IConfigurationDatabase
|
||||
{
|
||||
public string ConnectionString => "";
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class CocktailStorageContract : ICocktailStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.CocktailHistories.Where(x => x.CocktailId == cocktailId).OrderByDescending(x => x.ChangeDate).Select(x => _mapper.Map<CocktailHistoryDataModel>(x))];
|
||||
return [.. _dbContext.CocktailHistories.Include(x => x.Cocktail).Where(x => x.CocktailId == cocktailId).OrderByDescending(x => x.ChangeDate).Select(x => _mapper.Map<CocktailHistoryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -105,20 +105,35 @@ public class CocktailStorageContract : ICocktailStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetCocktailById(cocktailDataModel.Id) ?? throw new ElementNotFoundException(cocktailDataModel.Id);
|
||||
_dbContext.Cocktails.Update(_mapper.Map(cocktailDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var element = GetCocktailById(cocktailDataModel.Id) ?? throw new ElementNotFoundException(cocktailDataModel.Id);
|
||||
if (element.Price != cocktailDataModel.Price)
|
||||
{
|
||||
_dbContext.CocktailHistories.Add(new CocktailHistory() { CocktailId = element.Id, OldPrice = element.Price });
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
_dbContext.Cocktails.Update(_mapper.Map(cocktailDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Cocktails_CocktailName" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("CocktailName", cocktailDataModel.CocktailName);
|
||||
}
|
||||
catch (Exception ex) when (ex is ElementDeletedException || ex is ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
|
||||
@@ -16,7 +16,10 @@ public class EmployeeStorageContract : IEmployeeStorageContract
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddMaps(typeof(SquirrelDbContext).Assembly);
|
||||
cfg.CreateMap<Post, PostDataModel>()
|
||||
.ForMember(x => x.Id, x => x.MapFrom(src => src.PostId));
|
||||
cfg.CreateMap<Employee, EmployeeDataModel>();
|
||||
cfg.CreateMap<EmployeeDataModel, Employee>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
@@ -36,13 +39,13 @@ public class EmployeeStorageContract : IEmployeeStorageContract
|
||||
}
|
||||
if (fromBirthDate is not null && toBirthDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.BirthDate >= fromBirthDate && x.BirthDate <= toBirthDate);
|
||||
query = query.Where(x => x.BirthDate >= DateTime.SpecifyKind(fromBirthDate ?? DateTime.UtcNow, DateTimeKind.Utc) && x.BirthDate <= DateTime.SpecifyKind(toBirthDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
}
|
||||
if (fromEmploymentDate is not null && toEmploymentDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.EmploymentDate >= fromEmploymentDate && x.EmploymentDate <= toEmploymentDate);
|
||||
query = query.Where(x => x.EmploymentDate >= DateTime.SpecifyKind(fromEmploymentDate ?? DateTime.UtcNow, DateTimeKind.Utc) && x.EmploymentDate <= DateTime.SpecifyKind(toEmploymentDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<EmployeeDataModel>(x))];
|
||||
return [.. JoinPost(query).Select(x => _mapper.Map<EmployeeDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -68,7 +71,7 @@ public class EmployeeStorageContract : IEmployeeStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<EmployeeDataModel>(_dbContext.Employees.FirstOrDefault(x => x.FIO == fio));
|
||||
return _mapper.Map<EmployeeDataModel>(AddPost(_dbContext.Employees.FirstOrDefault(x => x.FIO == fio && !x.IsDeleted)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -81,7 +84,7 @@ public class EmployeeStorageContract : IEmployeeStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<EmployeeDataModel>(_dbContext.Employees.FirstOrDefault(x => x.Email == email));
|
||||
return _mapper.Map<EmployeeDataModel>(AddPost(_dbContext.Employees.FirstOrDefault(x => x.Email == email && !x.IsDeleted)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -149,5 +152,27 @@ public class EmployeeStorageContract : IEmployeeStorageContract
|
||||
}
|
||||
}
|
||||
|
||||
private Employee? GetEmployeeById(string id) => _dbContext.Employees.FirstOrDefault(x => x.Id == id && !x.IsDeleted);
|
||||
public int GetEmployeeTrend(DateTime fromPeriod, DateTime toPeriod)
|
||||
{
|
||||
try
|
||||
{
|
||||
var countWorkersOnBegining = _dbContext.Employees.Count(x => x.EmploymentDate < fromPeriod && (!x.IsDeleted || x.DateOfDelete > fromPeriod));
|
||||
var countWorkersOnEnding = _dbContext.Employees.Count(x => x.EmploymentDate < toPeriod && (!x.IsDeleted || x.DateOfDelete > toPeriod));
|
||||
return countWorkersOnEnding - countWorkersOnBegining;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Employee? GetEmployeeById(string id) => AddPost(_dbContext.Employees.FirstOrDefault(x => x.Id == id && !x.IsDeleted));
|
||||
|
||||
private IQueryable<Employee> JoinPost(IQueryable<Employee> query)
|
||||
=> query.GroupJoin(_dbContext.Posts.Where(x => x.IsActual), x => x.PostId, y => y.PostId, (x, y) => new { Employee = x, Post = y })
|
||||
.SelectMany(xy => xy.Post.DefaultIfEmpty(), (x, y) => x.Employee.AddPost(y));
|
||||
|
||||
private Employee? AddPost(Employee? employee)
|
||||
=> employee?.AddPost(_dbContext.Posts.FirstOrDefault(x => x.PostId == employee.PostId && x.IsActual));
|
||||
}
|
||||
|
||||
@@ -24,21 +24,18 @@ public class PostStorageContract : IPostStorageContract
|
||||
.ForMember(x => x.Id, x => x.Ignore())
|
||||
.ForMember(x => x.PostId, x => x.MapFrom(src => src.Id))
|
||||
.ForMember(x => x.IsActual, x => x.MapFrom(src => true))
|
||||
.ForMember(x => x.ChangeDate, x => x.MapFrom(src => DateTime.UtcNow));
|
||||
.ForMember(x => x.ChangeDate, x => x.MapFrom(src => DateTime.UtcNow))
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src =>
|
||||
src.ConfigurationModel));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetList(bool onlyActual = true)
|
||||
public List<PostDataModel> GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Posts.AsQueryable();
|
||||
if (onlyActual)
|
||||
{
|
||||
query = query.Where(x => x.IsActual);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<PostDataModel>(x))];
|
||||
return [.. _dbContext.Posts.Select(x => _mapper.Map<PostDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using AutoMapper;
|
||||
using BarBelochkaContract.DataModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
using SquirrelDatabase.Models;
|
||||
@@ -16,6 +18,7 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Employee, EmployeeDataModel>();
|
||||
cfg.CreateMap<Salary, SalaryDataModel>();
|
||||
cfg.CreateMap<SalaryDataModel, Salary>()
|
||||
.ForMember(dest => dest.EmployeeSalary, opt => opt.MapFrom(src => src.Salary));
|
||||
@@ -23,15 +26,17 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? employeeId = null)
|
||||
public List<SalaryDataModel> GetList(DateTime? startDate, DateTime? endDate, string? employeeId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Salaries.Where(x => x.SalaryDate >= startDate && x.SalaryDate <= endDate);
|
||||
if (employeeId is not null)
|
||||
{
|
||||
var query = _dbContext.Salaries.Include(d => d.Employee).AsQueryable();
|
||||
if (startDate.HasValue)
|
||||
query = query.Where(x => x.SalaryDate >= DateTime.SpecifyKind(startDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (endDate.HasValue)
|
||||
query = query.Where(x => x.SalaryDate <= DateTime.SpecifyKind(endDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (employeeId != null)
|
||||
query = query.Where(x => x.EmployeeId == employeeId);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<SalaryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -4,6 +4,8 @@ using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
using SquirrelDatabase.Models;
|
||||
using System;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SquirrelDatabase.Implementations;
|
||||
|
||||
@@ -16,13 +18,19 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
{
|
||||
cfg.CreateMap<Client, ClientDataModel>();
|
||||
cfg.CreateMap<Cocktail, CocktailDataModel>();
|
||||
cfg.CreateMap<Employee, EmployeeDataModel>();
|
||||
cfg.CreateMap<SaleCocktail, SaleCocktailDataModel>();
|
||||
cfg.CreateMap<SaleCocktailDataModel, SaleCocktail>();
|
||||
cfg.CreateMap<SaleCocktailDataModel, SaleCocktail>()
|
||||
.ForMember(x => x.Cocktail, x => x.Ignore());
|
||||
cfg.CreateMap<Sale, SaleDataModel>();
|
||||
cfg.CreateMap<SaleDataModel, Sale>()
|
||||
.ForMember(x => x.IsCancel, x => x.MapFrom(src => false))
|
||||
.ForMember(x => x.SaleCocktails, x => x.MapFrom(src => src.Cocktails));
|
||||
.ForMember(x => x.SaleCocktails, x => x.MapFrom(src => src.Cocktails))
|
||||
.ForMember(x => x.Employee, x => x.Ignore())
|
||||
.ForMember(x => x.Client, x => x.Ignore());
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
@@ -31,23 +39,23 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Sales.Include(x => x.SaleCocktails).AsQueryable();
|
||||
if (startDate is not null && endDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.SaleDate >= startDate && x.SaleDate < endDate);
|
||||
}
|
||||
if (employeeId is not null)
|
||||
{
|
||||
var query = _dbContext.Sales
|
||||
.Include(r => r.Employee)
|
||||
.Include(r => r.Client)
|
||||
.Include(r => r.SaleCocktails)!
|
||||
.ThenInclude(d => d.Cocktail)
|
||||
.AsQueryable();
|
||||
if (startDate.HasValue)
|
||||
query = query.Where(x => x.SaleDate >= DateTime.SpecifyKind(startDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (endDate.HasValue)
|
||||
query = query.Where(x => x.SaleDate <= DateTime.SpecifyKind(endDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (employeeId != null)
|
||||
query = query.Where(x => x.EmployeeId == employeeId);
|
||||
}
|
||||
if (clientId is not null)
|
||||
{
|
||||
if (clientId != null)
|
||||
query = query.Where(x => x.ClientId == clientId);
|
||||
}
|
||||
if (cocktailId is not null)
|
||||
{
|
||||
if (cocktailId != null)
|
||||
query = query.Where(x => x.SaleCocktails!.Any(y => y.CocktailId == cocktailId));
|
||||
}
|
||||
var s = query.ToList();
|
||||
return [.. query.Select(x => _mapper.Map<SaleDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -108,5 +116,5 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
}
|
||||
}
|
||||
|
||||
private Sale? GetSaleById(string id) => _dbContext.Sales.FirstOrDefault(x => x.Id == id);
|
||||
private Sale? GetSaleById(string id) => _dbContext.Sales.Include(x => x.Client).Include(x => x.Employee).Include(x => x.SaleCocktails)!.ThenInclude(x => x.Cocktail).FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ public class SupplyStorageContract : ISupplyStorageContract
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Supplies.Include(x => x.Cocktails).AsQueryable();
|
||||
if (startDate is not null && endDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.SupplyDate >= startDate && x.SupplyDate < endDate);
|
||||
}
|
||||
if (startDate.HasValue)
|
||||
query = query.Where(x => x.SupplyDate >= DateTime.SpecifyKind(startDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (endDate.HasValue)
|
||||
query = query.Where(x => x.SupplyDate <= DateTime.SpecifyKind(endDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (cocktailId is not null)
|
||||
{
|
||||
query = query.Where(x => x.Cocktails!.Any(y => y.CocktailId == cocktailId));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
@@ -121,7 +122,9 @@ public class WarehouseStorageContract : IWarehouseStorageContract
|
||||
using var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var warehouse = _dbContext.Warehouses.FirstOrDefault(w => w.Id == warehouseId);
|
||||
var warehouse = _dbContext.Warehouses
|
||||
.Include(w => w.Cocktails)
|
||||
.FirstOrDefault(w => w.Id == warehouseId);
|
||||
if (warehouse == null)
|
||||
{
|
||||
throw new ElementNotFoundException($"Warehouse with id {warehouseId} not found.");
|
||||
@@ -165,7 +168,7 @@ public class WarehouseStorageContract : IWarehouseStorageContract
|
||||
{
|
||||
int requiredCount = saleCocktail.Count;
|
||||
|
||||
var warehousesWithCocktail = _dbContext.Warehouses
|
||||
var warehousesWithCocktail = _dbContext.Warehouses.Include(w => w.Cocktails)
|
||||
.Where(w => w.Cocktails.Any(c => c.CocktailId == saleCocktail.CocktailId && c.Count > 0))
|
||||
.ToList();
|
||||
|
||||
|
||||
330
SquirrelContract/SquirrelDatabase/Migrations/20250407181533_FirstMigration.Designer.cs
generated
Normal file
330
SquirrelContract/SquirrelDatabase/Migrations/20250407181533_FirstMigration.Designer.cs
generated
Normal file
@@ -0,0 +1,330 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SquirrelDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SquirrelDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SquirrelDbContext))]
|
||||
[Migration("20250407181533_FirstMigration")]
|
||||
partial class FirstMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("DiscountSize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PhoneNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Cocktail", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("BaseAlcohol")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("CocktailName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Cocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.CocktailHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("CocktailId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("CocktailHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Employee", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Salary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("EmployeeId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("EmployeeSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ClientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Discount")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("DiscountType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("EmployeeId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsCancel")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime>("SaleDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.SaleCocktail", b =>
|
||||
{
|
||||
b.Property<string>("SaleId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("CocktailId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("SaleId", "CocktailId");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("SaleCocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.CocktailHistory", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Cocktail", "Cocktail")
|
||||
.WithMany("CocktailHistories")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Employee", "Employee")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Client", "Client")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("SquirrelDatabase.Models.Employee", "Employee")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.SaleCocktail", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Cocktail", "Cocktail")
|
||||
.WithMany("SaleCocktails")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SquirrelDatabase.Models.Sale", "Sale")
|
||||
.WithMany("SaleCocktails")
|
||||
.HasForeignKey("SaleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
|
||||
b.Navigation("Sale");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Cocktail", b =>
|
||||
{
|
||||
b.Navigation("CocktailHistories");
|
||||
|
||||
b.Navigation("SaleCocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Employee", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.Navigation("SaleCocktails");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SquirrelDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FirstMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Clients",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
FIO = table.Column<string>(type: "text", nullable: false),
|
||||
PhoneNumber = table.Column<string>(type: "text", nullable: false),
|
||||
DiscountSize = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Clients", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Cocktails",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
CocktailName = table.Column<string>(type: "text", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false),
|
||||
BaseAlcohol = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Cocktails", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Employees",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
FIO = table.Column<string>(type: "text", nullable: false),
|
||||
Email = table.Column<string>(type: "text", nullable: false),
|
||||
PostId = table.Column<string>(type: "text", nullable: false),
|
||||
BirthDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
EmploymentDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "boolean", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Employees", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Posts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
PostId = table.Column<string>(type: "text", nullable: false),
|
||||
PostName = table.Column<string>(type: "text", nullable: false),
|
||||
PostType = table.Column<int>(type: "integer", nullable: false),
|
||||
Salary = table.Column<double>(type: "double precision", nullable: false),
|
||||
IsActual = table.Column<bool>(type: "boolean", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Posts", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CocktailHistories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
CocktailId = table.Column<string>(type: "text", nullable: false),
|
||||
OldPrice = table.Column<double>(type: "double precision", nullable: false),
|
||||
ChangeDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CocktailHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_CocktailHistories_Cocktails_CocktailId",
|
||||
column: x => x.CocktailId,
|
||||
principalTable: "Cocktails",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Salaries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
EmployeeId = table.Column<string>(type: "text", nullable: false),
|
||||
SalaryDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
EmployeeSalary = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Salaries", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Salaries_Employees_EmployeeId",
|
||||
column: x => x.EmployeeId,
|
||||
principalTable: "Employees",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Sales",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
EmployeeId = table.Column<string>(type: "text", nullable: false),
|
||||
ClientId = table.Column<string>(type: "text", nullable: true),
|
||||
SaleDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
DiscountType = table.Column<int>(type: "integer", nullable: false),
|
||||
Discount = table.Column<double>(type: "double precision", nullable: false),
|
||||
IsCancel = table.Column<bool>(type: "boolean", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Sales", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Sales_Clients_ClientId",
|
||||
column: x => x.ClientId,
|
||||
principalTable: "Clients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "FK_Sales_Employees_EmployeeId",
|
||||
column: x => x.EmployeeId,
|
||||
principalTable: "Employees",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SaleCocktails",
|
||||
columns: table => new
|
||||
{
|
||||
SaleId = table.Column<string>(type: "text", nullable: false),
|
||||
CocktailId = table.Column<string>(type: "text", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SaleCocktails", x => new { x.SaleId, x.CocktailId });
|
||||
table.ForeignKey(
|
||||
name: "FK_SaleCocktails_Cocktails_CocktailId",
|
||||
column: x => x.CocktailId,
|
||||
principalTable: "Cocktails",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_SaleCocktails_Sales_SaleId",
|
||||
column: x => x.SaleId,
|
||||
principalTable: "Sales",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Clients_PhoneNumber",
|
||||
table: "Clients",
|
||||
column: "PhoneNumber",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CocktailHistories_CocktailId",
|
||||
table: "CocktailHistories",
|
||||
column: "CocktailId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Cocktails_CocktailName",
|
||||
table: "Cocktails",
|
||||
column: "CocktailName",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Posts_PostId_IsActual",
|
||||
table: "Posts",
|
||||
columns: new[] { "PostId", "IsActual" },
|
||||
unique: true,
|
||||
filter: "\"IsActual\" = TRUE");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Posts_PostName_IsActual",
|
||||
table: "Posts",
|
||||
columns: new[] { "PostName", "IsActual" },
|
||||
unique: true,
|
||||
filter: "\"IsActual\" = TRUE");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_EmployeeId",
|
||||
table: "Salaries",
|
||||
column: "EmployeeId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SaleCocktails_CocktailId",
|
||||
table: "SaleCocktails",
|
||||
column: "CocktailId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Sales_ClientId",
|
||||
table: "Sales",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Sales_EmployeeId",
|
||||
table: "Sales",
|
||||
column: "EmployeeId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "CocktailHistories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Posts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Salaries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "SaleCocktails");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Cocktails");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Sales");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Employees");
|
||||
}
|
||||
}
|
||||
}
|
||||
331
SquirrelContract/SquirrelDatabase/Migrations/20250407203820_ChangeFieldsInPost.Designer.cs
generated
Normal file
331
SquirrelContract/SquirrelDatabase/Migrations/20250407203820_ChangeFieldsInPost.Designer.cs
generated
Normal file
@@ -0,0 +1,331 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SquirrelDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SquirrelDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SquirrelDbContext))]
|
||||
[Migration("20250407203820_ChangeFieldsInPost")]
|
||||
partial class ChangeFieldsInPost
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("DiscountSize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PhoneNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Cocktail", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("BaseAlcohol")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("CocktailName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Cocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.CocktailHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("CocktailId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("CocktailHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Employee", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("EmployeeId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("EmployeeSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ClientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Discount")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("DiscountType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("EmployeeId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsCancel")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime>("SaleDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.SaleCocktail", b =>
|
||||
{
|
||||
b.Property<string>("SaleId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("CocktailId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("SaleId", "CocktailId");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("SaleCocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.CocktailHistory", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Cocktail", "Cocktail")
|
||||
.WithMany("CocktailHistories")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Employee", "Employee")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Client", "Client")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("SquirrelDatabase.Models.Employee", "Employee")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.SaleCocktail", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Cocktail", "Cocktail")
|
||||
.WithMany("SaleCocktails")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SquirrelDatabase.Models.Sale", "Sale")
|
||||
.WithMany("SaleCocktails")
|
||||
.HasForeignKey("SaleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
|
||||
b.Navigation("Sale");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Cocktail", b =>
|
||||
{
|
||||
b.Navigation("CocktailHistories");
|
||||
|
||||
b.Navigation("SaleCocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Employee", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.Navigation("SaleCocktails");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SquirrelDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ChangeFieldsInPost : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Salary",
|
||||
table: "Posts");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Configuration",
|
||||
table: "Posts",
|
||||
type: "jsonb",
|
||||
nullable: false,
|
||||
defaultValue: "{\"Rate\": 0, \"Type\": \"PostConfiguration\"}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Configuration",
|
||||
table: "Posts");
|
||||
|
||||
migrationBuilder.AddColumn<double>(
|
||||
name: "Salary",
|
||||
table: "Posts",
|
||||
type: "double precision",
|
||||
nullable: false,
|
||||
defaultValue: 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
334
SquirrelContract/SquirrelDatabase/Migrations/20250408214441_ChangeEmployee.Designer.cs
generated
Normal file
334
SquirrelContract/SquirrelDatabase/Migrations/20250408214441_ChangeEmployee.Designer.cs
generated
Normal file
@@ -0,0 +1,334 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SquirrelDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SquirrelDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SquirrelDbContext))]
|
||||
[Migration("20250408214441_ChangeEmployee")]
|
||||
partial class ChangeEmployee
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("DiscountSize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PhoneNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Cocktail", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("BaseAlcohol")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("CocktailName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Cocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.CocktailHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("CocktailId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("CocktailHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Employee", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateOfDelete")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("EmployeeId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("EmployeeSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ClientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Discount")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("DiscountType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("EmployeeId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsCancel")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime>("SaleDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.SaleCocktail", b =>
|
||||
{
|
||||
b.Property<string>("SaleId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("CocktailId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("SaleId", "CocktailId");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("SaleCocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.CocktailHistory", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Cocktail", "Cocktail")
|
||||
.WithMany("CocktailHistories")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Employee", "Employee")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Client", "Client")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("SquirrelDatabase.Models.Employee", "Employee")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.SaleCocktail", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Cocktail", "Cocktail")
|
||||
.WithMany("SaleCocktails")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SquirrelDatabase.Models.Sale", "Sale")
|
||||
.WithMany("SaleCocktails")
|
||||
.HasForeignKey("SaleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
|
||||
b.Navigation("Sale");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Cocktail", b =>
|
||||
{
|
||||
b.Navigation("CocktailHistories");
|
||||
|
||||
b.Navigation("SaleCocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Employee", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.Navigation("SaleCocktails");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SquirrelDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ChangeEmployee : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "DateOfDelete",
|
||||
table: "Employees",
|
||||
type: "timestamp without time zone",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DateOfDelete",
|
||||
table: "Employees");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SquirrelDatabase;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SquirrelDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(SquirrelDbContext))]
|
||||
partial class SquirrelDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("DiscountSize")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PhoneNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Cocktail", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("BaseAlcohol")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("CocktailName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Cocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.CocktailHistory", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("CocktailId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("OldPrice")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("CocktailHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Employee", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateOfDelete")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("EmploymentDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Post", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("ChangeDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<string>("Configuration")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b.Property<bool>("IsActual")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("PostId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PostName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PostType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PostId", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.HasIndex("PostName", "IsActual")
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsActual\" = TRUE");
|
||||
|
||||
b.ToTable("Posts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("EmployeeId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("EmployeeSalary")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("SalaryDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ClientId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Discount")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("DiscountType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("EmployeeId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsCancel")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime>("SaleDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.SaleCocktail", b =>
|
||||
{
|
||||
b.Property<string>("SaleId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("CocktailId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("SaleId", "CocktailId");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("SaleCocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.CocktailHistory", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Cocktail", "Cocktail")
|
||||
.WithMany("CocktailHistories")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Employee", "Employee")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Client", "Client")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("SquirrelDatabase.Models.Employee", "Employee")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.SaleCocktail", b =>
|
||||
{
|
||||
b.HasOne("SquirrelDatabase.Models.Cocktail", "Cocktail")
|
||||
.WithMany("SaleCocktails")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SquirrelDatabase.Models.Sale", "Sale")
|
||||
.WithMany("SaleCocktails")
|
||||
.HasForeignKey("SaleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
|
||||
b.Navigation("Sale");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Cocktail", b =>
|
||||
{
|
||||
b.Navigation("CocktailHistories");
|
||||
|
||||
b.Navigation("SaleCocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Employee", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SquirrelDatabase.Models.Sale", b =>
|
||||
{
|
||||
b.Navigation("SaleCocktails");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class Employee
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public string PostId { get; set; }
|
||||
public required string PostId { get; set; }
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
@@ -21,9 +21,20 @@ public class Employee
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public DateTime? DateOfDelete { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public Post? Post { get; set; }
|
||||
|
||||
[ForeignKey("EmployeeId")]
|
||||
public List<Salary>? Salaries { get; set; }
|
||||
|
||||
[ForeignKey("EmployeeId")]
|
||||
public List<Sale>? Sales { get; set; }
|
||||
|
||||
public Employee AddPost(Post? post)
|
||||
{
|
||||
Post = post;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using AutoMapper;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Enums;
|
||||
using SquirrelContract.Infastructure.PostConfigurations;
|
||||
|
||||
namespace SquirrelDatabase.Models;
|
||||
|
||||
@@ -14,7 +15,7 @@ public class Post
|
||||
|
||||
public PostType PostType { get; set; }
|
||||
|
||||
public double Salary { get; set; }
|
||||
public required PostConfiguration Configuration { get; set; }
|
||||
|
||||
public bool IsActual { get; set; }
|
||||
|
||||
|
||||
@@ -7,4 +7,10 @@ public class SaleCocktail
|
||||
public required string CocktailId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public Sale? Sale { get; set; }
|
||||
|
||||
public Cocktail? Cocktail { get; set; }
|
||||
}
|
||||
|
||||
12
SquirrelContract/SquirrelDatabase/SampleContextFactory.cs
Normal file
12
SquirrelContract/SquirrelDatabase/SampleContextFactory.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using SquirrelDatabase;
|
||||
|
||||
namespace SquirrelDatabase;
|
||||
|
||||
public class SampleContextFactory : IDesignTimeDbContextFactory<SquirrelDbContext>
|
||||
{
|
||||
public SquirrelDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
return new SquirrelDbContext(new DefaultConfigurationDatabase());
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -17,4 +22,10 @@
|
||||
<ProjectReference Include="..\SquirrelContract\SquirrelContract.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="SquirrelTests" />
|
||||
<InternalVisibleTo Include="SquirrelWebApi" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SquirrelContract.Infastructure;
|
||||
using SquirrelContract.Infastructure.PostConfigurations;
|
||||
using SquirrelDatabase.Models;
|
||||
|
||||
namespace SquirrelDatabase;
|
||||
|
||||
public class SquirrelDbContext(IConfigurationDatabase configurationDatabase) : DbContext
|
||||
public class SquirrelDbContext: DbContext
|
||||
{
|
||||
private readonly IConfigurationDatabase? _configurationDatabase = configurationDatabase;
|
||||
private readonly IConfigurationDatabase? _configurationDatabase;
|
||||
|
||||
public SquirrelDbContext(IConfigurationDatabase configurationDatabase)
|
||||
{
|
||||
_configurationDatabase = configurationDatabase;
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(_configurationDatabase?.ConnectionString, o => o.SetPostgresVersion(12, 2));
|
||||
optionsBuilder.UseNpgsql(_configurationDatabase?.ConnectionString, o
|
||||
=> o.SetPostgresVersion(12, 2));
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
@@ -20,6 +31,11 @@ public class SquirrelDbContext(IConfigurationDatabase configurationDatabase) : D
|
||||
|
||||
modelBuilder.Entity<Client>().HasIndex(x => x.PhoneNumber).IsUnique();
|
||||
|
||||
modelBuilder.Entity<Sale>()
|
||||
.HasOne(e => e.Client)
|
||||
.WithMany(e => e.Sales)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
modelBuilder.Entity<Cocktail>().HasIndex(x => x.CocktailName).IsUnique();
|
||||
|
||||
modelBuilder.Entity<Post>()
|
||||
@@ -39,6 +55,13 @@ public class SquirrelDbContext(IConfigurationDatabase configurationDatabase) : D
|
||||
modelBuilder.Entity<WarehouseCocktail>().HasKey(x => new { x.WarehouseId, x.CocktailId });
|
||||
|
||||
modelBuilder.Entity<SaleCocktail>().HasKey(x => new { x.SaleId, x.CocktailId });
|
||||
|
||||
modelBuilder.Entity<Post>()
|
||||
.Property(x => x.Configuration)
|
||||
.HasColumnType("jsonb")
|
||||
.HasConversion(
|
||||
x => SerializePostConfiguration(x),
|
||||
x => DeserialzePostConfiguration(x));
|
||||
}
|
||||
|
||||
public DbSet<Client> Clients { get; set; }
|
||||
@@ -64,4 +87,12 @@ public class SquirrelDbContext(IConfigurationDatabase configurationDatabase) : D
|
||||
public DbSet<SupplyCocktail> SupplyCocktails { get; set; }
|
||||
|
||||
public DbSet<WarehouseCocktail> WarehouseCocktails { get; set; }
|
||||
|
||||
private static string SerializePostConfiguration(PostConfiguration postConfiguration) => JsonConvert.SerializeObject(postConfiguration);
|
||||
private static PostConfiguration DeserialzePostConfiguration(string jsonString) => JToken.Parse(jsonString).Value<string>("Type") switch
|
||||
{
|
||||
nameof(BartenderPostConfiguration) => JsonConvert.DeserializeObject<BartenderPostConfiguration>(jsonString)!,
|
||||
nameof(ManagerPostConfiguration) => JsonConvert.DeserializeObject<ManagerPostConfiguration>(jsonString)!,
|
||||
_ => JsonConvert.DeserializeObject<PostConfiguration>(jsonString)!,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using SquirrelBusinessLogic.Implementations;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Enums;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Infastructure.PostConfigurations;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
|
||||
namespace SquirrelTests.BusinessLogicContractsTests;
|
||||
@@ -33,61 +34,53 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
var listOriginal = new List<PostDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(),"name 1", PostType.Manager, 10, true, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), "name 2", PostType.Manager, 10, false, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), "name 3", PostType.Manager, 10, true, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(),"name 1", PostType.Bartender, new PostConfiguration() { Rate = 10 }),
|
||||
new(Guid.NewGuid().ToString(), "name 2", PostType.Bartender, new PostConfiguration() { Rate = 10 }),
|
||||
new(Guid.NewGuid().ToString(), "name 3", PostType.Bartender, new PostConfiguration() { Rate = 10 }),
|
||||
};
|
||||
_postStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Returns(listOriginal);
|
||||
_postStorageContract.Setup(x => x.GetList()).Returns(listOriginal);
|
||||
//Act
|
||||
var listOnlyActive = _postBusinessLogicContract.GetAllPosts(true);
|
||||
var listAll = _postBusinessLogicContract.GetAllPosts(false);
|
||||
var list = _postBusinessLogicContract.GetAllPosts();
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(listAll, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal));
|
||||
Assert.That(listAll, Is.EquivalentTo(listOriginal));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
});
|
||||
_postStorageContract.Verify(x => x.GetList(true), Times.Once);
|
||||
_postStorageContract.Verify(x => x.GetList(false), Times.Once);
|
||||
_postStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Returns([]);
|
||||
_postStorageContract.Setup(x => x.GetList()).Returns([]);
|
||||
//Act
|
||||
var listOnlyActive = _postBusinessLogicContract.GetAllPosts(true);
|
||||
var listAll = _postBusinessLogicContract.GetAllPosts(false);
|
||||
var list = _postBusinessLogicContract.GetAllPosts();
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(listAll, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Has.Count.EqualTo(0));
|
||||
Assert.That(listAll, Has.Count.EqualTo(0));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
});
|
||||
_postStorageContract.Verify(x => x.GetList(It.IsAny<bool>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_postStorageContract.Verify(x => x.GetList(It.IsAny<bool>()), Times.Once);
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(), Throws.TypeOf<NullListException>());
|
||||
_postStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.GetList(It.IsAny<bool>()), Times.Once);
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -97,8 +90,8 @@ internal class PostBusinessLogicContractTests
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<PostDataModel>()
|
||||
{
|
||||
new(postId, "name 1", PostType.Manager, 10, true, DateTime.UtcNow),
|
||||
new(postId, "name 2", PostType.Manager, 10, false, DateTime.UtcNow)
|
||||
new(postId, "name 1", PostType.Bartender, new PostConfiguration() { Rate = 10 }),
|
||||
new(postId, "name 2", PostType.Bartender, new PostConfiguration() { Rate = 10 })
|
||||
};
|
||||
_postStorageContract.Setup(x => x.GetPostWithHistory(It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -162,7 +155,7 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new PostDataModel(id, "name", PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var record = new PostDataModel(id, "name", PostType.Bartender, new PostConfiguration() { Rate = 10 });
|
||||
_postStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _postBusinessLogicContract.GetPostByData(id);
|
||||
@@ -177,7 +170,7 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var postName = "name";
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), postName, PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), postName, PostType.Bartender, new PostConfiguration() { Rate = 10 });
|
||||
_postStorageContract.Setup(x => x.GetElementByName(postName)).Returns(record);
|
||||
//Act
|
||||
var element = _postBusinessLogicContract.GetPostByData(postName);
|
||||
@@ -233,12 +226,11 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, 10, true, DateTime.UtcNow.AddDays(-1));
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 10 });
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>()))
|
||||
.Callback((PostDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.Salary == record.Salary &&
|
||||
x.ChangeDate == record.ChangeDate;
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.ConfigurationModel.Rate == record.ConfigurationModel.Rate;
|
||||
});
|
||||
//Act
|
||||
_postBusinessLogicContract.InsertPost(record);
|
||||
@@ -253,7 +245,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Bartender, 10, true, DateTime.UtcNow)), Throws.TypeOf<ElementExistsException>());
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -269,7 +261,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void InsertPost_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new PostDataModel("id", "name", PostType.Bartender, 10, true, DateTime.UtcNow)), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new PostDataModel("id", "name", PostType.Bartender, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -279,7 +271,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Bartender, 10, true, DateTime.UtcNow)), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -288,12 +280,11 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, 10, true, DateTime.UtcNow.AddDays(-1));
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 10 });
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>()))
|
||||
.Callback((PostDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.Salary == record.Salary &&
|
||||
x.ChangeDate == record.ChangeDate;
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.ConfigurationModel.Rate == record.ConfigurationModel.Rate;
|
||||
});
|
||||
//Act
|
||||
_postBusinessLogicContract.UpdatePost(record);
|
||||
@@ -308,7 +299,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Bartender, 10, true, DateTime.UtcNow)), Throws.TypeOf<ElementNotFoundException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -318,7 +309,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.Bartender, 10, true, DateTime.UtcNow)), Throws.TypeOf<ElementExistsException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.Bartender, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -334,7 +325,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void UpdatePost_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new PostDataModel("id", "name", PostType.Bartender, 10, true, DateTime.UtcNow)), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new PostDataModel("id", "name", PostType.Bartender, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -344,7 +335,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Bartender, 10, true, DateTime.UtcNow)), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ using SquirrelBusinessLogic.Implementations;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Enums;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Infastructure.PostConfigurations;
|
||||
using SquirrelContract.Infrastructure;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
|
||||
namespace SquirrelTests.BusinessLogicContractsTests;
|
||||
@@ -17,6 +19,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
private Mock<ISaleStorageContract> _saleStorageContract;
|
||||
private Mock<IPostStorageContract> _postStorageContract;
|
||||
private Mock<IEmployeeStorageContract> _employeeStorageContract;
|
||||
private readonly ConfigurationSalaryTest _salaryConfigurationTest = new();
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
@@ -26,7 +29,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_postStorageContract = new Mock<IPostStorageContract>();
|
||||
_employeeStorageContract = new Mock<IEmployeeStorageContract>();
|
||||
_salaryBusinessLogicContract = new SalaryBusinessLogicContract(_salaryStorageContract.Object,
|
||||
_saleStorageContract.Object, _postStorageContract.Object, _employeeStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_saleStorageContract.Object, _postStorageContract.Object, _employeeStorageContract.Object, new Mock<ILogger>().Object, _salaryConfigurationTest);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -160,7 +163,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
public void GetAllSalariesByEmployee_EmployeeIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByEmployee(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), "workerId"), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByEmployee(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), "employeeId"), Throws.TypeOf<ValidationException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -187,16 +190,14 @@ internal class SalaryBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var saleSum = 200.0;
|
||||
var postSalary = 2000.0;
|
||||
var rate = 2000.0;
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, saleSum, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, postSalary, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = rate }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
var sum = 0.0;
|
||||
var expectedSum = postSalary + saleSum * 0.1;
|
||||
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
||||
.Callback((SalaryDataModel x) =>
|
||||
{
|
||||
@@ -205,29 +206,30 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Act
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
||||
//Assert
|
||||
Assert.That(sum, Is.EqualTo(expectedSum));
|
||||
Assert.That(sum, Is.EqualTo(rate));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WithSeveralWorkers_Test()
|
||||
public void CalculateSalaryByMounth_WithSeveralEmployees_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employee1Id = Guid.NewGuid().ToString();
|
||||
var employee2Id = Guid.NewGuid().ToString();
|
||||
var employee3Id = Guid.NewGuid().ToString();
|
||||
var list = new List<EmployeeDataModel>() {
|
||||
new(employee1Id, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
||||
new(employee2Id, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
||||
new(employee3Id, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)
|
||||
new(employee1Id, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
||||
new(employee2Id, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
||||
new(employee3Id, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employee1Id, null, 1, DiscountType.None, 0, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee1Id, null, 1, DiscountType.None, 0, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee2Id, null, 1, DiscountType.None, 0, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, 1, DiscountType.None, 0, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, 1, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employee1Id, null, DiscountType.None, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee1Id, null, DiscountType.None, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee2Id, null, DiscountType.None, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, DiscountType.None, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 100 }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns(list);
|
||||
//Act
|
||||
@@ -237,19 +239,18 @@ internal class SalaryBusinessLogicContractTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WithoutSalesByWorker_Test()
|
||||
public void CalculateSalaryByMounth_WithoutSalesByEmployee_Test()
|
||||
{
|
||||
//Arrange
|
||||
var postSalary = 2000.0;
|
||||
var rate = 2000.0;
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, postSalary, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = rate }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
var sum = 0.0;
|
||||
var expectedSum = postSalary;
|
||||
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
||||
.Callback((SalaryDataModel x) =>
|
||||
{
|
||||
@@ -258,7 +259,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Act
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
||||
//Assert
|
||||
Assert.That(sum, Is.EqualTo(expectedSum));
|
||||
Assert.That(sum, Is.EqualTo(rate));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -267,9 +268,9 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 100 }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
@@ -280,22 +281,22 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, 200, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WorkerStorageReturnNull_ThrowException_Test()
|
||||
public void CalculateSalaryByMounth_EmployeeStorageReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, 200, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 100 }));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
@@ -308,9 +309,9 @@ internal class SalaryBusinessLogicContractTests
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 100 }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
|
||||
}
|
||||
@@ -321,27 +322,89 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, 200, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WorkerStorageThrowException_ThrowException_Test()
|
||||
public void CalculateSalaryByMounth_EmployeeStorageThrowException_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, 200, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 100 }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMountht_WithBartenderPostConfiguration_CalculateSalary_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var rate = 2000.0;
|
||||
var percent = 0.1;
|
||||
var bonus = 0.5;
|
||||
var sales = new List<SaleDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5000, 12)])
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(sales);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new BartenderPostConfiguration() { Rate = rate, SalePercent = percent, BonusForExtraSales = bonus }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
var sum = 0.0;
|
||||
var expectedSum = rate + percent * (sales.Sum(x => x.Sum) / sales.Count) + sales.Where(x => x.Sum > _salaryConfigurationTest.ExtraSaleSum).Sum(x => x.Sum) * bonus;
|
||||
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
||||
.Callback((SalaryDataModel x) =>
|
||||
{
|
||||
sum = x.Salary;
|
||||
});
|
||||
//Act
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
||||
//Assert
|
||||
Assert.That(sum, Is.EqualTo(expectedSum));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMountht_WithManagerPostConfiguration_CalculateSalary_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var rate = 2000.0;
|
||||
var trend = 3;
|
||||
var bonus = 100;
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new ManagerPostConfiguration() { Rate = rate, PersonalCountTrendPremium = bonus }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
_employeeStorageContract.Setup(x => x.GetEmployeeTrend(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.Returns(trend);
|
||||
var sum = 0.0;
|
||||
var expectedSum = rate + trend * bonus;
|
||||
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
||||
.Callback((SalaryDataModel x) =>
|
||||
{
|
||||
sum = x.Salary;
|
||||
});
|
||||
//Act
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
||||
//Assert
|
||||
Assert.That(sum, Is.EqualTo(expectedSum));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ internal class SaleBusinessLogicContractTests
|
||||
var date = DateTime.UtcNow;
|
||||
var listOriginal = new List<SaleDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -101,10 +101,10 @@ internal class SaleBusinessLogicContractTests
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SaleDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -182,10 +182,10 @@ internal class SaleBusinessLogicContractTests
|
||||
var clientId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SaleDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -263,10 +263,10 @@ internal class SaleBusinessLogicContractTests
|
||||
var cocktailId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SaleDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -341,8 +341,8 @@ internal class SaleBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new SaleDataModel(id, Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
var record = new SaleDataModel(id, Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]);
|
||||
_saleStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _saleBusinessLogicContract.GetSaleByData(id);
|
||||
@@ -392,8 +392,8 @@ internal class SaleBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 10,
|
||||
false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
var record = new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.None,
|
||||
false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]);
|
||||
_warehouseStorageContract.Setup(x => x.CheckCocktails(It.IsAny<SaleDataModel>())).Returns(true);
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>()))
|
||||
.Callback((SaleDataModel x) =>
|
||||
@@ -421,7 +421,7 @@ internal class SaleBusinessLogicContractTests
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
Guid.NewGuid().ToString(), DiscountType.None, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])), Throws.TypeOf<ElementExistsException>());
|
||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
_warehouseStorageContract.Verify(x => x.CheckCocktails(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -438,7 +438,7 @@ internal class SaleBusinessLogicContractTests
|
||||
public void InsertSale_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new SaleDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [])), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new SaleDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.None, false, [])), Throws.TypeOf<ValidationException>());
|
||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -450,7 +450,7 @@ internal class SaleBusinessLogicContractTests
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
Guid.NewGuid().ToString(), DiscountType.None, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])), Throws.TypeOf<StorageException>());
|
||||
_warehouseStorageContract.Verify(x => x.CheckCocktails(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -461,8 +461,7 @@ internal class SaleBusinessLogicContractTests
|
||||
//Arrange
|
||||
_warehouseStorageContract.Setup(x => x.CheckCocktails(It.IsAny<SaleDataModel>())).Returns(false);
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false,
|
||||
[new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<InsufficientStockException>());
|
||||
Guid.NewGuid().ToString(), DiscountType.None, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])), Throws.TypeOf<InsufficientStockException>());
|
||||
//Act&Assert
|
||||
_warehouseStorageContract.Verify(x => x.CheckCocktails(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -518,4 +517,45 @@ internal class SaleBusinessLogicContractTests
|
||||
Assert.That(() => _saleBusinessLogicContract.CancelSale(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_saleStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateTotalRevenue_ReturnsCorrectSum_Test()
|
||||
{
|
||||
// Arrange
|
||||
DateTime fromDate = DateTime.UtcNow.AddDays(-10);
|
||||
DateTime toDate = DateTime.UtcNow;
|
||||
|
||||
var sales = new List<SaleDataModel>
|
||||
{
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.RegularCustomer, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 50.5)]),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, true, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, true, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 50.5)])
|
||||
};
|
||||
_saleStorageContract
|
||||
.Setup(x => x.GetList(fromDate, toDate, null, null, null))
|
||||
.Returns(sales);
|
||||
|
||||
// Act
|
||||
double revenue = _saleBusinessLogicContract.CalculateTotalRevenue(fromDate, toDate);
|
||||
|
||||
// Assert
|
||||
Assert.That(revenue, Is.EqualTo(126.25));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateTotalRevenue_NoSales_ReturnsZero()
|
||||
{
|
||||
// Arrange
|
||||
DateTime fromDate = DateTime.UtcNow.AddDays(-10);
|
||||
DateTime toDate = DateTime.UtcNow;
|
||||
_saleStorageContract
|
||||
.Setup(x => x.GetList(fromDate, toDate, null, null, null))
|
||||
.Returns(new List<SaleDataModel>());
|
||||
|
||||
// Act
|
||||
double revenue = _saleBusinessLogicContract.CalculateTotalRevenue(fromDate, toDate);
|
||||
|
||||
// Assert
|
||||
Assert.That(revenue, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,4 +281,48 @@ internal class SupplyBusinessLogicContractTests
|
||||
_supplyStorageContract.Verify(x => x.AddElement(It.IsAny<SupplyDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountByPeriod_ReturnInt_Test()
|
||||
{
|
||||
// Arrange
|
||||
string id = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SupplyDataModel>()
|
||||
{
|
||||
new(id, DateTime.UtcNow, new List<SupplyCocktailDataModel> { new SupplyCocktailDataModel(id, Guid.NewGuid().ToString(), 5), new SupplyCocktailDataModel(id, Guid.NewGuid().ToString(), 6) })
|
||||
};
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
// Act
|
||||
var count = _supplyBusinessLogicContract.CountByPeriod(DateTime.UtcNow.AddDays(-5), DateTime.UtcNow.AddDays(5));
|
||||
// Assert
|
||||
Assert.That(count, Is.EqualTo(11));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountByPeriod_ReturnIntZero_Test()
|
||||
{
|
||||
// Arrange
|
||||
string id1 = Guid.NewGuid().ToString();
|
||||
string id2 = Guid.NewGuid().ToString();
|
||||
string id3 = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SupplyDataModel>()
|
||||
{
|
||||
new(id1, DateTime.UtcNow, [])
|
||||
};
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
// Act
|
||||
var count = _supplyBusinessLogicContract.CountByPeriod(DateTime.UtcNow.AddDays(-5), DateTime.UtcNow.AddDays(5));
|
||||
// Assert
|
||||
Assert.That(count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountByPeriod_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.CountByPeriod(DateTime.UtcNow.AddDays(-5), DateTime.UtcNow.AddDays(5)), Throws.TypeOf<StorageException>());
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,13 +13,18 @@ namespace SquirrelTests.BusinessLogicContractsTests;
|
||||
internal class WarehouseBusinessLogicContractTests
|
||||
{
|
||||
private WarehouseBusinessLogicContract _warehouseBusinessLogicContract;
|
||||
private Mock<ISaleStorageContract> _saleStorageContract;
|
||||
private Mock<ISupplyStorageContract> _supplyStorageContract;
|
||||
private Mock<IWarehouseStorageContract> _warehouseStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_warehouseStorageContract = new Mock<IWarehouseStorageContract>();
|
||||
_warehouseBusinessLogicContract = new WarehouseBusinessLogicContract(_warehouseStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_saleStorageContract = new Mock<ISaleStorageContract>();
|
||||
_supplyStorageContract = new Mock<ISupplyStorageContract>();
|
||||
_warehouseBusinessLogicContract = new WarehouseBusinessLogicContract(_warehouseStorageContract.Object,
|
||||
_supplyStorageContract.Object, _saleStorageContract.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -317,4 +322,50 @@ internal class WarehouseBusinessLogicContractTests
|
||||
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetCocktailStockCountAsync_CorrectlyCalculatesStock_Test()
|
||||
{
|
||||
// Arrange
|
||||
var supplies = new List<SupplyDataModel>
|
||||
{
|
||||
new SupplyDataModel(Guid.NewGuid().ToString(), DateTime.UtcNow, new List<SupplyCocktailDataModel>
|
||||
{
|
||||
new SupplyCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10),
|
||||
new SupplyCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 20)
|
||||
})
|
||||
};
|
||||
var sales = new List<SaleDataModel>
|
||||
{
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
new List<SaleCocktailDataModel>
|
||||
{
|
||||
new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 100.0),
|
||||
new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 8, 150.0)
|
||||
})
|
||||
};
|
||||
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Returns(supplies);
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(sales);
|
||||
|
||||
// Act
|
||||
var result = await _warehouseBusinessLogicContract.GetCocktailStockCountAsync();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.EqualTo(17));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetCocktailStockCountAsync_NoSuppliesOrSales_ReturnsZero_Test()
|
||||
{
|
||||
// Arrange
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Returns(new List<SupplyDataModel>());
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(new List<SaleDataModel>());
|
||||
|
||||
// Act
|
||||
var result = await _warehouseBusinessLogicContract.GetCocktailStockCountAsync();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Enums;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Infastructure.PostConfigurations;
|
||||
|
||||
namespace SquirrelTests.DataModelsTests;
|
||||
|
||||
@@ -10,41 +11,49 @@ internal class PostDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, "name", PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel(null, "name", PostType.Bartender, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, "name", PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
post = CreateDataModel(string.Empty, "name", PostType.Bartender, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", "name", PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel("id", "name", PostType.Bartender, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Bartender, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Bartender, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SalaryIsLessOrZeroTest()
|
||||
public void ConfigurationModelIsNullTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 0, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, null);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, -10, true, DateTime.UtcNow);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void RateIsLessOrZeroTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = 0 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Bartender, new PostConfiguration() { Rate = -10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -53,23 +62,20 @@ internal class PostDataModelTests
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var postName = "name";
|
||||
var postType = PostType.Manager;
|
||||
var salary = 10;
|
||||
var isActual = false;
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var post = CreateDataModel(postId, postName, postType, salary, isActual, changeDate);
|
||||
var postType = PostType.Bartender;
|
||||
var configuration = new PostConfiguration() { Rate = 10 };
|
||||
var post = CreateDataModel(postId, postName, postType, configuration);
|
||||
Assert.That(() => post.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(post.Id, Is.EqualTo(postId));
|
||||
Assert.That(post.PostName, Is.EqualTo(postName));
|
||||
Assert.That(post.PostType, Is.EqualTo(postType));
|
||||
Assert.That(post.Salary, Is.EqualTo(salary));
|
||||
Assert.That(post.IsActual, Is.EqualTo(isActual));
|
||||
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
||||
Assert.That(post.ConfigurationModel, Is.EqualTo(configuration));
|
||||
Assert.That(post.ConfigurationModel.Rate, Is.EqualTo(configuration.Rate));
|
||||
});
|
||||
}
|
||||
|
||||
private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
|
||||
new(id, postName, postType, salary, isActual, changeDate);
|
||||
private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType, PostConfiguration configuration) =>
|
||||
new(id, postName, postType, configuration);
|
||||
}
|
||||
|
||||
@@ -9,41 +9,50 @@ internal class SaleCocktailDataModelTests
|
||||
[Test]
|
||||
public void SaleIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleCocktail = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
var saleCocktail = CreateDataModel(null, Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
saleCocktail = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
saleCocktail = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SaleIdIsNotGuidTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
var saleCocktail = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
var saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), null, 10, 1.1);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
saleCocktail = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
saleCocktail = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
public void CocktailIdIsNotGuidTest()
|
||||
{
|
||||
var saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10);
|
||||
var saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), "cocktailId", 10, 1.1);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
var saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, 1.1);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, 1.1);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 0);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
saleCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, -10);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -53,16 +62,18 @@ internal class SaleCocktailDataModelTests
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var cocktailId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var saleCocktail = CreateDataModel(saleId, cocktailId, count);
|
||||
var price = 1.2;
|
||||
var saleCocktail = CreateDataModel(saleId, cocktailId, count, price);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleCocktail.SaleId, Is.EqualTo(saleId));
|
||||
Assert.That(saleCocktail.CocktailId, Is.EqualTo(cocktailId));
|
||||
Assert.That(saleCocktail.Count, Is.EqualTo(count));
|
||||
Assert.That(saleCocktail.Price, Is.EqualTo(price));
|
||||
});
|
||||
}
|
||||
|
||||
private static SaleCocktailDataModel CreateDataModel(string? saleId, string? cocktailId, int count) =>
|
||||
new(saleId, cocktailId, count);
|
||||
private static SaleCocktailDataModel CreateDataModel(string? saleId, string? cocktailId, int count, double price) =>
|
||||
new(saleId, cocktailId, count, price);
|
||||
}
|
||||
|
||||
@@ -10,88 +10,120 @@ internal class SaleDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void EmployeeIdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmployeeIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ClientIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "clientId", 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "clientId", DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailsIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, null);
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, null);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, []);
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalcSumAndDiscountTest()
|
||||
{
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var clientId = Guid.NewGuid().ToString();
|
||||
var cocktails = new List<SaleCocktailDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 2, 1.1),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 1.3)
|
||||
};
|
||||
var isCancel = false;
|
||||
var totalSum = cocktails.Sum(x => x.Price * x.Count);
|
||||
var saleNone = CreateDataModel(saleId, employeeId, clientId, DiscountType.None, isCancel, cocktails);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleNone.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleNone.Discount, Is.EqualTo(0));
|
||||
});
|
||||
var saleOnSale = CreateDataModel(saleId, employeeId, clientId, DiscountType.OnSale, isCancel, cocktails);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleOnSale.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleOnSale.Discount, Is.EqualTo(totalSum * 0.1));
|
||||
});
|
||||
var saleRegularCustomer = CreateDataModel(saleId, employeeId, clientId, DiscountType.RegularCustomer, isCancel, cocktails);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleRegularCustomer.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleRegularCustomer.Discount, Is.EqualTo(totalSum * 0.5));
|
||||
});
|
||||
var saleCertificate = CreateDataModel(saleId, employeeId, clientId, DiscountType.Certificate, isCancel, cocktails);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleCertificate.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleCertificate.Discount, Is.EqualTo(totalSum * 0.3));
|
||||
});
|
||||
var saleMulty = CreateDataModel(saleId, employeeId, clientId, DiscountType.Certificate | DiscountType.RegularCustomer, isCancel, cocktails);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleMulty.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleMulty.Discount, Is.EqualTo(totalSum * 0.8));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var clientId = Guid.NewGuid().ToString();
|
||||
var sum = 10;
|
||||
var discountType = DiscountType.Certificate;
|
||||
var discount = 1;
|
||||
var isCancel = true;
|
||||
var cocktails = CreateSubDataModel();
|
||||
var sale = CreateDataModel(saleId, employeeId, clientId, sum, discountType, discount, isCancel, cocktails);
|
||||
var sale = CreateDataModel(saleId, employeeId, clientId, discountType, isCancel, cocktails);
|
||||
Assert.That(() => sale.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(sale.Id, Is.EqualTo(saleId));
|
||||
Assert.That(sale.EmployeeId, Is.EqualTo(employeeId));
|
||||
Assert.That(sale.ClientId, Is.EqualTo(clientId));
|
||||
Assert.That(sale.Sum, Is.EqualTo(sum));
|
||||
Assert.That(sale.DiscountType, Is.EqualTo(discountType));
|
||||
Assert.That(sale.Discount, Is.EqualTo(discount));
|
||||
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
||||
Assert.That(sale.Cocktails, Is.EquivalentTo(cocktails));
|
||||
});
|
||||
}
|
||||
|
||||
private static SaleDataModel CreateDataModel(string? id, string? employeeId, string? clientId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleCocktailDataModel>? cocktails) =>
|
||||
new(id, employeeId, clientId, sum, discountType, discount, isCancel, cocktails);
|
||||
private static SaleDataModel CreateDataModel(string? id, string? employeeId, string? clientId, DiscountType discountType, bool isCancel, List<SaleCocktailDataModel>? cocktails) =>
|
||||
new(id, employeeId, clientId, discountType, isCancel, cocktails);
|
||||
|
||||
private static List<SaleCocktailDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 1.1)];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelContract.Infrastructure;
|
||||
|
||||
class ConfigurationSalaryTest : IConfigurationSalary
|
||||
{
|
||||
public double ExtraSaleSum => 10;
|
||||
|
||||
public int MaxConcurrentThreads => 4;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelTests.Infrastructure;
|
||||
|
||||
internal class CustomWebApplicationFactory<TProgram> : WebApplicationFactory<TProgram>
|
||||
where TProgram : class
|
||||
{
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
var databaseConfig = services.SingleOrDefault(x => x.ServiceType == typeof(IConfigurationDatabase));
|
||||
if (databaseConfig is not null)
|
||||
services.Remove(databaseConfig);
|
||||
|
||||
var loggerFactory = services.SingleOrDefault(x => x.ServiceType == typeof(LoggerFactory));
|
||||
if (loggerFactory is not null)
|
||||
services.Remove(loggerFactory);
|
||||
|
||||
services.AddSingleton<IConfigurationDatabase, ConfigurationDatabaseTest>();
|
||||
});
|
||||
|
||||
builder.UseEnvironment("Development");
|
||||
|
||||
base.ConfigureWebHost(builder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
using SquirrelContract.Enums;
|
||||
using SquirrelDatabase;
|
||||
using SquirrelDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SquirrelContract.Infastructure.PostConfigurations;
|
||||
|
||||
namespace SquirrelTests.Infrastructure;
|
||||
|
||||
internal static class SquirrelDbContextExtensions
|
||||
{
|
||||
public static Client InsertClientToDatabaseAndReturn(this SquirrelDbContext dbContext, string? id = null, string fio = "test", string phoneNumber = "+7-777-777-77-77", double discountSize = 10)
|
||||
{
|
||||
var client = new Client() { Id = id ?? Guid.NewGuid().ToString(), FIO = fio, PhoneNumber = phoneNumber, DiscountSize = discountSize };
|
||||
dbContext.Clients.Add(client);
|
||||
dbContext.SaveChanges();
|
||||
return client;
|
||||
}
|
||||
|
||||
public static Post InsertPostToDatabaseAndReturn(this SquirrelDbContext dbContext, string? id = null, string postName = "test", PostType postType = PostType.Bartender, PostConfiguration? config = null, bool isActual = true, DateTime? changeDate = null)
|
||||
{
|
||||
var post = new Post() { Id = Guid.NewGuid().ToString(), PostId = id ?? Guid.NewGuid().ToString(), PostName = postName, PostType = postType, Configuration = config ?? new PostConfiguration() { Rate = 100 }, IsActual = isActual, ChangeDate = changeDate ?? DateTime.UtcNow };
|
||||
dbContext.Posts.Add(post);
|
||||
dbContext.SaveChanges();
|
||||
return post;
|
||||
}
|
||||
|
||||
public static Cocktail InsertCocktailToDatabaseAndReturn(this SquirrelDbContext dbContext, string? id = null, string cocktailName = "test", AlcoholType baseAlcohol = AlcoholType.Vodka, double price = 1)
|
||||
{
|
||||
var cocktail = new Cocktail() { Id = id ?? Guid.NewGuid().ToString(), CocktailName = cocktailName, BaseAlcohol = baseAlcohol, Price = price };
|
||||
dbContext.Cocktails.Add(cocktail);
|
||||
dbContext.SaveChanges();
|
||||
return cocktail;
|
||||
}
|
||||
|
||||
public static CocktailHistory InsertCocktailHistoryToDatabaseAndReturn(this SquirrelDbContext dbContext, string cocktailId, double price = 10, DateTime? changeDate = null)
|
||||
{
|
||||
var cocktailHistory = new CocktailHistory() { Id = Guid.NewGuid().ToString(), CocktailId = cocktailId, OldPrice = price, ChangeDate = changeDate ?? DateTime.UtcNow };
|
||||
dbContext.CocktailHistories.Add(cocktailHistory);
|
||||
dbContext.SaveChanges();
|
||||
return cocktailHistory;
|
||||
}
|
||||
|
||||
public static Salary InsertSalaryToDatabaseAndReturn(this SquirrelDbContext dbContext, string employeeId, double employeeSalary = 1, DateTime? salaryDate = null)
|
||||
{
|
||||
var salary = new Salary() { EmployeeId = employeeId, EmployeeSalary = employeeSalary, SalaryDate = salaryDate ?? DateTime.UtcNow };
|
||||
dbContext.Salaries.Add(salary);
|
||||
dbContext.SaveChanges();
|
||||
return salary;
|
||||
}
|
||||
|
||||
public static Sale InsertSaleToDatabaseAndReturn(this SquirrelDbContext dbContext, string employeeId, string? clientId = null, DateTime? saleDate = null, double sum = 1, DiscountType discountType = DiscountType.None, double discount = 0, bool isCancel = false, List<(string, int, double)>? cocktails = null)
|
||||
{
|
||||
var sale = new Sale() { EmployeeId = employeeId, ClientId = clientId, SaleDate = saleDate ?? DateTime.UtcNow, Sum = sum, DiscountType = discountType, Discount = discount, IsCancel = isCancel, SaleCocktails = [] };
|
||||
if (cocktails is not null)
|
||||
{
|
||||
foreach (var elem in cocktails)
|
||||
{
|
||||
sale.SaleCocktails.Add(new SaleCocktail { CocktailId = elem.Item1, SaleId = sale.Id, Count = elem.Item2, Price = elem.Item3 });
|
||||
}
|
||||
}
|
||||
dbContext.Sales.Add(sale);
|
||||
dbContext.SaveChanges();
|
||||
return sale;
|
||||
}
|
||||
|
||||
public static Employee InsertEmployeeToDatabaseAndReturn(this SquirrelDbContext dbContext, string? id = null, string fio = "test", string email = "abc@gmail.com", string? postId = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false, DateTime? dateDelete = null)
|
||||
{
|
||||
var worker = new Employee() { Id = id ?? Guid.NewGuid().ToString(), FIO = fio, Email = email, PostId = postId ?? Guid.NewGuid().ToString(), BirthDate = birthDate ?? DateTime.UtcNow.AddYears(-20), EmploymentDate = employmentDate ?? DateTime.UtcNow, IsDeleted = isDeleted, DateOfDelete = dateDelete };
|
||||
dbContext.Employees.Add(worker);
|
||||
dbContext.SaveChanges();
|
||||
return worker;
|
||||
}
|
||||
|
||||
public static Warehouse InsertWarehouseToDatabaseAndReturn(this SquirrelDbContext dbContext, string? id = null, string name = "test", List<(string, int)>? cocktails = null)
|
||||
{
|
||||
var warehouse = new Warehouse() { Id = id ?? Guid.NewGuid().ToString(), Name = name, Cocktails = [] };
|
||||
if (cocktails is not null)
|
||||
{
|
||||
foreach (var elem in cocktails)
|
||||
{
|
||||
warehouse.Cocktails.Add(new WarehouseCocktail { WarehouseId = warehouse.Id, CocktailId = elem.Item1, Count = elem.Item2 });
|
||||
}
|
||||
}
|
||||
dbContext.Warehouses.Add(warehouse);
|
||||
dbContext.SaveChanges();
|
||||
return warehouse;
|
||||
}
|
||||
|
||||
public static Supply InsertSupplyToDatabaseAndReturn(this SquirrelDbContext dbContext, string? id = null, DateTime? supplyDate = null, List<(string, int)>? cocktails = null)
|
||||
{
|
||||
var supply = new Supply() { Id = id ?? Guid.NewGuid().ToString(), SupplyDate = supplyDate ?? DateTime.UtcNow, Cocktails = [] };
|
||||
if (cocktails is not null)
|
||||
{
|
||||
foreach (var elem in cocktails)
|
||||
{
|
||||
supply.Cocktails.Add(new SupplyCocktail { SupplyId = supply.Id, CocktailId = elem.Item1, Count = elem.Item2 });
|
||||
}
|
||||
}
|
||||
dbContext.Supplies.Add(supply);
|
||||
dbContext.SaveChanges();
|
||||
return supply;
|
||||
}
|
||||
|
||||
public static Client? GetClientFromDatabase(this SquirrelDbContext dbContext, string id) => dbContext.Clients.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static Post? GetPostFromDatabaseByPostId(this SquirrelDbContext dbContext, string id) => dbContext.Posts.FirstOrDefault(x => x.PostId == id && x.IsActual);
|
||||
|
||||
public static Post[] GetPostsFromDatabaseByPostId(this SquirrelDbContext dbContext, string id) => [.. dbContext.Posts.Where(x => x.PostId == id).OrderByDescending(x => x.ChangeDate)];
|
||||
|
||||
public static Cocktail? GetCocktailFromDatabaseById(this SquirrelDbContext dbContext, string id) => dbContext.Cocktails.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static Salary[] GetSalariesFromDatabaseByEmployeeId(this SquirrelDbContext dbContext, string id) => [.. dbContext.Salaries.Where(x => x.EmployeeId == id)];
|
||||
|
||||
public static Sale? GetSaleFromDatabaseById(this SquirrelDbContext dbContext, string id) => dbContext.Sales.Include(x => x.SaleCocktails).FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static Sale[] GetSalesByClientId(this SquirrelDbContext dbContext, string? clientId) => [.. dbContext.Sales.Include(x => x.SaleCocktails).Where(x => x.ClientId == clientId)];
|
||||
|
||||
public static Employee? GetEmployeeFromDatabaseById(this SquirrelDbContext dbContext, string id) => dbContext.Employees.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static Warehouse? GetWarehouseFromDatabaseById(this SquirrelDbContext dbContext, string id) => dbContext.Warehouses.Include(x => x.Cocktails).FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static Supply? GetSuppliesFromDatabaseById(this SquirrelDbContext dbContext, string id) => dbContext.Supplies.Include(x => x.Cocktails).FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static void RemoveClientsFromDatabase(this SquirrelDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Clients\" CASCADE;");
|
||||
|
||||
public static void RemovePostsFromDatabase(this SquirrelDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Posts\" CASCADE;");
|
||||
|
||||
public static void RemoveCocktailsFromDatabase(this SquirrelDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Cocktails\" CASCADE;");
|
||||
|
||||
public static void RemoveSalariesFromDatabase(this SquirrelDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Salaries\" CASCADE;");
|
||||
|
||||
public static void RemoveSalesFromDatabase(this SquirrelDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Sales\" CASCADE;");
|
||||
|
||||
public static void RemoveEmployeesFromDatabase(this SquirrelDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Employees\" CASCADE;");
|
||||
|
||||
public static void RemoveWarehousesFromDatabase(this SquirrelDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Warehouses\" CASCADE;");
|
||||
|
||||
public static void RemoveSuppliesFromDatabase(this SquirrelDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Supplies\" CASCADE;");
|
||||
|
||||
private static void ExecuteSqlRaw(this SquirrelDbContext dbContext, string command) => dbContext.Database.ExecuteSqlRaw(command);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user