Compare commits

...

25 Commits

Author SHA1 Message Date
Илья Федотов
ccb78dd53d Merge branch 'ReportLogic' of https://git.is.ulstu.ru/Ilfedotov.01/CourseWorkElectronicsShop into ReportLogic 2024-04-29 19:35:41 +04:00
Илья Федотов
0975a9b4d6 Report logis запрос нв получение данных из бд 2024-04-29 19:35:19 +04:00
4a958769f0 Mb not done 2024-04-29 19:34:14 +04:00
Илья Федотов
d07ef5499f Report logis запрос нв получение данных из бд 2024-04-29 19:33:15 +04:00
Илья Федотов
d934652b6c data base fix 2024-04-29 18:34:49 +04:00
Илья Федотов
11ea6cc0c0 Merge branch 'DataBaseImplement_02' of https://git.is.ulstu.ru/Ilfedotov.01/CourseWorkElectronicsShop into DataBaseImplement_02 2024-04-29 18:01:28 +04:00
858d42295b Trabls 2024-04-29 18:00:54 +04:00
99b0e691c4 Last fix ProductList 2024-04-29 18:00:54 +04:00
a8beee0d2c Trabls 2024-04-29 17:59:45 +04:00
45205630a5 Last fix ProductList 2024-04-29 01:55:20 +04:00
Илья Федотов
134f7d6cef Business logic 0.2 2024-04-29 01:28:41 +04:00
Илья Федотов
02d78da38f fixed 0.5 2024-04-29 00:44:49 +04:00
Илья Федотов
15f995b6ce fixed 0.4 категории воскресли! 2024-04-28 23:53:21 +04:00
Илья Федотов
f899455329 fixed 0.3 :/ 2024-04-28 23:36:49 +04:00
Илья Федотов
3cba2df163 fixed 0.2 :c 2024-04-28 23:33:49 +04:00
Илья Федотов
64532a3804 fixed :) 2024-04-28 23:24:54 +04:00
Илья Федотов
8770645a82 Total dead 2024-04-28 23:09:52 +04:00
ffc2c88104 Total dead 2024-04-28 23:08:09 +04:00
Илья Федотов
f931b8c14e Merge branch 'BusinessLogic' of https://git.is.ulstu.ru/Ilfedotov.01/CourseWorkElectronicsShop into BusinessLogic 2024-04-28 21:25:57 +04:00
Илья Федотов
47d59c7bfb Business logic добавить хранилище, убрать затычки! 0.1 2024-04-28 21:23:43 +04:00
Илья Федотов
4b0183ae91 Business logic добавить хранилище, убрать затычки! 0.1 2024-04-28 21:20:10 +04:00
6a7395b3b5 Storage add 2024-04-28 20:59:10 +04:00
Илья Федотов
9c049cd819 Contracts исправил модели! 0.2 2024-04-28 20:14:44 +04:00
Илья Федотов
2587d43871 Contracts 0.1 2024-04-27 13:01:57 +04:00
Илья Федотов
3b361e18fc Data models 0.1 2024-04-27 12:58:16 +04:00
59 changed files with 2232 additions and 0 deletions

View File

