add BusinessLogic
This commit is contained in:
parent
3e9619c7c4
commit
50bc49151d
@ -5,9 +5,11 @@ VisualStudioVersion = 17.9.34723.18
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarShowroomDataModels", "CarShowroomDataModels\CarShowroomDataModels.csproj", "{7EECD77A-5D26-4093-85B0-F2D33C6F0C2C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarShowroomContracts", "CarShowroomContracts\CarShowroomContracts.csproj", "{6274B5CD-C339-4FD3-AC45-DE8384AD4CB7}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarShowroomContracts", "CarShowroomContracts\CarShowroomContracts.csproj", "{6274B5CD-C339-4FD3-AC45-DE8384AD4CB7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarShowroomDatabaseStorage", "CarShowroomDatabaseStorage\CarShowroomDatabaseStorage.csproj", "{7F0A0E4D-6EFD-459D-AFFF-99F3185243F8}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarShowroomDatabaseStorage", "CarShowroomDatabaseStorage\CarShowroomDatabaseStorage.csproj", "{7F0A0E4D-6EFD-459D-AFFF-99F3185243F8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarShowroomBusinessLogic", "CarShowroomBusinessLogic\CarShowroomBusinessLogic.csproj", "{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -27,6 +29,10 @@ Global
|
||||
{7F0A0E4D-6EFD-459D-AFFF-99F3185243F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7F0A0E4D-6EFD-459D-AFFF-99F3185243F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7F0A0E4D-6EFD-459D-AFFF-99F3185243F8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B0DA0319-2DBC-4785-BA5F-338AD5E3E437}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,89 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomContracts.StorageContracts;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class CarLogic : ICarLogic
|
||||
{
|
||||
private readonly ICarStorage _carStorage;
|
||||
|
||||
public CarLogic(ICarStorage storage)
|
||||
{
|
||||
_carStorage = storage;
|
||||
}
|
||||
|
||||
public List<CarView>? ReadList(CarSearch? model)
|
||||
{
|
||||
var list = model == null ? _carStorage.GetFullList() : _carStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public CarView? ReadElement(CarSearch model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
var element = _carStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(CarDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_carStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(CarDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_carStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(CarDto model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_carStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(CarDto model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
if (model.ModelId < 0)
|
||||
throw new InvalidOperationException();
|
||||
if (string.IsNullOrEmpty(model.Color))
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomContracts.StorageContracts;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ClientLogic : IClientLogic
|
||||
{
|
||||
private readonly IClientStorage _clientStorage;
|
||||
|
||||
public ClientLogic(IClientStorage storage)
|
||||
{
|
||||
_clientStorage = storage;
|
||||
}
|
||||
|
||||
public List<ClientView>? ReadList(ClientSearch? model)
|
||||
{
|
||||
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ClientView? ReadElement(ClientSearch model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
var element = _clientStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ClientDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ClientDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ClientDto model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_clientStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ClientDto model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
throw new InvalidOperationException();
|
||||
if (string.IsNullOrEmpty(model.PhoneNumber))
|
||||
throw new InvalidOperationException();
|
||||
var element = _clientStorage.GetElement(new ClientSearch
|
||||
{
|
||||
PhoneNumber = model.PhoneNumber,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomContracts.StorageContracts;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class EmployeeLogic : IEmployeeLogic
|
||||
{
|
||||
private readonly IEmployeeStorage _employeeStorage;
|
||||
|
||||
public EmployeeLogic(IEmployeeStorage storage)
|
||||
{
|
||||
_employeeStorage = storage;
|
||||
}
|
||||
|
||||
public List<EmployeeView>? ReadList(EmployeeSearch? model)
|
||||
{
|
||||
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public EmployeeView? ReadElement(EmployeeSearch model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
var element = _employeeStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(EmployeeDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_employeeStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(EmployeeDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_employeeStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(EmployeeDto model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_employeeStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(EmployeeDto model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
throw new InvalidOperationException();
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
throw new InvalidOperationException();
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
throw new InvalidOperationException();
|
||||
var element = _employeeStorage.GetElement(new EmployeeSearch
|
||||
{
|
||||
Email = model.Email,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomContracts.StorageContracts;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class MakeLogic : IMakeLogic
|
||||
{
|
||||
private readonly IMakeStorage _makeStorage;
|
||||
|
||||
public MakeLogic(IMakeStorage storage)
|
||||
{
|
||||
_makeStorage = storage;
|
||||
}
|
||||
|
||||
public List<MakeView>? ReadList(MakeSearch? model)
|
||||
{
|
||||
var list = model == null ? _makeStorage.GetFullList() : _makeStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public MakeView? ReadElement(MakeSearch model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
var element = _makeStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(MakeDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_makeStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(MakeDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_makeStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(MakeDto model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_makeStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(MakeDto model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
throw new InvalidOperationException();
|
||||
var element = _makeStorage.GetElement(new MakeSearch
|
||||
{
|
||||
Name = model.Name,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomContracts.StorageContracts;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ModelLogic : IModelLogic
|
||||
{
|
||||
private readonly IModelStorage _modelStorage;
|
||||
|
||||
public ModelLogic(IModelStorage storage)
|
||||
{
|
||||
_modelStorage = storage;
|
||||
}
|
||||
|
||||
public List<ModelView>? ReadList(ModelSearch? model)
|
||||
{
|
||||
var list = model == null ? _modelStorage.GetFullList() : _modelStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ModelView? ReadElement(ModelSearch model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
var element = _modelStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ModelDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_modelStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ModelDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_modelStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ModelDto model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_modelStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ModelDto model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
throw new InvalidOperationException();
|
||||
if (model.MakeId < 0)
|
||||
throw new InvalidOperationException();
|
||||
if (model.Price < 0)
|
||||
throw new InvalidOperationException();
|
||||
var element = _modelStorage.GetElement(new ModelSearch
|
||||
{
|
||||
Name = model.Name,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomContracts.StorageContracts;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class SaleLogic : ISaleLogic
|
||||
{
|
||||
private readonly ISaleStorage _saleStorage;
|
||||
|
||||
public SaleLogic(ISaleStorage storage)
|
||||
{
|
||||
_saleStorage = storage;
|
||||
}
|
||||
|
||||
public List<SaleView>? ReadList(SaleSearch? model)
|
||||
{
|
||||
var list = model == null ? _saleStorage.GetFullList() : _saleStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public SaleView? ReadElement(SaleSearch model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
var element = _saleStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(SaleDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_saleStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(SaleDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_saleStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(SaleDto model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_saleStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(SaleDto model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
if (model.Cost < 0)
|
||||
throw new InvalidOperationException();
|
||||
if (model.EmployeeId < 0)
|
||||
throw new InvalidOperationException();
|
||||
if (model.ClientId < 0)
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
using CarShowroomContracts.BusinessLogic;
|
||||
using CarShowroomContracts.StorageContracts;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using CarShowroomDataModels.Views;
|
||||
using ServiceShowroomContracts.BusinessLogic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ServiceLogic : IServiceLogic
|
||||
{
|
||||
private readonly IServiceStorage _serviceStorage;
|
||||
|
||||
public ServiceLogic(IServiceStorage storage)
|
||||
{
|
||||
_serviceStorage = storage;
|
||||
}
|
||||
|
||||
public List<ServiceView>? ReadList(ServiceSearch? model)
|
||||
{
|
||||
var list = model == null ? _serviceStorage.GetFullList() : _serviceStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ServiceView? ReadElement(ServiceSearch model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
var element = _serviceStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ServiceDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_serviceStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ServiceDto model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_serviceStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ServiceDto model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_serviceStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ServiceDto model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
throw new InvalidOperationException();
|
||||
if (model.Cost < 0)
|
||||
throw new InvalidOperationException();
|
||||
var element = _serviceStorage.GetElement(new ServiceSearch
|
||||
{
|
||||
Name = model.Name,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarShowroomContracts\CarShowroomContracts.csproj" />
|
||||
<ProjectReference Include="..\CarShowroomDataModels\CarShowroomDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,4 +1,4 @@
|
||||
using CarShowroomContracts.Dtos;
|
||||
using CarShowroomDataModels.Dtos;
|
||||
using CarShowroomDataModels.Views;
|
||||
using CarShowroomDataModels.SearchModel;
|
||||
using System;
|
||||
|
@ -9,5 +9,6 @@ namespace CarShowroomDataModels.SearchModel
|
||||
public class ClientSearch
|
||||
{
|
||||
public int? Id;
|
||||
public string? PhoneNumber;
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ namespace CarShowroomDataModels.SearchModel
|
||||
public class MakeSearch
|
||||
{
|
||||
public int? Id;
|
||||
public string? Name;
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ namespace CarShowroomDataModels.SearchModel
|
||||
public class ModelSearch
|
||||
{
|
||||
public int? Id;
|
||||
public string? Name;
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ namespace CarShowroomDataModels.SearchModel
|
||||
public class ServiceSearch
|
||||
{
|
||||
public int? Id;
|
||||
public string? Name;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
{
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Cars
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CarView> GetFilteredList(CarSearch model)
|
||||
|
@ -17,32 +17,36 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
{
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Clients
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ClientView> GetFilteredList(ClientSearch model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue &&
|
||||
string.IsNullOrEmpty(model.PhoneNumber))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Clients
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id)
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.PhoneNumber) || x.PhoneNumber.Equals(model.PhoneNumber)))
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ClientView? GetElement(ClientSearch model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue &&
|
||||
string.IsNullOrEmpty(model.PhoneNumber))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => !model.Id.HasValue || x.Id == model.Id)
|
||||
.FirstOrDefault(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.PhoneNumber) || x.PhoneNumber.Equals(model.PhoneNumber)))
|
||||
?.GetView();
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,8 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
{
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Employees
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<EmployeeView> GetFilteredList(EmployeeSearch model)
|
||||
@ -31,10 +31,9 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Employees
|
||||
.Where(x =>
|
||||
!model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password == model.Password) &&
|
||||
(string.IsNullOrEmpty(model.Email) || x.Password == model.Email))
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)) &&
|
||||
(string.IsNullOrEmpty(model.Email) || x.Password.Equals(model.Email)))
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
@ -49,10 +48,9 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Employees
|
||||
.FirstOrDefault(x =>
|
||||
!model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password == model.Password) &&
|
||||
(string.IsNullOrEmpty(model.Email) || x.Password == model.Email))
|
||||
.FirstOrDefault(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)) &&
|
||||
(string.IsNullOrEmpty(model.Email) || x.Password.Equals(model.Email)))
|
||||
?.GetView();
|
||||
}
|
||||
|
||||
|
@ -17,32 +17,36 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
{
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Makes
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MakeView> GetFilteredList(MakeSearch model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue &&
|
||||
string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Makes
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id)
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Name) || x.Name.Equals(model.Name)))
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MakeView? GetElement(MakeSearch model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue &&
|
||||
string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Makes
|
||||
.FirstOrDefault(x => !model.Id.HasValue || x.Id == model.Id)
|
||||
.FirstOrDefault(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Name) || x.Name.Equals(model.Name)))
|
||||
?.GetView();
|
||||
}
|
||||
|
||||
|
@ -17,32 +17,36 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
{
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Models
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ModelView> GetFilteredList(ModelSearch model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue &&
|
||||
string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Models
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id)
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Name) || x.Name.Equals(model.Name)))
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ModelView? GetElement(ModelSearch model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue &&
|
||||
string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Models
|
||||
.FirstOrDefault(x => !model.Id.HasValue || x.Id == model.Id)
|
||||
.FirstOrDefault(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Name) || x.Name.Equals(model.Name)))
|
||||
?.GetView();
|
||||
}
|
||||
|
||||
@ -62,14 +66,14 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
public ModelView? Update(ModelDto model)
|
||||
{
|
||||
using var context = new CarShowroomDatabase();
|
||||
var model = context.Models.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (model == null)
|
||||
var entity = context.Models.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
model.Update(model);
|
||||
entity.Update(entity);
|
||||
context.SaveChanges();
|
||||
return model.GetView();
|
||||
return entity.GetView();
|
||||
}
|
||||
|
||||
public ModelView? Delete(ModelDto model)
|
||||
|
@ -17,8 +17,8 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
{
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Sales
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<SaleView> GetFilteredList(SaleSearch model)
|
||||
|
@ -17,32 +17,36 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
{
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Services
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ServiceView> GetFilteredList(ServiceSearch model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue &&
|
||||
string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Services
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id)
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Name) || x.Name.Equals(model.Name)))
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ServiceView? GetElement(ServiceSearch model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue &&
|
||||
string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Services
|
||||
.FirstOrDefault(x => !model.Id.HasValue || x.Id == model.Id)
|
||||
.FirstOrDefault(x => !model.Id.HasValue || x.Id == model.Id &&
|
||||
(string.IsNullOrEmpty(model.Name) || x.Name.Equals(model.Name)))
|
||||
?.GetView();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user