фикс
This commit is contained in:
parent
ea927af136
commit
c60990c516
49
ComputerShop.sln
Normal file
49
ComputerShop.sln
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34511.84
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopDataModels", "ComputerShopDataModels\ComputerShopDataModels.csproj", "{BBCF398B-D800-4D8D-99E8-F7ED2CC14A65}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopContracts", "ComputerShopContracts\ComputerShopContracts.csproj", "{B197888D-702B-4122-BFBF-BA6BCB49C0F3}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopBusinessLogic", "ComputerShopBusinessLogic\ComputerShopBusinessLogic.csproj", "{82FCBA71-AC54-45C8-9B21-BCB3DF6E085B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopDatabaseImplement", "ComputerShopDatabaseImplement\ComputerShopDatabaseImplement.csproj", "{CDE4C963-67B5-47A6-A394-901E95EA40F7}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopImplementerApp", "ComputerShopImplementerApp\ComputerShopImplementerApp.csproj", "{0E13C365-F2CC-4A32-BDD0-52E2DB324734}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BBCF398B-D800-4D8D-99E8-F7ED2CC14A65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BBCF398B-D800-4D8D-99E8-F7ED2CC14A65}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BBCF398B-D800-4D8D-99E8-F7ED2CC14A65}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BBCF398B-D800-4D8D-99E8-F7ED2CC14A65}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B197888D-702B-4122-BFBF-BA6BCB49C0F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B197888D-702B-4122-BFBF-BA6BCB49C0F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B197888D-702B-4122-BFBF-BA6BCB49C0F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B197888D-702B-4122-BFBF-BA6BCB49C0F3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{82FCBA71-AC54-45C8-9B21-BCB3DF6E085B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{82FCBA71-AC54-45C8-9B21-BCB3DF6E085B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{82FCBA71-AC54-45C8-9B21-BCB3DF6E085B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{82FCBA71-AC54-45C8-9B21-BCB3DF6E085B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CDE4C963-67B5-47A6-A394-901E95EA40F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CDE4C963-67B5-47A6-A394-901E95EA40F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CDE4C963-67B5-47A6-A394-901E95EA40F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CDE4C963-67B5-47A6-A394-901E95EA40F7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0E13C365-F2CC-4A32-BDD0-52E2DB324734}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0E13C365-F2CC-4A32-BDD0-52E2DB324734}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0E13C365-F2CC-4A32-BDD0-52E2DB324734}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0E13C365-F2CC-4A32-BDD0-52E2DB324734}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {9414A502-1CCD-466A-9FFA-21B0297A8ECA}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
99
ComputerShopBusinessLogic/BusinessLogics/Batch.cs
Normal file
99
ComputerShopBusinessLogic/BusinessLogics/Batch.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class Batch : IBatchLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBatchStorage _batchStorage;
|
||||
|
||||
public Batch(ILogger<Batch> logger, IBatchStorage batchStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_batchStorage = batchStorage;
|
||||
}
|
||||
|
||||
public List<BatchViewModel> ReadList(BatchSearchModel? model)
|
||||
{
|
||||
var list = (model == null) ? _batchStorage.GetFullList() : _batchStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("Read null list");
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public BatchViewModel? ReadElement(BatchSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
var batch = _batchStorage.GetElement(model);
|
||||
if (batch == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement batch not found");
|
||||
return null;
|
||||
}
|
||||
return batch;
|
||||
}
|
||||
|
||||
public bool Create(BatchBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_batchStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(BatchBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_batchStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(BatchBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_batchStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(BatchBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
94
ComputerShopBusinessLogic/BusinessLogics/RequestLogic.cs
Normal file
94
ComputerShopBusinessLogic/BusinessLogics/RequestLogic.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class RequestLogic : IRequestLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRequestStorage _requestStorage;
|
||||
public RequestLogic(ILogger<RequestLogic> logger, IRequestStorage requestStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_requestStorage = requestStorage;
|
||||
}
|
||||
|
||||
public List<RequestViewModel>? ReadList(RequestSearchModel? model)
|
||||
{
|
||||
var list = (model == null ) ? _requestStorage.GetFullList() : _requestStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("Null list");
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public RequestViewModel? ReadElement(RequestSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
var element = _requestStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement request not found");
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_requestStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_requestStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ConnectRequestAssembly(int requestId, int assemblyId)
|
||||
{
|
||||
_logger.LogInformation("Connect Assembly {rId} with request {aId}", requestId, assemblyId);
|
||||
return _requestStorage.ConnectRequestAssembly(requestId, assemblyId);
|
||||
}
|
||||
|
||||
public bool Delete(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_requestStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
127
ComputerShopBusinessLogic/BusinessLogics/UserLogic.cs
Normal file
127
ComputerShopBusinessLogic/BusinessLogics/UserLogic.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class UserLogic : IUserLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUserStorage _userStorage;
|
||||
|
||||
public UserLogic(ILogger<IUserLogic> logger, IUserStorage userStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_userStorage = userStorage;
|
||||
}
|
||||
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
||||
{
|
||||
var list = model == null ? _userStorage.GetFullList() : _userStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("Null list user");
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public UserViewModel? ReadElement(UserSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
var element = _userStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement user not found");
|
||||
return null;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_userStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_userStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_userStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(UserBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Логин не существует", nameof(model.Login));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Пароль не существует", nameof(model.Password));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Почта не существует", nameof(model.Email));
|
||||
}
|
||||
|
||||
var user1 = _userStorage.GetElement(new UserSearchModel
|
||||
{
|
||||
Login = model.Login
|
||||
});
|
||||
|
||||
if (user1 != null && user1.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Логин занят");
|
||||
}
|
||||
|
||||
var user2 = _userStorage.GetElement(new UserSearchModel
|
||||
{
|
||||
Email = model.Email
|
||||
});
|
||||
|
||||
if (user2 != null && user2.Id != model.Id) {
|
||||
throw new InvalidOperationException("Почта занята");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
ComputerShopBusinessLogic/ComputerShopBusinessLogic.csproj
Normal file
17
ComputerShopBusinessLogic/ComputerShopBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
16
ComputerShopContracts/BindingModels/AssemblyBindingModel.cs
Normal file
16
ComputerShopContracts/BindingModels/AssemblyBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
|
||||
namespace ComputerShopContracts.BindingModels
|
||||
{
|
||||
public class AssemblyBindingModel : IAssemblyModel
|
||||
{
|
||||
public string AssemblyName { get; set; } = string.Empty;
|
||||
|
||||
public double Cost { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> AssemblyComponents { get; set; } = new();
|
||||
}
|
||||
}
|
18
ComputerShopContracts/BindingModels/BatchBindingModel.cs
Normal file
18
ComputerShopContracts/BindingModels/BatchBindingModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.BindingModels
|
||||
{
|
||||
public class BatchBindingModel : IBatchModel
|
||||
{
|
||||
public DateTime DateBatch { get; set; } = DateTime.Now;
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
}
|
||||
}
|
17
ComputerShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
17
ComputerShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
|
||||
namespace ComputerShopContracts.BindingModels
|
||||
{
|
||||
public class ComponentBindingModel : IComponentModel
|
||||
{
|
||||
public double Cost { get; set; }
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public int UserId { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
14
ComputerShopContracts/BindingModels/ProductBindingModel.cs
Normal file
14
ComputerShopContracts/BindingModels/ProductBindingModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
|
||||
namespace ComputerShopContracts.BindingModels
|
||||
{
|
||||
public class ProductBindingModel : IProductModel
|
||||
{
|
||||
public double Cost { get; set; }
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public int UserId { get; set; }
|
||||
public int? BatchId { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
16
ComputerShopContracts/BindingModels/RequestBindingModel.cs
Normal file
16
ComputerShopContracts/BindingModels/RequestBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.BindingModels
|
||||
{
|
||||
public class RequestBindingModel : IRequestModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime DateRequest { get; set; } = DateTime.Now;
|
||||
public int? AssemblyId { get; set; }
|
||||
}
|
||||
}
|
19
ComputerShopContracts/BindingModels/UserBindingModel.cs
Normal file
19
ComputerShopContracts/BindingModels/UserBindingModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.BindingModels
|
||||
{
|
||||
public class UserBindingModel : IUserModel
|
||||
{
|
||||
public string Fio { get; set; } = string.Empty;
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
public string Login { get; set; } = string.Empty; // TODO сделать адекватно
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
|
||||
namespace ComputerShopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IAssemblyLogic
|
||||
{
|
||||
List<AssemblyViewModel>? ReadList(AssemblySearchModel? Model);
|
||||
|
||||
AssemblyViewModel? ReadElement(AssemblySearchModel Model);
|
||||
|
||||
bool Create(AssemblyBindingModel Model);
|
||||
|
||||
bool Update(AssemblyBindingModel Model);
|
||||
|
||||
bool Delete(AssemblyBindingModel Model);
|
||||
}
|
||||
}
|
20
ComputerShopContracts/BusinessLogicContracts/IBatchLogic.cs
Normal file
20
ComputerShopContracts/BusinessLogicContracts/IBatchLogic.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IBatchLogic
|
||||
{
|
||||
List<BatchViewModel>? ReadList(BatchSearchModel? model);
|
||||
BatchViewModel? ReadElement(BatchSearchModel model);
|
||||
bool Create(BatchBindingModel model);
|
||||
bool Update(BatchBindingModel model);
|
||||
bool Delete(BatchBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
|
||||
namespace ComputerShopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
List<ComponentViewModel>? ReadList(ComponentSearchModel? Model);
|
||||
|
||||
ComponentViewModel? ReadElement(ComponentSearchModel Model);
|
||||
|
||||
bool Create(ComponentBindingModel Model);
|
||||
|
||||
bool Update(ComponentBindingModel Model);
|
||||
|
||||
bool Delete(ComponentBindingModel Model);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
|
||||
namespace ComputerShopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IProductLogic
|
||||
{
|
||||
List<ProductViewModel>? ReadList(ProductSearchModel? Model);
|
||||
|
||||
ProductViewModel? ReadElement(ProductSearchModel Model);
|
||||
|
||||
bool Create(ProductBindingModel Model);
|
||||
|
||||
bool Update(ProductBindingModel Model);
|
||||
|
||||
bool Delete(ProductBindingModel Model);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IRequestLogic
|
||||
{
|
||||
List<RequestViewModel>? ReadList(RequestSearchModel? model);
|
||||
RequestViewModel? ReadElement(RequestSearchModel model);
|
||||
bool Create(RequestBindingModel model);
|
||||
bool Update(RequestBindingModel model);
|
||||
bool Delete(RequestBindingModel model);
|
||||
bool ConnectRequestAssembly(int requestId, int assemblyId);
|
||||
}
|
||||
}
|
20
ComputerShopContracts/BusinessLogicContracts/IUserLogic.cs
Normal file
20
ComputerShopContracts/BusinessLogicContracts/IUserLogic.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IUserLogic
|
||||
{
|
||||
List<UserViewModel>? ReadList(UserSearchModel? model);
|
||||
UserViewModel? ReadElement(UserSearchModel model);
|
||||
bool Create(UserBindingModel model);
|
||||
bool Update(UserBindingModel model);
|
||||
bool Delete(UserBindingModel model);
|
||||
}
|
||||
}
|
13
ComputerShopContracts/ComputerShopContracts.csproj
Normal file
13
ComputerShopContracts/ComputerShopContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerShopDataModels\ComputerShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
10
ComputerShopContracts/SearchModels/AssemblySearchModel.cs
Normal file
10
ComputerShopContracts/SearchModels/AssemblySearchModel.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace ComputerShopContracts.SearchModels
|
||||
{
|
||||
public class AssemblySearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
|
||||
}
|
||||
}
|
16
ComputerShopContracts/SearchModels/BatchSearchModel.cs
Normal file
16
ComputerShopContracts/SearchModels/BatchSearchModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.SearchModels
|
||||
{
|
||||
public class BatchSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace ComputerShopContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
}
|
||||
}
|
11
ComputerShopContracts/SearchModels/ProductSearchModel.cs
Normal file
11
ComputerShopContracts/SearchModels/ProductSearchModel.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace ComputerShopContracts.SearchModels
|
||||
{
|
||||
public class ProductSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
|
||||
public int? BatchId { get; set; }
|
||||
}
|
||||
}
|
17
ComputerShopContracts/SearchModels/RequestSearchModel.cs
Normal file
17
ComputerShopContracts/SearchModels/RequestSearchModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.SearchModels
|
||||
{
|
||||
public class RequestSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? AssemblyId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
}
|
||||
}
|
19
ComputerShopContracts/SearchModels/UserSearchModel.cs
Normal file
19
ComputerShopContracts/SearchModels/UserSearchModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using ComputerShopDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.SearchModels
|
||||
{
|
||||
public class UserSearchModel
|
||||
{
|
||||
public string? Fio { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public int? Id { get; set; }
|
||||
public string? Login { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
}
|
21
ComputerShopContracts/StorageContracts/IAssemblyStorage.cs
Normal file
21
ComputerShopContracts/StorageContracts/IAssemblyStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
|
||||
namespace ComputerShopContracts.StorageContracts
|
||||
{
|
||||
public interface IAssemblyStorage
|
||||
{
|
||||
List<AssemblyViewModel> GetFullList();
|
||||
|
||||
List<AssemblyViewModel> GetFilteredList(AssemblySearchModel Model);
|
||||
|
||||
AssemblyViewModel? GetElement(AssemblySearchModel Model);
|
||||
|
||||
AssemblyViewModel? Insert(AssemblyBindingModel Model);
|
||||
|
||||
AssemblyViewModel? Update(AssemblyBindingModel Model);
|
||||
|
||||
AssemblyViewModel? Delete(AssemblyBindingModel Model);
|
||||
}
|
||||
}
|
20
ComputerShopContracts/StorageContracts/IBatchStorage.cs
Normal file
20
ComputerShopContracts/StorageContracts/IBatchStorage.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.StorageContracts
|
||||
{
|
||||
public interface IBatchStorage
|
||||
{
|
||||
List<BatchViewModel> GetFullList();
|
||||
BatchViewModel? GetElement(BatchSearchModel model);
|
||||
BatchViewModel? Insert(BatchBindingModel model);
|
||||
BatchViewModel? Update(BatchBindingModel model);
|
||||
BatchViewModel? Delete(BatchBindingModel model);
|
||||
}
|
||||
}
|
21
ComputerShopContracts/StorageContracts/IComponentStorage.cs
Normal file
21
ComputerShopContracts/StorageContracts/IComponentStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
|
||||
namespace ComputerShopContracts.StorageContracts
|
||||
{
|
||||
public interface IComponentStorage
|
||||
{
|
||||
List<ComponentViewModel> GetFullList();
|
||||
|
||||
List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model);
|
||||
|
||||
ComponentViewModel? GetElement(ComponentSearchModel Model);
|
||||
|
||||
ComponentViewModel? Insert(ComponentBindingModel Model);
|
||||
|
||||
ComponentViewModel? Update(ComponentBindingModel Model);
|
||||
|
||||
ComponentViewModel? Delete(ComponentBindingModel Model);
|
||||
}
|
||||
}
|
21
ComputerShopContracts/StorageContracts/IProductStorage.cs
Normal file
21
ComputerShopContracts/StorageContracts/IProductStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
|
||||
namespace ComputerShopContracts.StorageContracts
|
||||
{
|
||||
public interface IProductStorage
|
||||
{
|
||||
List<ProductViewModel> GetFullList();
|
||||
|
||||
List<ProductViewModel> GetFilteredList(ProductSearchModel Model);
|
||||
|
||||
ProductViewModel? GetElement(ProductSearchModel Model);
|
||||
|
||||
ProductViewModel? Insert(ProductBindingModel Model);
|
||||
|
||||
ProductViewModel? Update(ProductBindingModel Model);
|
||||
|
||||
ProductViewModel? Delete(ProductBindingModel Model);
|
||||
}
|
||||
}
|
21
ComputerShopContracts/StorageContracts/IRequestStorage.cs
Normal file
21
ComputerShopContracts/StorageContracts/IRequestStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.StorageContracts
|
||||
{
|
||||
public interface IRequestStorage
|
||||
{
|
||||
List<RequestViewModel> GetFullList();
|
||||
RequestViewModel? GetElement(RequestSearchModel model);
|
||||
RequestViewModel? Insert(RequestBindingModel model);
|
||||
RequestViewModel? Update(RequestBindingModel model);
|
||||
RequestViewModel? Delete(RequestBindingModel model);
|
||||
bool ConnectRequestAssembly(int requestId, int assemblyId);
|
||||
}
|
||||
}
|
20
ComputerShopContracts/StorageContracts/IUserStorage.cs
Normal file
20
ComputerShopContracts/StorageContracts/IUserStorage.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.StorageContracts
|
||||
{
|
||||
public interface IUserStorage
|
||||
{
|
||||
List<UserViewModel> GetFullList();
|
||||
UserViewModel? GetElement(UserSearchModel model);
|
||||
UserViewModel? Insert(UserBindingModel model);
|
||||
UserViewModel? Update(UserBindingModel model);
|
||||
UserViewModel? Delete(UserBindingModel model);
|
||||
}
|
||||
}
|
18
ComputerShopContracts/ViewModels/AssemblyViewModel.cs
Normal file
18
ComputerShopContracts/ViewModels/AssemblyViewModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerShopContracts.ViewModels
|
||||
{
|
||||
public class AssemblyViewModel : IAssemblyModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
[DisplayName("Имя сборки")]
|
||||
public string AssemblyName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> AssemblyComponents { get; set; } = new();
|
||||
}
|
||||
}
|
25
ComputerShopContracts/ViewModels/BatchViewModel.cs
Normal file
25
ComputerShopContracts/ViewModels/BatchViewModel.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.ViewModels
|
||||
{
|
||||
public class BatchViewModel : IBatchModel
|
||||
{
|
||||
[DisplayName("Дата партии")]
|
||||
public DateTime DateBatch { get; set; } = DateTime.Now;
|
||||
|
||||
public int ProductId { get; set; }
|
||||
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
22
ComputerShopContracts/ViewModels/ComponentViewModel.cs
Normal file
22
ComputerShopContracts/ViewModels/ComponentViewModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerShopContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[DisplayName("Имя комплектующего")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Описание комплектующего")]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
}
|
||||
}
|
23
ComputerShopContracts/ViewModels/ProductViewModel.cs
Normal file
23
ComputerShopContracts/ViewModels/ProductViewModel.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerShopContracts.ViewModels
|
||||
{
|
||||
public class ProductViewModel : IProductModel
|
||||
{
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[DisplayName("Название товара")]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Описание товара")]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public int UserId { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public int? BatchId { get; set; }
|
||||
|
||||
}
|
||||
}
|
23
ComputerShopContracts/ViewModels/RequestViewModel.cs
Normal file
23
ComputerShopContracts/ViewModels/RequestViewModel.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.ViewModels
|
||||
{
|
||||
public class RequestViewModel : IRequestModel
|
||||
{
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateRequest { get; set; } = DateTime.Now;
|
||||
public int? AssemblyId { get; set; }
|
||||
public IAssemblyModel? Assembly { get; set; }
|
||||
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
|
||||
}
|
||||
}
|
30
ComputerShopContracts/ViewModels/UserViewModel.cs
Normal file
30
ComputerShopContracts/ViewModels/UserViewModel.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using ComputerShopDataModels.Enums;
|
||||
using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopContracts.ViewModels
|
||||
{
|
||||
public class UserViewModel : IUserModel
|
||||
{
|
||||
[DisplayName("ФИО")]
|
||||
public string Fio { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Номер телефона")]
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Логин")]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Почта")]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
9
ComputerShopDataModels/ComputerShopDataModels.csproj
Normal file
9
ComputerShopDataModels/ComputerShopDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
28
ComputerShopDataModels/Models/IAssemblyModel.cs
Normal file
28
ComputerShopDataModels/Models/IAssemblyModel.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace ComputerShopDataModels.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Сборка
|
||||
/// </summary>
|
||||
public interface IAssemblyModel : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Название сборки
|
||||
/// </summary>
|
||||
string AssemblyName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Стоимость
|
||||
/// </summary>
|
||||
double Cost { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Пользователь, который создал сборку
|
||||
/// </summary>
|
||||
int UserId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Список комплектующих
|
||||
/// </summary>
|
||||
Dictionary<int, (IComponentModel, int)> AssemblyComponents { get; }
|
||||
}
|
||||
}
|
25
ComputerShopDataModels/Models/IBatchModel.cs
Normal file
25
ComputerShopDataModels/Models/IBatchModel.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDataModels.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Партия товара
|
||||
/// </summary>
|
||||
public interface IBatchModel : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Дата
|
||||
/// </summary>
|
||||
DateTime DateBatch { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ID товара
|
||||
/// </summary>
|
||||
int ProductId { get; }
|
||||
}
|
||||
}
|
29
ComputerShopDataModels/Models/IComponentModel.cs
Normal file
29
ComputerShopDataModels/Models/IComponentModel.cs
Normal file
@ -0,0 +1,29 @@
|
||||
namespace ComputerShopDataModels.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Комплектующее
|
||||
/// </summary>
|
||||
public interface IComponentModel : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Стоимость комплектующего
|
||||
/// </summary>
|
||||
double Cost { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Название комплектующего
|
||||
/// </summary>
|
||||
string ComponentName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Название комплектующего
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Пользователь, который добавил комплектующее
|
||||
/// </summary>
|
||||
int UserId { get; }
|
||||
|
||||
}
|
||||
}
|
7
ComputerShopDataModels/Models/IId.cs
Normal file
7
ComputerShopDataModels/Models/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace ComputerShopDataModels.Models
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
33
ComputerShopDataModels/Models/IProductModel.cs
Normal file
33
ComputerShopDataModels/Models/IProductModel.cs
Normal file
@ -0,0 +1,33 @@
|
||||
namespace ComputerShopDataModels.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Товар
|
||||
/// </summary>
|
||||
public interface IProductModel : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Стоимость товара
|
||||
/// </summary>
|
||||
double Cost { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Название товара
|
||||
/// </summary>
|
||||
string ProductName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Название товара
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Пользователь, который добавил товар
|
||||
/// </summary>
|
||||
int UserId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Привязка товара к партии товаров
|
||||
/// </summary>
|
||||
int? BatchId { get; }
|
||||
}
|
||||
}
|
25
ComputerShopDataModels/Models/IRequestModel.cs
Normal file
25
ComputerShopDataModels/Models/IRequestModel.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDataModels.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Заявка
|
||||
/// </summary>
|
||||
public interface IRequestModel : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Дата создания заявки
|
||||
/// </summary>
|
||||
DateTime DateRequest { get; }
|
||||
|
||||
/// <summary>
|
||||
/// ID сборки
|
||||
/// </summary>
|
||||
int? AssemblyId { get; }
|
||||
|
||||
}
|
||||
}
|
17
ComputerShopDataModels/Models/IUserModel.cs
Normal file
17
ComputerShopDataModels/Models/IUserModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDataModels.Models
|
||||
{
|
||||
public interface IUserModel : IId
|
||||
{
|
||||
string Fio { get; }
|
||||
string PhoneNumber { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
string Email { get; }
|
||||
}
|
||||
}
|
32
ComputerShopDatabaseImplement/ComputerShopDatabase.cs
Normal file
32
ComputerShopDatabaseImplement/ComputerShopDatabase.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using ComputerShopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerShopDatabaseImplement
|
||||
{
|
||||
public class ComputerShopDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder OptionsBuilder)
|
||||
{
|
||||
if (!OptionsBuilder.IsConfigured)
|
||||
{
|
||||
OptionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=ComputerStoreDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
|
||||
}
|
||||
|
||||
base.OnConfiguring(OptionsBuilder);
|
||||
|
||||
}
|
||||
public virtual DbSet<User> Users { get; set; }
|
||||
|
||||
public virtual DbSet<Component> Components { get; set; }
|
||||
|
||||
public virtual DbSet<Assembly> Assemblies { get; set; }
|
||||
|
||||
public virtual DbSet<AssemblyComponent> AssemblyComponents { get; set; }
|
||||
|
||||
public virtual DbSet<Product> Products { get; set; }
|
||||
|
||||
public virtual DbSet<Request> Requests { get; set; }
|
||||
public virtual DbSet<Batch> Batchs { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.18" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.18" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.18">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="netcore-psql-util" Version="1.2.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
|
||||
<ProjectReference Include="..\ComputerShopDataModels\ComputerShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
99
ComputerShopDatabaseImplement/Implements/AssemblyStorage.cs
Normal file
99
ComputerShopDatabaseImplement/Implements/AssemblyStorage.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class AssemblyStorage : IAssemblyStorage
|
||||
{
|
||||
public List<AssemblyViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
return Context.Assemblies
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Assembly)
|
||||
.Select(x => x.ViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<AssemblyViewModel> GetFilteredList(AssemblySearchModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
// сборки по комплектующим
|
||||
return Context.Assemblies
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Assembly)
|
||||
.Select(x => x.ViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public AssemblyViewModel? GetElement(AssemblySearchModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
return Context.Assemblies
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Assembly)
|
||||
.FirstOrDefault(x => x.Id == Model.Id)?
|
||||
.ViewModel;
|
||||
}
|
||||
|
||||
public AssemblyViewModel? Insert(AssemblyBindingModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
var NewAssembly = Assembly.Create(Context, Model);
|
||||
Context.Assemblies.Add(NewAssembly);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewAssembly.ViewModel;
|
||||
}
|
||||
|
||||
public AssemblyViewModel? Update(AssemblyBindingModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
using var Transaction = Context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var ExistingAssembly = Context.Assemblies.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (ExistingAssembly == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ExistingAssembly.Update(Model);
|
||||
Context.SaveChanges();
|
||||
ExistingAssembly.UpdateComponents(Context, Model);
|
||||
Transaction.Commit();
|
||||
|
||||
return ExistingAssembly.ViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public AssemblyViewModel? Delete(AssemblyBindingModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
var ExistingAssembly = Context.Assemblies.Include(x => x.Components).FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (ExistingAssembly == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Context.Assemblies.Remove(ExistingAssembly);
|
||||
Context.SaveChanges();
|
||||
|
||||
return ExistingAssembly.ViewModel;
|
||||
}
|
||||
}
|
||||
}
|
111
ComputerShopDatabaseImplement/Implements/BatchStorage.cs
Normal file
111
ComputerShopDatabaseImplement/Implements/BatchStorage.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class BatchStorage : IBatchStorage
|
||||
{
|
||||
public List<BatchViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
|
||||
return context.Batchs
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<BatchViewModel> GetFilteredList(BatchSearchModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
//сортировка партий по дате
|
||||
if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
return context.Batchs
|
||||
.Where(x => (x.DateBatch >= model.DateFrom && x.DateBatch <= model.DateTo))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
//партии по товарам
|
||||
return context.Batchs
|
||||
.Where(x => x.ProductId == model.ProductId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public BatchViewModel? GetElement(BatchSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerShopDatabase();
|
||||
return context.Batchs
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public BatchViewModel? Insert(BatchBindingModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
var newBatch = Batch.Create(context, model);
|
||||
|
||||
if (newBatch == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Batchs.Add(newBatch);
|
||||
context.SaveChanges();
|
||||
|
||||
return newBatch.GetViewModel;
|
||||
}
|
||||
|
||||
public BatchViewModel? Update(BatchBindingModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var batch = context.Batchs.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (batch == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
batch.Update(model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return context.Batchs
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public BatchViewModel? Delete(BatchBindingModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
var batch = context.Batchs.FirstOrDefault(y => y.Id == model.Id);
|
||||
if (batch != null)
|
||||
{
|
||||
context.Batchs.Remove(batch);
|
||||
context.SaveChanges();
|
||||
return batch.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
82
ComputerShopDatabaseImplement/Implements/ComponentStorage.cs
Normal file
82
ComputerShopDatabaseImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDatabaseImplement.Models;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
return Context.Components
|
||||
.Select(x => x.ViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
// колмплектующие по пользователям (дополнительно)
|
||||
return Context.Components
|
||||
.Where(x => x.UserId == Model.UserId)
|
||||
.Select(x => x.ViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
return Context.Components
|
||||
.FirstOrDefault(x => x.Id == Model.Id)?
|
||||
.ViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
var NewComponent = Component.Create(Model);
|
||||
Context.Components.Add(NewComponent);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewComponent.ViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
var ExistingComponent = Context.Components.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (ExistingComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ExistingComponent.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return ExistingComponent.ViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
var ExistingComponent = Context.Components.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (ExistingComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Context.Components.Remove(ExistingComponent);
|
||||
Context.SaveChanges();
|
||||
|
||||
return ExistingComponent.ViewModel;
|
||||
}
|
||||
}
|
||||
}
|
102
ComputerShopDatabaseImplement/Implements/ProductStorage.cs
Normal file
102
ComputerShopDatabaseImplement/Implements/ProductStorage.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class ProductStorage : IProductStorage
|
||||
{
|
||||
public List<ProductViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
return Context.Products
|
||||
.Select(x => x.ViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
// сортировка по партиям
|
||||
if (Model.BatchId.HasValue)
|
||||
{
|
||||
return Context.Products
|
||||
.Where(x => x.UserId == Model.UserId && x.BatchId == Model.BatchId)
|
||||
.Select(x => x.ViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return Context.Products
|
||||
.Where(x => x.UserId == Model.UserId)
|
||||
.Select(x => x.ViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ProductViewModel? GetElement(ProductSearchModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
return Context.Products
|
||||
.FirstOrDefault(x => x.Id == Model.Id)?
|
||||
.ViewModel;
|
||||
}
|
||||
|
||||
public ProductViewModel? Insert(ProductBindingModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
var NewProduct = Product.Create(Context, Model);
|
||||
Context.Products.Add(NewProduct);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewProduct.ViewModel;
|
||||
}
|
||||
|
||||
public ProductViewModel? Update(ProductBindingModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
using var Transaction = Context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var ExistingProduct = Context.Products.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (ExistingProduct == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ExistingProduct.Update(Model);
|
||||
Context.SaveChanges();
|
||||
Transaction.Commit();
|
||||
|
||||
return ExistingProduct.ViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ProductViewModel? Delete(ProductBindingModel Model)
|
||||
{
|
||||
using var Context = new ComputerShopDatabase();
|
||||
|
||||
var ExistingProduct = Context.Products.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (ExistingProduct == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Context.Products.Remove(ExistingProduct);
|
||||
Context.SaveChanges();
|
||||
|
||||
return ExistingProduct.ViewModel;
|
||||
}
|
||||
}
|
||||
}
|
104
ComputerShopDatabaseImplement/Implements/RequestStorage.cs
Normal file
104
ComputerShopDatabaseImplement/Implements/RequestStorage.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class RequestStorage : IRequestStorage
|
||||
{
|
||||
public List<RequestViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
return context.Requests
|
||||
.Include(x => x.Assembly)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public RequestViewModel? GetElement(RequestSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerShopDatabase();
|
||||
return context.Requests
|
||||
.Include(x => x.Assembly)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public RequestViewModel? Insert(RequestBindingModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
var newRequest = Request.Create(context, model);
|
||||
if (newRequest == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Requests.Add(newRequest);
|
||||
context.SaveChanges();
|
||||
return newRequest.GetViewModel;
|
||||
}
|
||||
|
||||
public RequestViewModel? Update(RequestBindingModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var request = context.Requests.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (request == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
request.Update(model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return request.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public RequestViewModel? Delete(RequestBindingModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
var request = context.Requests
|
||||
.FirstOrDefault(y => y.Id == model.Id);
|
||||
if (request != null)
|
||||
{
|
||||
context.Requests.Remove(request);
|
||||
context.SaveChanges();
|
||||
return request.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool ConnectRequestAssembly(int requestId, int assemblyId)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
var request = context.Requests.FirstOrDefault(x => x.Id == requestId);
|
||||
var assembly = context.Assemblies.FirstOrDefault(x => x.Id == assemblyId);
|
||||
if (request == null || assembly == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
request.ConnectAssembly(context, assemblyId);
|
||||
context.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
68
ComputerShopDatabaseImplement/Implements/UserStorage.cs
Normal file
68
ComputerShopDatabaseImplement/Implements/UserStorage.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.StorageContracts;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class UserStorage : IUserStorage
|
||||
{
|
||||
public List<UserViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
return context.Users.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
|
||||
public UserViewModel? GetElement(UserSearchModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
return context.Users.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public UserViewModel? Insert(UserBindingModel model)
|
||||
{
|
||||
var newUser = User.Create(model);
|
||||
if (newUser == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerShopDatabase();
|
||||
context.Users.Add(newUser);
|
||||
context.SaveChanges();
|
||||
return newUser.GetViewModel;
|
||||
}
|
||||
|
||||
public UserViewModel? Update(UserBindingModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
var user = context.Users.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (user == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
user.Update(model);
|
||||
context.SaveChanges();
|
||||
return user.GetViewModel;
|
||||
}
|
||||
|
||||
public UserViewModel? Delete(UserBindingModel model)
|
||||
{
|
||||
using var context = new ComputerShopDatabase();
|
||||
var user = context.Users.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (user != null)
|
||||
{
|
||||
context.Users.Remove(user);
|
||||
context.SaveChanges();
|
||||
return user.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
115
ComputerShopDatabaseImplement/Models/Assembly.cs
Normal file
115
ComputerShopDatabaseImplement/Models/Assembly.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
public class Assembly : IAssemblyModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string AssemblyName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Cost { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int UserId { get; private set; }
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<AssemblyComponent> Components { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _assemblyComponents;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> AssemblyComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_assemblyComponents == null)
|
||||
{
|
||||
_assemblyComponents = Components.ToDictionary(
|
||||
AsmComp => AsmComp.ComponentId,
|
||||
AsmComp => (AsmComp.Component as IComponentModel, AsmComp.Count)
|
||||
);
|
||||
}
|
||||
|
||||
return _assemblyComponents;
|
||||
}
|
||||
}
|
||||
|
||||
public static Assembly Create(ComputerShopDatabase Context, AssemblyBindingModel Model)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = Model.Id,
|
||||
AssemblyName = Model.AssemblyName,
|
||||
Cost = Model.Cost,
|
||||
UserId = Model.UserId,
|
||||
Components = Model.AssemblyComponents.Select(x => new AssemblyComponent
|
||||
{
|
||||
Component = Context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(AssemblyBindingModel Model)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Model.AssemblyName))
|
||||
{
|
||||
AssemblyName = Model.AssemblyName;
|
||||
}
|
||||
|
||||
Cost = Model.Cost;
|
||||
}
|
||||
|
||||
public void UpdateComponents(ComputerShopDatabase Context, AssemblyBindingModel Model)
|
||||
{
|
||||
var AssemblyComponents = Context.AssemblyComponents.Where(x => x.AssemblyId == Model.Id).ToList();
|
||||
if (AssemblyComponents != null && AssemblyComponents.Count > 0)
|
||||
{
|
||||
Context.AssemblyComponents
|
||||
.RemoveRange(AssemblyComponents
|
||||
.Where(x => !Model.AssemblyComponents.ContainsKey(x.ComponentId)));
|
||||
Context.SaveChanges();
|
||||
|
||||
foreach (var ComponentToUpdate in AssemblyComponents)
|
||||
{
|
||||
ComponentToUpdate.Count = Model.AssemblyComponents[ComponentToUpdate.ComponentId].Item2;
|
||||
Model.AssemblyComponents.Remove(ComponentToUpdate.ComponentId);
|
||||
}
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
var CurrentAssembly = Context.Assemblies.First(x => x.Id == Id);
|
||||
foreach (var AssemblyComponent in Model.AssemblyComponents)
|
||||
{
|
||||
Context.AssemblyComponents.Add(new AssemblyComponent
|
||||
{
|
||||
Assembly = CurrentAssembly,
|
||||
Component = Context.Components.First(x => x.Id == AssemblyComponent.Key),
|
||||
Count = AssemblyComponent.Value.Item2
|
||||
});
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
_assemblyComponents = null;
|
||||
}
|
||||
|
||||
public AssemblyViewModel ViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
AssemblyName = AssemblyName,
|
||||
Cost = Cost,
|
||||
UserId = UserId,
|
||||
AssemblyComponents = AssemblyComponents,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
22
ComputerShopDatabaseImplement/Models/AssemblyComponent.cs
Normal file
22
ComputerShopDatabaseImplement/Models/AssemblyComponent.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
public class AssemblyComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int AssemblyId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Assembly Assembly { get; set; } = new();
|
||||
|
||||
public virtual Component Component { get; set; } = new();
|
||||
}
|
||||
}
|
51
ComputerShopDatabaseImplement/Models/Batch.cs
Normal file
51
ComputerShopDatabaseImplement/Models/Batch.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDataModels.Models;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
public class Batch : IBatchModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime DateBatch { get; set; } = DateTime.Now;
|
||||
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
public static Batch Create(ComputerShopDatabase context, BatchBindingModel model)
|
||||
{
|
||||
return new Batch()
|
||||
{
|
||||
Id = model.Id,
|
||||
DateBatch = model.DateBatch,
|
||||
ProductId = model.ProductId,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(BatchBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ProductId = model.ProductId;
|
||||
DateBatch = model.DateBatch;
|
||||
}
|
||||
|
||||
public BatchViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DateBatch = DateBatch,
|
||||
ProductId = ProductId
|
||||
};
|
||||
}
|
||||
}
|
56
ComputerShopDatabaseImplement/Models/Component.cs
Normal file
56
ComputerShopDatabaseImplement/Models/Component.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Cost { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Description { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int UserId { get; private set; }
|
||||
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<AssemblyComponent> AssemblyComponents { get; set; } = new();
|
||||
|
||||
public static Component Create(ComponentBindingModel Model)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = Model.Id,
|
||||
Cost = Model.Cost,
|
||||
ComponentName = Model.ComponentName,
|
||||
UserId = Model.UserId,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel Model)
|
||||
{
|
||||
Cost = Model.Cost;
|
||||
ComponentName = Model.ComponentName;
|
||||
|
||||
}
|
||||
|
||||
public ComponentViewModel ViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Cost = Cost,
|
||||
ComponentName = ComponentName,
|
||||
UserId = UserId,
|
||||
|
||||
};
|
||||
}
|
||||
}
|
67
ComputerShopDatabaseImplement/Models/Product.cs
Normal file
67
ComputerShopDatabaseImplement/Models/Product.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
public class Product : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int UserId { get; set; }
|
||||
|
||||
public int? BatchId { get; set; }
|
||||
|
||||
|
||||
public static Product Create(ComputerShopDatabase Context, ProductBindingModel Model)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = Model.Id,
|
||||
Cost = Model.Cost,
|
||||
ProductName = Model.ProductName,
|
||||
Description = Model.Description,
|
||||
UserId = Model.UserId,
|
||||
BatchId = Model.BatchId,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ProductBindingModel Model)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Model.ProductName))
|
||||
{
|
||||
ProductName = Model.ProductName;
|
||||
}
|
||||
|
||||
Cost = Model.Cost;
|
||||
ProductName = Model.ProductName;
|
||||
Description = Model.Description;
|
||||
UserId = Model.UserId;
|
||||
BatchId = Model.BatchId;
|
||||
}
|
||||
|
||||
public ProductViewModel ViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Cost = Cost,
|
||||
ProductName = ProductName,
|
||||
Description = Description,
|
||||
UserId = UserId,
|
||||
BatchId = BatchId,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
58
ComputerShopDatabaseImplement/Models/Request.cs
Normal file
58
ComputerShopDatabaseImplement/Models/Request.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
public class Request : IRequestModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
public int? AssemblyId { get; set; }
|
||||
|
||||
public virtual Assembly? Assembly { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public DateTime DateRequest { get; set; }
|
||||
|
||||
|
||||
public static Request Create(ComputerShopDatabase context, RequestBindingModel model)
|
||||
{
|
||||
return new Request() {
|
||||
Id = model.Id,
|
||||
AssemblyId = model.AssemblyId,
|
||||
Assembly = model.AssemblyId.HasValue ? context.Assemblies.First(x => x.Id == model.AssemblyId) : null,
|
||||
DateRequest = model.DateRequest,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(RequestBindingModel model)
|
||||
{
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public RequestViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
AssemblyId = AssemblyId,
|
||||
Assembly = Assembly,
|
||||
DateRequest = DateRequest,
|
||||
};
|
||||
|
||||
public void ConnectAssembly(ComputerShopDatabase context, int assemblyId)
|
||||
{
|
||||
AssemblyId = assemblyId;
|
||||
Assembly = context.Assemblies.First(x => x.Id == assemblyId);
|
||||
}
|
||||
}
|
||||
}
|
70
ComputerShopDatabaseImplement/Models/User.cs
Normal file
70
ComputerShopDatabaseImplement/Models/User.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using ComputerShopDataModels.Enums;
|
||||
using ComputerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
public class User : IUserModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string Fio { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
|
||||
public static User Create(UserBindingModel model)
|
||||
{
|
||||
return new User
|
||||
{
|
||||
Id = model.Id,
|
||||
Fio = model.Fio,
|
||||
PhoneNumber = model.PhoneNumber,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
Email = model.Email,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(UserBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Fio = model.Fio;
|
||||
PhoneNumber = model.PhoneNumber;
|
||||
Login = model.Login;
|
||||
Password = model.Password;
|
||||
Email = model.Email;
|
||||
}
|
||||
|
||||
public UserViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Fio = Fio,
|
||||
PhoneNumber = PhoneNumber,
|
||||
Login = Login,
|
||||
Password = Password,
|
||||
Email = Email,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user