@ -3,7 +3,37 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicsShopDataModels", "ElectronicsShopDataModels\ElectronicsShopDataModels.csproj", "{380E3833-D9AE-46C7-8881-9B15B8559411}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicsShopContracts", "ElectronicsShopContracts\ElectronicsShopContracts.csproj", "{69411E41-F304-4D1B-8F15-48DD08585C7A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicsShopBusinessLogic", "ElectronicsShopBusinessLogic\ElectronicsShopBusinessLogic.csproj", "{0CCDB712-EE03-4050-AC4B-4315FF14ABD2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicsShopDataBaseImplement", "ElectronicsShopDataBaseImplement\ElectronicsShopDataBaseImplement.csproj", "{03442D38-4C09-49D1-85F3-F8F563072F9B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{380E3833-D9AE-46C7-8881-9B15B8559411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{380E3833-D9AE-46C7-8881-9B15B8559411}.Debug|Any CPU.Build.0 = Debug|Any CPU
{380E3833-D9AE-46C7-8881-9B15B8559411}.Release|Any CPU.ActiveCfg = Release|Any CPU
{380E3833-D9AE-46C7-8881-9B15B8559411}.Release|Any CPU.Build.0 = Release|Any CPU
{69411E41-F304-4D1B-8F15-48DD08585C7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69411E41-F304-4D1B-8F15-48DD08585C7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69411E41-F304-4D1B-8F15-48DD08585C7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69411E41-F304-4D1B-8F15-48DD08585C7A}.Release|Any CPU.Build.0 = Release|Any CPU
{0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Release|Any CPU.Build.0 = Release|Any CPU
{03442D38-4C09-49D1-85F3-F8F563072F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03442D38-4C09-49D1-85F3-F8F563072F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03442D38-4C09-49D1-85F3-F8F563072F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03442D38-4C09-49D1-85F3-F8F563072F9B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection

View File

@ -0,0 +1,89 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class CategoryProductLogic : ICategoryProductLogic
{
private readonly ILogger _logger;
private readonly ICategoryProductStorage _storage;
public CategoryProductLogic(ILogger<CategoryProductLogic> logger, ICategoryProductStorage storage) {
_logger = logger;
_storage = storage;
}
public bool Create(CategoryProductBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null) {
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CategoryProductBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete. ID:{model.ID}");
if (_storage.Insert(model) == null) {
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Update(CategoryProductBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null) {
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public List<CategoryProductViewModel>? ReadList(CategoryProductSearchModel? model)
{
_logger.LogInformation($"ReadList. ID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
if (list == null) {
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation($"ReadList. Count:{list.Count}");
return list;
}
private void CheckModel(CategoryProductBindingModel model, bool withParams = true) {
if (model == null) {
throw new ArgumentNullException(nameof(model));
}
if (!withParams) {
return;
}
if (string.IsNullOrEmpty(model.Name)) {
throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name));
}
_logger.LogInformation($"CategoryProduct. ID:{model.ID}.Name:{model.Name}");
var element = _storage.GetElement(new CategoryProductSearchModel
{
Name = model.Name
});
if (element != null && element.ID != model.ID) {
throw new InvalidOperationException("Категория с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,104 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _storage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage storage) {
_logger = logger;
_storage = storage;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
model.Status = OrderStatus.Принят;
if (_storage.Insert(model) == null) {
_logger.LogInformation("Insert operation failed");
return false;
}
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выдан);
}
public bool FinishOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Готов);
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation($"ReadList:ID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); ;
if (list == null) {
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation($"ReadList.Count:{list.Count}");
return list;
}
private void CheckModel(OrderBindingModel model, bool withParams = true) {
if (model == null) {
throw new ArgumentNullException(nameof(model));
}
if (!withParams) {
return;
}
if (string.IsNullOrEmpty((model.ID).ToString())) {
throw new ArgumentNullException("Нет ID заказа", nameof(model.ID));
}
if (model.Sum <= 0) {
throw new ArgumentNullException("Цена зака должна быть больше 0", nameof(model.Sum));
}
_logger.LogInformation($"Order. ID:{model.ID}.Sum:{model.Sum}.Status:{model.Status}.PaymeantOption:{model.PaymeantOption}." +
$"DateCreate:{model.DateCreate}.DataImplement:{model.DateImplement}");
}
private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus)
{
CheckModel(model, false);
var viewModel = _storage.GetElement(new OrderSearchModel { ID = model.ID });
if (viewModel == null) {
throw new ArgumentNullException(nameof(model));
}
if (viewModel.Status + 1 != newOrderStatus) {
_logger.LogWarning("Status update to " + newOrderStatus.ToString() + " operation failed.");
return false;
}
model.Status = newOrderStatus;
if (model.Status == OrderStatus.Готов) {
model.DateImplement = DateTime.Now;
}
else {
model.DateImplement = viewModel.DateImplement;
}
if (_storage.Update(model) == null) {
_logger.LogWarning("Update operarion failed");
return false;
}
return true;
}
}
}

View File

@ -0,0 +1,99 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class ProductLogic : IProductLogic
{
private readonly ILogger _logger;
private readonly IProductStorage _storage;
public ProductLogic(ILogger<ProductLogic> logger, IProductStorage productStorage) {
_logger = logger;
_storage = productStorage;
}
public bool Create(ProductBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null) {
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ProductBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete. ID:{model.ID}");
if (_storage.Delete(model) == null) {
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Update(ProductBindingModel model)
{
CheckModel(model);
if (_storage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public ProductViewModel? ReadElement(ProductSearchModel? model)
{
if (model == null) throw new ArgumentNullException(nameof(model));
_logger.LogInformation($"ReadElement. ProductName:{model.ProductName}. ID:{model.ID}");
var element = _storage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement. elementn not found");
return null;
}
_logger.LogInformation($"ReadElement find. ID:{element.ID}");
return element;
}
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
{
_logger.LogInformation($"ReadList. ProductName:{model?.ProductName}. ID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation($"ReadList. Count:{list.Count}");
return list;
}
private void CheckModel(ProductBindingModel model, bool withParams = true)
{
if (model == null) throw new ArgumentNullException(nameof(model));
if (!withParams) return;
if (string.IsNullOrEmpty(model.ProductName))
throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName));
if (model.Price <= 0)
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
_logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}.Count:{model.Count}" +
$".CategoryID:{model.CategoryID}");
var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName });
if (element != null && element.ID != model.ID)
throw new InvalidOperationException("Продукт с таким названием уже есть");
}
}
}

View File

@ -0,0 +1,42 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class ReportLogic : IReportLogic
{
private readonly IOrderStorage _orderStorage;
private readonly IProductStorage _productStorag;
public ReportLogic(IOrderStorage orderStorage, IProductStorage productStorag) {
_orderStorage = orderStorage;
_productStorag = productStorag;
}
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model) {
throw new NotImplementedException();
}
// Получение списка заказов за определенный период
public List<ReportOrdersViewModel> GerOrders(ReportBindingModel model) {
return _orderStorage.GetFilteredList(new OrderSearchModel {
DateFrom = model.DateFrom,
DateTo = model.DateTo,
}).Select(x => new ReportOrdersViewModel {
ID = x.ID,
DateCreate = x.DateCreate,
Sum = x.Sum,
PaymeantOption = x.PaymeantOption.ToString(),
OrderStatus = x.Status.ToString(),
}).ToList();
}
}
}

View File

@ -0,0 +1,99 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class RoleLogic : IRoleLogic
{
private readonly ILogger _logger;
private readonly IRoleStorage _storage;
public RoleLogic(ILogger<RoleLogic> logger, IRoleStorage storage)
{
_logger = logger;
_storage = storage;
}
public bool Create(RoleBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(RoleBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete. ID:{model.ID}");
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Update(RoleBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public List<RoleViewModel>? ReadList(RoleSearchModel? model)
{
_logger.LogInformation($"ReadList. ID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation($"ReadList. Count:{list.Count}");
return list;
}
private void CheckModel(RoleBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name));
}
_logger.LogInformation($"CategoryProduct. ID:{model.ID}.Name:{model.Name}");
var element = _storage.GetElement(new RoleSearchModel
{
Name = model.Name
});
if (element != null && element.ID != model.ID)
{
throw new InvalidOperationException("Такая роль уже есть");
}
}
}
}

View File

@ -0,0 +1,142 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
internal class UserLogic : IUserLogic
{
private readonly ILogger _logger;
private readonly IUserStorage _storage;
// todo нет интерфейса хранилища
public UserLogic(ILogger<UserLogic> logger, IUserStorage storage)
{
_logger = logger;
_storage = storage;
}
public bool Add(UserBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Add operation failed");
return false;
}
return true;
}
public bool Update(UserBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(UserBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete.ID:{model.ID}");
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Delete operation failes");
return false;
}
return true;
}
public UserViewModel? ReadElemet(UserSearchModel? model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation($"ReadElement: logint:{model.Login}.ID:{model.ID}");
var element = _storage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not fount");
return null;
}
_logger.LogInformation($"ReadElement: find.ID:{element.ID}");
return element;
}
public List<UserViewModel>? ReadList(UserSearchModel? model)
{
_logger.LogInformation($"ReadList: ClientID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); ;
if (list == null)
{
_logger.LogWarning("ReadList: return null list");
return null;
}
_logger.LogInformation($"ReadList:Count:{list.Count}");
return list;
}
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.FirstName))
{
throw new ArgumentNullException("Нет имени пользователя", nameof(model.FirstName));
}
if (string.IsNullOrEmpty(model.LastName))
{
throw new ArgumentNullException("Нет фамилии пользоватея", nameof(model.LastName));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет почты клиента", nameof(model.Email));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
}
if (string.IsNullOrEmpty(model.PhoneNumber))
{
throw new ArgumentNullException("Нет номер телефона пользователя", nameof(model.PhoneNumber));
}
_logger.LogInformation($"Client. ID:{model.ID}.RoleID:{model.RoleID}.FirstName:{model.FirstName}." +
$"LastName:{model.LastName}.Password:{model.Password}.PhoneNumber:{model.PhoneNumber}.Login:{model.Login}." +
$"Email:{model.Email}");
var element = _storage.GetElement(new UserSearchModel
{
Login = model.Login
});
if (element != null && element.ID != model.ID)
{
throw new InvalidOperationException("Клиент с таким логином уже есть");
}
}
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ElectronicsShopContracts\ElectronicsShopContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,16 @@
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BindingModels
{
public class CategoryProductBindingModel : ICategoryProductModel
{
public int ID { get; set; }
public string Name { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,29 @@
using ElectronicsShopDataModels.Enums;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public int ID { get; set; }
public int UserID { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public PaymeantOption PaymeantOption { get; set; } = PaymeantOption.Неизвестно;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new();
}
}

View File

@ -0,0 +1,24 @@
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BindingModels
{
public class ProductBindingModel : IProductModel
{
//ID категории продукта (товара)
public int CategoryID { get; set; }
//ID продукта (товара)
public int ID { get; set; }
public string ProductName { get; set; } = string.Empty;
public double Price { get; set; }
public int Count { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BindingModels
{
public class ReportBindingModel
{
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BindingModels
{
public class RoleBindingModel : IRoleModel
{
public int ID { get; set; }
public string Name { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,32 @@
using ElectronicsShopDataModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BindingModels
{
public class UserBindingModel : IUserModel
{
//ID пользователя
public int ID { get; set; }
//ID роли (клиент)
public int RoleID { get; set; }
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string Login { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public string PhoneNumber { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,20 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BusinessLogicContracts
{
public interface ICategoryProductLogic
{
List<CategoryProductViewModel>? ReadList(CategoryProductSearchModel? model);
bool Create(CategoryProductBindingModel model);
bool Update(CategoryProductBindingModel model);
bool Delete(CategoryProductBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BusinessLogicContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.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);
}
}

View File

@ -0,0 +1,16 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BusinessLogicContracts
{
public interface IReportLogic
{
// Получение списка заказов за определенный период
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BusinessLogicContracts
{
public interface IRoleLogic
{
List<RoleViewModel>? ReadList(RoleSearchModel? model);
bool Create(RoleBindingModel model);
bool Update(RoleBindingModel model);
bool Delete(RoleBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BusinessLogicContracts
{
public interface IUserLogic
{
List<UserViewModel>? ReadList(UserSearchModel? model);
UserViewModel? ReadElemet(UserSearchModel? model);
bool Add(UserBindingModel model);
bool Update(UserBindingModel model);
bool Delete(UserBindingModel model);
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ElectronicsShopDataModels\ElectronicsShopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.SearchModels
{
public class CategoryProductSearchModel
{
public int? ID { get; set; }
public string? Name { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using ElectronicsShopDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.SearchModels
{
public class OrderSearchModel
{
public int? ID { get; set; }
public int? UserID { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set;}
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.SearchModels
{
public class ProductSearchModel
{
public int? ID { get; set; }
public string? ProductName { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.SearchModels
{
public class RoleSearchModel
{
public int? ID { get; set; }
public string? Name { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.SearchModels
{
public class UserSearchModel
{
public int? ID { get; set; }
public string? Login { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.StorageContracts
{
public interface ICategoryProductStorage
{
List<CategoryProductViewModel> GetFullList();
List<CategoryProductViewModel> GetFilteredList(CategoryProductSearchModel model);
CategoryProductViewModel? GetElement(CategoryProductSearchModel model);
CategoryProductViewModel? Insert(CategoryProductBindingModel model);
CategoryProductViewModel? Update(CategoryProductBindingModel model);
CategoryProductViewModel? Delete(CategoryProductBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.StorageContracts
{
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.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);
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.StorageContracts
{
public interface IRoleStorage
{
List<RoleViewModel> GetFullList();
List<RoleViewModel> GetFilteredList(RoleSearchModel model);
RoleViewModel? GetElement(RoleSearchModel model);
RoleViewModel? Insert(RoleBindingModel model);
RoleViewModel? Update(RoleBindingModel model);
RoleViewModel? Delete(RoleBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.StorageContracts
{
public interface IUserStorage
{
List<UserViewModel> GetFullList();
List<UserViewModel> GetFilteredList(UserSearchModel model);
UserViewModel? GetElement(UserSearchModel model);
UserViewModel? Insert(UserBindingModel model);
UserViewModel? Update(UserBindingModel model);
UserViewModel? Delete(UserBindingModel model);
}
}

View File

@ -0,0 +1,18 @@
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.ViewModels
{
public class CategoryProductViewModel : ICategoryProductModel
{
public int ID { get; set; }
[DisplayName("Название категории продукта")]
public string Name { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,35 @@
using ElectronicsShopDataModels.Enums;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
public int ID { get; set; }
[DisplayName("Клиент ID")]
public int UserID { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Стутус оплаты")]
public PaymeantOption PaymeantOption { get; set; } = PaymeantOption.Неизвестно;
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new();
}
}

View File

@ -0,0 +1,27 @@
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.ViewModels
{
public class ProductViewModel : IProductModel
{
//ID категории продукта (товара)
public int CategoryID { get; set; }
//ID продукта (товара)
public int ID { get; set; }
[DisplayName("Название товара")]
public string ProductName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
[DisplayName("Количество")]
public int Count { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.ViewModels
{
public class ReportOrdersViewModel
{
public int ID { get; set; }
public DateTime DateCreate { get; set; }
public double Sum { get; set; }
public string PaymeantOption { get; set; } = string.Empty;
public string OrderStatus { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopDataModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.ViewModels
{
public class RoleViewModel : IRoleModel
{
public int ID { get; set; }
[DisplayName("Название роли")]
public string Name { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,38 @@
using ElectronicsShopDataModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.ViewModels
{
public class UserViewModel : IUserModel
{
//ID пользователя
public int ID { get; set; }
//ID роли (клиент)
public int RoleID { get; set; }
[DisplayName("Имя")]
public string FirstName { get; set; } = string.Empty;
[DisplayName("Фамилия")]
public string LastName { get; set; } = string.Empty;
[DisplayName("Логин")]
public string Login { get; set; } = string.Empty;
[DisplayName("Почта")]
public string Email { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
[DisplayName("Номер телефона")]
public string PhoneNumber { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,25 @@
using ElectronicsShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
namespace ElectronicsShopDataBaseImplement
{
public class Database : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder
optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<CategoryProduct> CategoryProducts { set; get; }
public virtual DbSet<User> Users { set; get; }
public virtual DbSet<Role> Roles { set; get; }
public virtual DbSet<Product> Products { set; get; }
public virtual DbSet<Order> Orders { set; get; }
}
}

View File

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ElectronicsShopContracts\ElectronicsShopContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,83 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements
{
public class CategoryProductStorage : ICategoryProductStorage
{
public CategoryProductViewModel? Delete(CategoryProductBindingModel model)
{
using var context = new Database();
var element = context.CategoryProducts.FirstOrDefault(rec => rec.ID == model.ID);
if (element != null)
{
context.CategoryProducts.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public CategoryProductViewModel? GetElement(CategoryProductSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue)
{
return null;
}
using var context = new Database();
return context.CategoryProducts.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
}
public List<CategoryProductViewModel> GetFilteredList(CategoryProductSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new Database();
return context.CategoryProducts.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
}
public List<CategoryProductViewModel> GetFullList()
{
using var context = new Database();
return context.CategoryProducts.Select(x => x.GetViewModel).ToList();
}
public CategoryProductViewModel? Insert(CategoryProductBindingModel model)
{
var newComponent = CategoryProduct.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new Database();
context.CategoryProducts.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public CategoryProductViewModel? Update(CategoryProductBindingModel model)
{
using var context = new Database();
var component = context.CategoryProducts.FirstOrDefault(x => x.ID == model.ID);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,88 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new Database();
var element = context.Orders.FirstOrDefault(rec => rec.ID == model.ID);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.ID.HasValue)
{
return null;
}
using var context = new Database();
return context.Orders.FirstOrDefault(x =>
(x.DateCreate == model.DateFrom && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.ID.HasValue && (model.DateFrom == null || model.DateTo == null))
{
return new();
}
using var context = new Database();
return context.Orders
.Include(x => x.Products)
.ThenInclude(x => x._product)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFullList()
{
using var context = new Database();
return context.Orders.Select(x => x.GetViewModel).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new Database();
var newComponent = Order.Create(context,model);
if (newComponent == null)
{
return null;
}
context.Orders.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new Database();
var component = context.Orders.FirstOrDefault(x => x.ID == model.ID);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,84 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements
{
public class ProductStorage : IProductStorage
{
public ProductViewModel? Delete(ProductBindingModel model)
{
using var context = new Database();
var element = context.Products.FirstOrDefault(rec => rec.ID == model.ID);
if (element != null)
{
context.Products.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ProductViewModel? GetElement(ProductSearchModel model)
{
if (string.IsNullOrEmpty(model.ProductName) && !model.ID.HasValue)
{
return null;
}
using var context = new Database();
return context.Products.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ProductName) && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
}
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
{
if (string.IsNullOrEmpty(model.ProductName))
{
return new();
}
using var context = new Database();
return context.Products.Where(x => x.ProductName.Contains(model.ProductName)).Select(x => x.GetViewModel).ToList();
}
public List<ProductViewModel> GetFullList()
{
using var context = new Database();
return context.Products.Select(x => x.GetViewModel).ToList();
}
public ProductViewModel? Insert(ProductBindingModel model)
{
var newComponent = Product.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new Database();
context.Products.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public ProductViewModel? Update(ProductBindingModel model)
{
using var context = new Database();
var component = context.Products.FirstOrDefault(x => x.ID == model.ID);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,82 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements
{
public class RoleStorage: IRoleStorage
{
public RoleViewModel? Delete(RoleBindingModel model)
{
using var context = new Database();
var element = context.Roles.FirstOrDefault(rec => rec.ID == model.ID);
if (element != null)
{
context.Roles.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public RoleViewModel? GetElement(RoleSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue)
{
return null;
}
using var context = new Database();
return context.Roles.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
}
public List<RoleViewModel> GetFilteredList(RoleSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new Database();
return context.Roles.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
}
public List<RoleViewModel> GetFullList()
{
using var context = new Database();
return context.Roles.Select(x => x.GetViewModel).ToList();
}
public RoleViewModel? Insert(RoleBindingModel model)
{
var newComponent = Role.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new Database();
context.Roles.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public RoleViewModel? Update(RoleBindingModel model)
{
using var context = new Database();
var component = context.Roles.FirstOrDefault(x => x.ID == model.ID);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,83 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements
{
public class UserStorage : IUserStorage
{
public UserViewModel? Delete(UserBindingModel model)
{
using var context = new Database();
var element = context.Users.FirstOrDefault(rec => rec.ID == model.ID);
if (element != null)
{
context.Users.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public UserViewModel? GetElement(UserSearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && !model.ID.HasValue)
{
return null;
}
using var context = new Database();
return context.Users.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Login) && x.Login == model.Login ||
(model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
}
public List<UserViewModel> GetFilteredList(UserSearchModel model)
{
if (string.IsNullOrEmpty(model.Login))
{
return new();
}
using var context = new Database();
return context.Users.Where(x => x.Login.Contains(model.Login)).Select(x => x.GetViewModel).ToList();
}
public List<UserViewModel> GetFullList()
{
using var context = new Database();
return context.Users.Select(x => x.GetViewModel).ToList();
}
public UserViewModel? Insert(UserBindingModel model)
{
var newComponent = User.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new Database();
context.Users.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public UserViewModel? Update(UserBindingModel model)
{
using var context = new Database();
var component = context.Users.FirstOrDefault(x => x.ID == model.ID);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,57 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class CategoryProduct : ICategoryProductModel
{
public int ID { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
public static CategoryProduct? Create(CategoryProductBindingModel? model)
{
if(model == null)
{
return null;
}
return new CategoryProduct()
{
ID = model.ID,
Name = model.Name
};
}
public static CategoryProduct? Create(CategoryProductViewModel model)
{
return new CategoryProduct
{
ID = model.ID,
Name = model.Name
};
}
public void Update(CategoryProductBindingModel model)
{
if(model == null)
{
return;
}
Name = model.Name;
}
public CategoryProductViewModel GetViewModel => new()
{
ID = ID,
Name = Name
};
}
}

View File

@ -0,0 +1,99 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class Order : IOrderModel
{
public int ID { get; set; }
[Required]
public double Sum { get; set; }
[Required]
public int UserID { get; set; }
[Required]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[Required]
public PaymeantOption PaymeantOption { get; set; } = PaymeantOption.Неизвестно;
[Required]
public DateTime DateCreate { get; set; } = DateTime.Now;
[Required]
public DateTime? DateImplement { get; set; }
[Required]
public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new();
[NotMapped]
public Dictionary<int, (IProductModel, int)> _productList
{
get {
if (ProductList == null) {
ProductList = Products.ToDictionary(recPC => recPC.ProductID, recPC => (recPC._product as IProductModel, recPC.Count));
}
return _productList;
}
}
public virtual List<OrderProducts> Products { get; set; } = new();
public static Order? Create(Database context ,OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
ID = model.ID,
UserID=model.UserID,
Sum = model.Sum,
Status = model.Status,
PaymeantOption = model.PaymeantOption,
DateCreate = model.DateCreate,
Products = model.ProductList.Select(x => new OrderProducts
{
_product = context.Products.First(y => y.ID == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(OrderBindingModel model)
{
if (model == null)
{
return;
}
ID = model.ID;
UserID = model.UserID;
Sum = model.Sum;
PaymeantOption = model.PaymeantOption;
Status = model.Status;
DateCreate = model.DateCreate;
if (model.DateImplement != null)
{
DateImplement = model.DateImplement;
}
//todo ProductList
}
public OrderViewModel GetViewModel => new()
{
ID = ID,
UserID = UserID,
Sum = Sum,
PaymeantOption = PaymeantOption,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
ProductList = ProductList
};
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class OrderProducts
{
public int ID { get; set; }
[Required]
public int OrdersID { get; set; }
[Required]
public int ProductID { get; set; }
[Required]
public int Count { get; set; }
public virtual Order _order { get; set; } = new();
public virtual Product _product { get; set; } = new();
}
}

View File

@ -0,0 +1,72 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class Product : IProductModel
{
public int ID { get; set; }
[Required]
public string ProductName { get; set; }=string.Empty;
[Required]
public double Price { get; set; }
[Required]
public int Count { get; set; }
[Required]
public int CategoryID { get; set; }
public static Product? Create(ProductBindingModel? model)
{
if (model == null)
{
return null;
}
return new Product()
{
ID = model.ID,
ProductName = model.ProductName,
Price = model.Price,
Count = model.Count,
CategoryID = model.CategoryID
};
}
public static Product? Create(ProductViewModel model)
{
return new Product
{
ID = model.ID,
ProductName = model.ProductName,
Price = model.Price,
Count = model.Count,
CategoryID = model.CategoryID
};
}
public void Update(ProductBindingModel model)
{
if (model == null)
{
return;
}
ProductName = model.ProductName;
Price = model.Price;
Count = model.Count;
CategoryID = model.CategoryID;
}
public ProductViewModel GetViewModel => new()
{
ID = ID,
ProductName = ProductName,
Price = Price,
Count = Count,
CategoryID = CategoryID
};
}
}

View File

@ -0,0 +1,55 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class Role : IRoleModel
{
public int ID { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
public static Role? Create(RoleBindingModel? model)
{
if (model == null)
{
return null;
}
return new Role()
{
ID = model.ID,
Name = model.Name
};
}
public static Role? Create(RoleViewModel model)
{
return new Role
{
ID = model.ID,
Name = model.Name
};
}
public void Update(RoleBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public RoleViewModel GetViewModel => new()
{
ID = ID,
Name = Name
};
}
}

View File

@ -0,0 +1,90 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class User : IUserModel
{
public int ID { get; set; }
[Required]
public string FirstName { get; set; }=string.Empty;
[Required]
public string LastName {get; set; }=string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public string PhoneNumber { get; set; } = string.Empty;
[Required]
public string Login { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public int RoleID { get; set; }
public static User? Create(UserBindingModel model)
{
if(model == null)
{
return null;
}
return new User()
{
ID = model.ID,
FirstName = model.FirstName,
LastName = model.LastName,
Password = model.Password,
PhoneNumber = model.PhoneNumber,
Login = model.Login,
Email = model.Email,
RoleID = model.RoleID
};
}
public static User Create(UserViewModel model)
{
return new User
{
ID = model.ID,
FirstName = model.FirstName,
LastName = model.LastName,
Password = model.Password,
PhoneNumber = model.PhoneNumber,
Login = model.Login,
Email = model.Email,
RoleID = model.RoleID
};
}
public void Update(UserBindingModel model)
{
if (model == null)
{
return;
}
FirstName = model.FirstName;
LastName = model.LastName;
Password = model.Password;
PhoneNumber = model.PhoneNumber;
Login = model.Login;
Email = model.Email;
RoleID = model.RoleID;
}
public UserViewModel GetViewModel => new()
{
ID = ID,
FirstName = FirstName,
LastName = LastName,
Password = Password,
PhoneNumber = PhoneNumber,
Login = Login,
Email = Email,
RoleID = RoleID
};
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataModels.Enums
{
public enum OrderStatus
{
Неизвестен = -1,
Принят = 0,
Выполняется = 1,
Готов = 2,
Выдан = 3
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataModels.Enums
{
public enum PaymeantOption
{
Неизвестно = -1,
Полная_оплата = 0,
Частичная_оплата = 1
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataModels
{
public interface IID
{
int ID { get; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataModels.Models
{
public interface ICategoryProductModel : IID
{
string Name { get; }
}
}

View File

@ -0,0 +1,21 @@
using ElectronicsShopDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataModels.Models
{
public interface IOrderModel : IID
{
double Sum { get; }
int UserID { get; }
OrderStatus Status { get; }
PaymeantOption PaymeantOption { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
//список товаров в заказе
Dictionary<int, (IProductModel, int)> ProductList { get; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataModels.Models
{
public interface IProductModel : IID
{
string ProductName { get; }
double Price { get; }
int Count { get; }
int CategoryID { get; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataModels.Models
{
public interface IRoleModel : IID
{
string Name { get; }
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataModels
{
public interface IUserModel : IID
{
//ID role
int RoleID { get; }
string FirstName { get; }
string LastName { get; }
string Password { get; }
string PhoneNumber { get; }
string Login { get; }
string Email { get; }
}
}