diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/BackUpLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..a0f09be --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,103 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicContracts; +using ComputersShopContracts.StorageContracts; +using ComputersShopDataModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + + private readonly IBackUpInfo _backUpInfo; + + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + + public void CreateBackUp(BackUpSaveBinidngModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + // зачистка папки и удаление старого архива + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ClientLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ClientLogic.cs index 7ae73d4..4d0d0ea 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -1,7 +1,7 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using Microsoft.Extensions.Logging; using System; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs index 86dd084..37a57b1 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -1,7 +1,7 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using Microsoft.Extensions.Logging; using System; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs index 8eac11e..6b51b64 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs @@ -1,7 +1,7 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using Microsoft.Extensions.Logging; using System; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs index 3de8d7a..e3d0a8a 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -1,7 +1,7 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using Microsoft.Extensions.Logging; using System; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs index 618fa72..15a420c 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -1,7 +1,7 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using Microsoft.Extensions.Logging; using System; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs index 3b8a2d5..8393b2a 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -2,7 +2,7 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataModels.Enums; using Microsoft.Extensions.Logging; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ReportLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ReportLogic.cs index 1cd7224..18b61c9 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -3,7 +3,7 @@ using ComputersShopBusinessLogic.OfficePackage.HeplerModels; using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using System; using System.Collections.Generic; diff --git a/ComputersShop/ComputersShopContracts/Attributes/ColumnAttribute.cs b/ComputersShop/ComputersShopContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..3ed8f81 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + public string Title { get; private set; } + public bool Visible { get; private set; } + public int Width { get; private set; } + public GridViewAutoSize GridViewAutoSize { get; private set; } + public bool IsUseAutoSize { get; private set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/Attributes/GridViewAutoSize.cs b/ComputersShop/ComputersShopContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..a23edde --- /dev/null +++ b/ComputersShop/ComputersShopContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/BackUpSaveBinidngModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..12d7c35 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ClientBindingModels.cs b/ComputersShop/ComputersShopContracts/BindingModels/ClientBindingModels.cs index 1c51c3d..f47a356 100644 --- a/ComputersShop/ComputersShopContracts/BindingModels/ClientBindingModels.cs +++ b/ComputersShop/ComputersShopContracts/BindingModels/ClientBindingModels.cs @@ -4,15 +4,20 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using ComputersShopContracts.Attributes; using СomputersShopDataModels.Models; namespace ComputersShopContracts.BindingModels { public class ClientBindingModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; + [Column("Логин (эл. почта)", width: 200)] public string Email { get; set; } = string.Empty; + [Column("Пароль", width: 200)] public string Password { get; set; } = string.Empty; } } diff --git a/ComputersShop/ComputersShopContracts/BindingModels/MessageInfoBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/MessageInfoBindingModel.cs index 2966e42..c37f707 100644 --- a/ComputersShop/ComputersShopContracts/BindingModels/MessageInfoBindingModel.cs +++ b/ComputersShop/ComputersShopContracts/BindingModels/MessageInfoBindingModel.cs @@ -20,5 +20,7 @@ namespace ComputersShopContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + + public int Id => throw new NotImplementedException(); } } diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicContracts/IBackUpLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicContracts/IBackUpLogic.cs new file mode 100644 index 0000000..d6e9a5d --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using ComputersShopContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BusinessLogicContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj index a5d52fc..9b25187 100644 --- a/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj +++ b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj @@ -8,6 +8,8 @@ + + diff --git a/ComputersShop/ComputersShopContracts/DI/DependencyManager.cs b/ComputersShop/ComputersShopContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..45ed965 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/DI/DependencyManager.cs @@ -0,0 +1,44 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + private static DependencyManager? _manager; + private static readonly object _locjObject = new(); + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + public static DependencyManager Instance + { + get + { + if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } + return _manager; + } + } + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + public void AddLogging(Action configure) => + _dependencyManager.AddLogging(configure); + public void RegisterType(bool isSingle = false) where U : + class, T where T : class => _dependencyManager.RegisterType(isSingle); + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + public T Resolve() => _dependencyManager.Resolve(); + } +} diff --git a/ComputersShop/ComputersShopContracts/DI/IDependencyContainer.cs b/ComputersShop/ComputersShopContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..5514b47 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/DI/IDependencyContainer.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.DI +{ + public interface IDependencyContainer + { + void AddLogging(Action configure); + void RegisterType(bool isSingle) where U : class, T where T : class; + void RegisterType(bool isSingle) where T : class; + T Resolve(); + } +} diff --git a/ComputersShop/ComputersShopContracts/DI/IImplementationExtension.cs b/ComputersShop/ComputersShopContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..f0d9c00 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/DI/IImplementationExtension.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + } +} diff --git a/ComputersShop/ComputersShopContracts/DI/ServiceDependencyContainer.cs b/ComputersShop/ComputersShopContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..cd5508f --- /dev/null +++ b/ComputersShop/ComputersShopContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} diff --git a/ComputersShop/ComputersShopContracts/DI/ServiceProviderLoader.cs b/ComputersShop/ComputersShopContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..68b9ed2 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.DI +{ + public class ServiceProviderLoader + { + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = + Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", + SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && + typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = + (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = + (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + private static string TryGetImplementationExtensionsFolder() + { + var directory = new + DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && + !directory.GetDirectories("ImplementationExtensions", + SearchOption.AllDirectories) + .Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/ComputersShop/ComputersShopContracts/DI/UnityDependencyContainer.cs b/ComputersShop/ComputersShopContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..0886159 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; +using Unity.Microsoft.Logging; + +namespace ComputersShopContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +} diff --git a/ComputersShop/ComputersShopContracts/StorageContracts/IBackUpInfo.cs b/ComputersShop/ComputersShopContracts/StorageContracts/IBackUpInfo.cs new file mode 100644 index 0000000..40c49f2 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StorageContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.StorageContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/ComputersShop/ComputersShopContracts/StorageContracts/IClientStorage.cs b/ComputersShop/ComputersShopContracts/StorageContracts/IClientStorage.cs index e9c9cd3..96cfc27 100644 --- a/ComputersShop/ComputersShopContracts/StorageContracts/IClientStorage.cs +++ b/ComputersShop/ComputersShopContracts/StorageContracts/IClientStorage.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopContracts.StoragesContracts +namespace ComputersShopContracts.StorageContracts { public interface IClientStorage { diff --git a/ComputersShop/ComputersShopContracts/StorageContracts/IComponentStorage.cs b/ComputersShop/ComputersShopContracts/StorageContracts/IComponentStorage.cs index 1a5b4d4..30866e6 100644 --- a/ComputersShop/ComputersShopContracts/StorageContracts/IComponentStorage.cs +++ b/ComputersShop/ComputersShopContracts/StorageContracts/IComponentStorage.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopContracts.StoragesContracts +namespace ComputersShopContracts.StorageContracts { public interface IComponentStorage { diff --git a/ComputersShop/ComputersShopContracts/StorageContracts/IComputerStorage.cs b/ComputersShop/ComputersShopContracts/StorageContracts/IComputerStorage.cs index d4da35b..bf3b2e4 100644 --- a/ComputersShop/ComputersShopContracts/StorageContracts/IComputerStorage.cs +++ b/ComputersShop/ComputersShopContracts/StorageContracts/IComputerStorage.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopContracts.StoragesContracts +namespace ComputersShopContracts.StorageContracts { public interface IComputerStorage { diff --git a/ComputersShop/ComputersShopContracts/StorageContracts/IImplementerStorage.cs b/ComputersShop/ComputersShopContracts/StorageContracts/IImplementerStorage.cs index ed5e3bc..df76739 100644 --- a/ComputersShop/ComputersShopContracts/StorageContracts/IImplementerStorage.cs +++ b/ComputersShop/ComputersShopContracts/StorageContracts/IImplementerStorage.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopContracts.StoragesContracts +namespace ComputersShopContracts.StorageContracts { public interface IImplementerStorage { diff --git a/ComputersShop/ComputersShopContracts/StorageContracts/IMessageInfoStorage.cs b/ComputersShop/ComputersShopContracts/StorageContracts/IMessageInfoStorage.cs index 64dfea8..3295952 100644 --- a/ComputersShop/ComputersShopContracts/StorageContracts/IMessageInfoStorage.cs +++ b/ComputersShop/ComputersShopContracts/StorageContracts/IMessageInfoStorage.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopContracts.StoragesContracts +namespace ComputersShopContracts.StorageContracts { public interface IMessageInfoStorage { diff --git a/ComputersShop/ComputersShopContracts/StorageContracts/IOrderStorage.cs b/ComputersShop/ComputersShopContracts/StorageContracts/IOrderStorage.cs index cd29c6d..f653d99 100644 --- a/ComputersShop/ComputersShopContracts/StorageContracts/IOrderStorage.cs +++ b/ComputersShop/ComputersShopContracts/StorageContracts/IOrderStorage.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopContracts.StoragesContracts +namespace ComputersShopContracts.StorageContracts { public interface IOrderStorage { diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ClientViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ClientViewModel.cs index f716a40..15ef5ab 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/ClientViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using ComputersShopDataModels.Models; +using ComputersShopContracts.Attributes; +using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -11,15 +12,16 @@ namespace ComputersShopContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column("Логин (эл. почта)", width: 200)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs index 484c23c..7074d23 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using ComputersShopDataModels.Models; +using ComputersShopContracts.Attributes; +using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,11 @@ namespace ComputersShopContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компонента")] + [Column("Название комплектующего", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Cost { get; set; } } } diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs index af63721..d7fd5f8 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs @@ -1,4 +1,5 @@ -using ComputersShopDataModels.Models; +using ComputersShopContracts.Attributes; +using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,14 +11,15 @@ namespace ComputersShopContracts.ViewModels { public class ComputerViewModel : IComputerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название компьютера")] + [Column("Название компьютера", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComputerName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Price { get; set; } - + [Column(visible: false)] public Dictionary ComputerComponents { get; diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs index 919a96d..f4b5179 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using ComputersShopDataModels.Models; +using ComputersShopContracts.Attributes; +using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace ComputersShopContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } } } diff --git a/ComputersShop/ComputersShopContracts/ViewModels/MessageInfoViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/MessageInfoViewModel.cs index e9f7ce7..6bfe6dd 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/MessageInfoViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using ComputersShopDataModels.Models; +using ComputersShopContracts.Attributes; +using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,20 +11,24 @@ namespace ComputersShopContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; - + [Column(visible: false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column("Дата письма", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column("Заголовок", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column("Текст", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + + [Column(visible: false)] + public int Id => throw new NotImplementedException(); } } diff --git a/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs index a60c65d..9fc5389 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using ComputersShopDataModels.Enums; +using ComputersShopContracts.Attributes; +using ComputersShopDataModels.Enums; using ComputersShopDataModels.Models; using System; using System.Collections.Generic; @@ -11,27 +12,43 @@ namespace ComputersShopContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - public int ComputerId { get; set; } - public int ClientId { get; set; } - [DisplayName("Фамилия клиента")] - public string ClientFIO { get; set; } = string.Empty; - public string ClientEmail { get; set; } = string.Empty; + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Id { get; set; } + + [Column(visible: false)] + public int ComputerId { get; set; } + + [Column(visible: false)] + public int ClientId { get; set; } + + [Column("Данные клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + + [Column(visible: false)] + public string ClientEmail { get; set; } = string.Empty; + + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] + + [Column("Данные исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Компьютер")] + + [Column("Компьютер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string ComputerName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } + + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Count { get; set; } + + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public double Sum { get; set; } + + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [Column("Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [Column("Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } } } diff --git a/ComputersShop/ComputersShopDataBaseImplement/ComputersShopDataBaseImplement.csproj b/ComputersShop/ComputersShopDataBaseImplement/ComputersShopDataBaseImplement.csproj index 64aaf91..0fb9013 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/ComputersShopDataBaseImplement.csproj +++ b/ComputersShop/ComputersShopDataBaseImplement/ComputersShopDataBaseImplement.csproj @@ -20,4 +20,7 @@ + + + diff --git a/ComputersShop/ComputersShopDataBaseImplement/DatabaseImplementationExtension.cs b/ComputersShop/ComputersShopDataBaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..584bff6 --- /dev/null +++ b/ComputersShop/ComputersShopDataBaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,27 @@ +using ComputersShopContracts.DI; +using ComputersShopContracts.StorageContracts; +using ComputersShopDataBaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataBaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/ComputersShop/ComputersShopDataBaseImplement/Implements/BackUpInfo.cs b/ComputersShop/ComputersShopDataBaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..1839682 --- /dev/null +++ b/ComputersShop/ComputersShopDataBaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using ComputersShopContracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataBaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new ComputersShopDataBase(); + return context.Set().ToList(); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && + type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/ComputersShop/ComputersShopDataBaseImplement/Implements/ClientStorage.cs b/ComputersShop/ComputersShopDataBaseImplement/Implements/ClientStorage.cs index 74c5cc8..8934c6d 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Implements/ClientStorage.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Implements/ClientStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataBaseImplement.Models; using System; diff --git a/ComputersShop/ComputersShopDataBaseImplement/Implements/ComponentStorage.cs b/ComputersShop/ComputersShopDataBaseImplement/Implements/ComponentStorage.cs index fdaaaea..5606f85 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Implements/ComponentStorage.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Implements/ComponentStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataBaseImplement.Models; using System; diff --git a/ComputersShop/ComputersShopDataBaseImplement/Implements/ComputerStorage.cs b/ComputersShop/ComputersShopDataBaseImplement/Implements/ComputerStorage.cs index 262ee6c..31ae87e 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Implements/ComputerStorage.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Implements/ComputerStorage.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore; using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataBaseImplement.Models; using System; diff --git a/ComputersShop/ComputersShopDataBaseImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopDataBaseImplement/Implements/ImplementerStorage.cs index b997954..e0e72fb 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Implements/ImplementerStorage.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Implements/ImplementerStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; diff --git a/ComputersShop/ComputersShopDataBaseImplement/Implements/MessageInfoStorage.cs b/ComputersShop/ComputersShopDataBaseImplement/Implements/MessageInfoStorage.cs index afdbfaa..b2a52ff 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Implements/MessageInfoStorage.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Implements/MessageInfoStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataBaseImplement.Models; using System; diff --git a/ComputersShop/ComputersShopDataBaseImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopDataBaseImplement/Implements/OrderStorage.cs index d046d1b..9093ebc 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Implements/OrderStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; diff --git a/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240512072253_SecondMig.Designer.cs b/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240512072253_SecondMig.Designer.cs new file mode 100644 index 0000000..c40712c --- /dev/null +++ b/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240512072253_SecondMig.Designer.cs @@ -0,0 +1,285 @@ +// +using System; +using ComputersShopDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ComputersShopDataBaseImplement.Migrations +{ + [DbContext(typeof(ComputersShopDataBase))] + [Migration("20240512072253_SecondMig")] + partial class SecondMig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Computer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComputerName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Computers"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ComputerComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("ComputerId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ComputerId"); + + b.ToTable("ComputerComponents"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Message", b => + { + b.Property("MessageId") + .HasColumnType("text"); + + b.Property("Body") + .IsRequired() + .HasColumnType("text"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("DateDelivery") + .HasColumnType("timestamp with time zone"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("MessageId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("ComputerId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp with time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp with time zone"); + + b.Property("ImplementerId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ComputerId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ComputerComponent", b => + { + b.HasOne("ComputersShopDataBaseImplement.Models.Component", "Component") + .WithMany("ComputerComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer") + .WithMany("Components") + .HasForeignKey("ComputerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Computer"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b => + { + b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer") + .WithMany("Orders") + .HasForeignKey("ComputerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputersShopDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Client"); + + b.Navigation("Computer"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b => + { + b.Navigation("ComputerComponents"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Computer", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240512072253_SecondMig.cs b/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240512072253_SecondMig.cs new file mode 100644 index 0000000..0eeb084 --- /dev/null +++ b/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240512072253_SecondMig.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputersShopDataBaseImplement.Migrations +{ + /// + public partial class SecondMig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Messages_Clients_ClientId", + table: "Messages"); + + migrationBuilder.DropIndex( + name: "IX_Messages_ClientId", + table: "Messages"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + + migrationBuilder.AddForeignKey( + name: "FK_Messages_Clients_ClientId", + table: "Messages", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id"); + } + } +} diff --git a/ComputersShop/ComputersShopDataBaseImplement/Migrations/ComputersShopDataBaseModelSnapshot.cs b/ComputersShop/ComputersShopDataBaseImplement/Migrations/ComputersShopDataBaseModelSnapshot.cs index c4f6fe2..36c956f 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Migrations/ComputersShopDataBaseModelSnapshot.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Migrations/ComputersShopDataBaseModelSnapshot.cs @@ -165,8 +165,6 @@ namespace ComputersShopDataBaseImplement.Migrations b.HasKey("MessageId"); - b.HasIndex("ClientId"); - b.ToTable("Messages"); }); @@ -232,15 +230,6 @@ namespace ComputersShopDataBaseImplement.Migrations b.Navigation("Computer"); }); - modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Message", b => - { - b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client") - .WithMany("Messages") - .HasForeignKey("ClientId"); - - b.Navigation("Client"); - }); - modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b => { b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client") @@ -268,8 +257,6 @@ namespace ComputersShopDataBaseImplement.Migrations modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b => { - b.Navigation("Messages"); - b.Navigation("Orders"); }); diff --git a/ComputersShop/ComputersShopDataBaseImplement/Models/Client.cs b/ComputersShop/ComputersShopDataBaseImplement/Models/Client.cs index facae9d..2943af6 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Models/Client.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Models/Client.cs @@ -8,21 +8,26 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; using СomputersShopDataModels.Models; namespace ComputersShopDataBaseImplement.Models { + [DataContract] public class Client : IClientModel { [Required] + [DataMember] public string ClientFIO { get; set; } = string.Empty; [Required] + [DataMember] public string Email { get; set; } = string.Empty; [Required] + [DataMember] public string Password { get; set; } = string.Empty; - + [DataMember] public int Id { get; set; } [ForeignKey("ClientId")] diff --git a/ComputersShop/ComputersShopDataBaseImplement/Models/Component.cs b/ComputersShop/ComputersShopDataBaseImplement/Models/Component.cs index 861df26..f77c24c 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Models/Component.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Models/Component.cs @@ -9,15 +9,20 @@ using System.Text; using System.Threading.Tasks; using ComputersShopContracts.BindingModels; using ComputersShopContracts.ViewModels; +using System.Runtime.Serialization; namespace ComputersShopDataBaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ComponentName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List ComputerComponents { get; set; } = new(); diff --git a/ComputersShop/ComputersShopDataBaseImplement/Models/Computer.cs b/ComputersShop/ComputersShopDataBaseImplement/Models/Computer.cs index 60b02b3..4c609ae 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Models/Computer.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Models/Computer.cs @@ -8,15 +8,20 @@ using System.Text; using System.Threading.Tasks; using ComputersShopContracts.BindingModels; using ComputersShopContracts.ViewModels; +using System.Runtime.Serialization; namespace ComputersShopDataBaseImplement.Models { + [DataContract] public class Computer : IComputerModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string ComputerName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _ComputerComponents = null; [NotMapped] diff --git a/ComputersShop/ComputersShopDataBaseImplement/Models/Implementer.cs b/ComputersShop/ComputersShopDataBaseImplement/Models/Implementer.cs index ade0055..6e48013 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Models/Implementer.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Models/Implementer.cs @@ -8,23 +8,30 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace ComputersShopDataBaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string ImplementerFIO { get; set; } = string.Empty; [Required] + [DataMember] public string Password { get; set; } = string.Empty; [Required] + [DataMember] public int WorkExperience { get; set; } [Required] + [DataMember] public int Qualification { get; set; } [ForeignKey("ImplementerId")] diff --git a/ComputersShop/ComputersShopDataBaseImplement/Models/Message.cs b/ComputersShop/ComputersShopDataBaseImplement/Models/Message.cs index 269d6be..8bf2073 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Models/Message.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Models/Message.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; @@ -13,6 +14,7 @@ namespace ComputersShopDataBaseImplement.Models public class Message : IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } @@ -27,6 +29,8 @@ namespace ComputersShopDataBaseImplement.Models public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); + public static Message? Create(MessageInfoBindingModel model) { if (model == null) @@ -41,7 +45,7 @@ namespace ComputersShopDataBaseImplement.Models MessageId = model.MessageId, SenderName = model.SenderName, DateDelivery = DateTime.SpecifyKind(model.DateDelivery, DateTimeKind.Utc) - }; + }; } public MessageInfoViewModel GetViewModel => new() diff --git a/ComputersShop/ComputersShopDataBaseImplement/Models/Order.cs b/ComputersShop/ComputersShopDataBaseImplement/Models/Order.cs index a4f31e1..c6d8bb9 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Models/Order.cs @@ -7,78 +7,86 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection.Metadata; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ComputersShopDataBaseImplement.Models { - public class Order : IOrderModel - { - [Required] - public int ComputerId { get; set; } - [Required] - public int ClientId { get; private set; } + [DataContract] + public class Order : IOrderModel + { + [Required] + [DataMember] + public int ComputerId { get; set; } + [Required] + [DataMember] + public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; set; } [Required] - public int Count { get; set; } - [Required] - public double Sum { get; set; } - [Required] - public OrderStatus Status { get; set; } - [Required] - public DateTime DateCreate { get; set; } - - public DateTime? DateImplement { get; set; } - public virtual Computer Computer { get; set; } - public virtual Client Client { get; set; } + [DataMember] + public int Count { get; set; } + [Required] + [DataMember] + public double Sum { get; set; } + [Required] + [DataMember] + public OrderStatus Status { get; set; } + [Required] + [DataMember] + public DateTime DateCreate { get; set; } + [DataMember] + public DateTime? DateImplement { get; set; } + public virtual Computer Computer { get; set; } + public virtual Client Client { get; set; } public virtual Implementer? Implementer { get; set; } public int Id { get; set; } - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - ComputerId = model.ComputerId, - ClientId = model.ClientId, + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ComputerId = model.ComputerId, + ClientId = model.ClientId, ImplementerId = model.ImplementerId, Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement - }; - } + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - DateImplement = model.DateImplement; + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() - { - Id = Id, - ComputerId = ComputerId, - ClientId = ClientId, - ClientFIO = Client.ClientFIO, - ClientEmail = Client.Email, + { + Id = Id, + ComputerId = ComputerId, + ClientId = ClientId, + ClientFIO = Client.ClientFIO, ImplementerId = ImplementerId, ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - ComputerName = Computer.ComputerName - }; - } + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + ComputerName = Computer.ComputerName + }; + } } diff --git a/ComputersShop/ComputersShopFileImplement/ComputersShopFileImplement.csproj b/ComputersShop/ComputersShopFileImplement/ComputersShopFileImplement.csproj index 67fa075..70ad8da 100644 --- a/ComputersShop/ComputersShopFileImplement/ComputersShopFileImplement.csproj +++ b/ComputersShop/ComputersShopFileImplement/ComputersShopFileImplement.csproj @@ -11,4 +11,7 @@ + + + diff --git a/ComputersShop/ComputersShopFileImplement/FileImplementationExtension.cs b/ComputersShop/ComputersShopFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..f5682c1 --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/FileImplementationExtension.cs @@ -0,0 +1,27 @@ +using ComputersShopContracts.DI; +using ComputersShopContracts.StorageContracts; +using ComputersShopFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/ComputersShop/ComputersShopFileImplement/Implements/BackUpInfo.cs b/ComputersShop/ComputersShopFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..881fe43 --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,35 @@ +using ComputersShopContracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + // Получаем значения из singleton-объекта универсального свойства содержащее тип T + var source = DataFileSingleton.GetInstance(); + return (List?)source.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T)) + ?.GetValue(source); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ClientStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ClientStorage.cs index 610735e..4971855 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/ClientStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/ClientStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopFileImplement.Models; using System; diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ComponentStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ComponentStorage.cs index 8145f62..404150d 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/ComponentStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/ComponentStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopFileImplement.Models; using System; diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ComputerStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ComputerStorage.cs index 6a70923..9a90349 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/ComputerStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/ComputerStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopFileImplement.Models; using System; diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs index abfe9ab..8bd390d 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopFileImplement.Models; using System; diff --git a/ComputersShop/ComputersShopFileImplement/Implements/MessageInfoStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/MessageInfoStorage.cs index 73b9afd..9fa4cc8 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/MessageInfoStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/MessageInfoStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopFileImplement.Models; using System; diff --git a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs index 1ea7d9b..60a78db 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopFileImplement.Models; using System; diff --git a/ComputersShop/ComputersShopFileImplement/Models/Client.cs b/ComputersShop/ComputersShopFileImplement/Models/Client.cs index 07e24a8..1aa46d6 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Client.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Client.cs @@ -4,6 +4,7 @@ using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; @@ -11,14 +12,16 @@ using СomputersShopDataModels.Models; namespace ComputersShopFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public string ClientFIO { get; private set; } = string.Empty; - + [DataMember] public string Email { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int Id { get; private set; } public static Client? Create(ClientBindingModel model) diff --git a/ComputersShop/ComputersShopFileImplement/Models/Component.cs b/ComputersShop/ComputersShopFileImplement/Models/Component.cs index 6b6d8a0..ecfa2c4 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Component.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Component.cs @@ -4,16 +4,21 @@ using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ComputersShopFileImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ComponentName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) { diff --git a/ComputersShop/ComputersShopFileImplement/Models/Computer.cs b/ComputersShop/ComputersShopFileImplement/Models/Computer.cs index 0f407ff..a8c6899 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Computer.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Computer.cs @@ -4,16 +4,21 @@ using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ComputersShopFileImplement.Models { + [DataContract] public class Computer : IComputerModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ComputerName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _ComputerComponents = null; diff --git a/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs b/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs index a777a6f..1f61ab4 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs @@ -4,22 +4,25 @@ using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ComputersShopFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public string ImplementerFIO { get; set; } = string.Empty; - + [DataMember] public string Password { get; set; } = string.Empty; - + [DataMember] public int WorkExperience { get; set; } - + [DataMember] public int Qualification { get; set; } - + [DataMember] public int Id { get; set; } public static Implementer? Create(ImplementerBindingModel? model) diff --git a/ComputersShop/ComputersShopFileImplement/Models/Message.cs b/ComputersShop/ComputersShopFileImplement/Models/Message.cs index bef34fa..6e934d5 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Message.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Message.cs @@ -4,77 +4,82 @@ using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ComputersShopFileImplement.Models { - public class Message : IMessageInfoModel - { - public string MessageId { get; private set; } = string.Empty; + [DataContract] + public class Message : IMessageInfoModel + { + [DataMember] + public string MessageId { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } + [DataMember] + public string SenderName { get; private set; } = string.Empty; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + public int Id => throw new NotImplementedException(); - public string SenderName { get; private set; } = string.Empty; + public static Message? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } - public DateTime DateDelivery { get; private set; } = DateTime.Now; + public static Message? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Body = element.Attribute("Body")!.Value, + Subject = element.Attribute("Subject")!.Value, + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + MessageId = element.Attribute("MessageId")!.Value, + SenderName = element.Attribute("SenderName")!.Value, + DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value), + }; + } - public string Subject { get; private set; } = string.Empty; + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; - public string Body { get; private set; } = string.Empty; - - public static Message? Create(MessageInfoBindingModel model) - { - if (model == null) - { - return null; - } - return new() - { - Body = model.Body, - Subject = model.Subject, - ClientId = model.ClientId, - MessageId = model.MessageId, - SenderName = model.SenderName, - DateDelivery = model.DateDelivery, - }; - } - - public static Message? Create(XElement element) - { - if (element == null) - { - return null; - } - return new() - { - Body = element.Attribute("Body")!.Value, - Subject = element.Attribute("Subject")!.Value, - ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), - MessageId = element.Attribute("MessageId")!.Value, - SenderName = element.Attribute("SenderName")!.Value, - DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value), - }; - } - - public MessageInfoViewModel GetViewModel => new() - { - Body = Body, - Subject = Subject, - ClientId = ClientId, - MessageId = MessageId, - SenderName = SenderName, - DateDelivery = DateDelivery, - }; - - public XElement GetXElement => new("MessageInfo", - new XAttribute("Body", Body), - new XAttribute("Subject", Subject), - new XAttribute("ClientId", ClientId), - new XAttribute("MessageId", MessageId), - new XAttribute("SenderName", SenderName), - new XAttribute("DateDelivery", DateDelivery) - ); - } + public XElement GetXElement => new("MessageInfo", + new XAttribute("Body", Body), + new XAttribute("Subject", Subject), + new XAttribute("ClientId", ClientId), + new XAttribute("MessageId", MessageId), + new XAttribute("SenderName", SenderName), + new XAttribute("DateDelivery", DateDelivery) + ); + } } diff --git a/ComputersShop/ComputersShopFileImplement/Models/Order.cs b/ComputersShop/ComputersShopFileImplement/Models/Order.cs index 857d0b3..b4402e8 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Order.cs @@ -5,113 +5,116 @@ using ComputersShopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ComputersShopFileImplement.Models { - public class Order : IOrderModel - { - public int ComputerId { get; private set; } - - public int ClientId { get; set; } - + [DataContract] + public class Order : IOrderModel + { + [DataMember] + public int ComputerId { get; private set; } + [DataMember] + public int ClientId { get; set; } + [DataMember] public int? ImplementerId { get; private set; } - + [DataMember] public int Count { get; private set; } + [DataMember] + public double Sum { get; private set; } + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); + [DataMember] + public DateTime? DateImplement { get; private set; } + [DataMember] + public int Id { get; private set; } - public double Sum { get; private set; } - - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - - public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } - - public int Id { get; private set; } - - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - ComputerId = model.ComputerId, - ClientId = model.ClientId, + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ComputerId = model.ComputerId, + ClientId = model.ClientId, ImplementerId = model.ImplementerId, Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement - }; - } + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } - public static Order? Create(XElement element) - { - if (element == null) - { - return null; - } - var order = new Order() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ComputerId = Convert.ToInt32(element.Element("ComputerId")!.Value), - ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + var order = new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComputerId = Convert.ToInt32(element.Element("ComputerId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), - Sum = Convert.ToDouble(element.Element("Sum")!.Value), - DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), - }; - DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), + }; + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); - order.DateImplement = dateImpl; + order.DateImplement = dateImpl; - if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) - { - return null; - } - order.Status = status; - return order; - } + if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) + { + return null; + } + order.Status = status; + return order; + } - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - DateImplement = model.DateImplement; - ImplementerId = model.ImplementerId; - } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; + } - public OrderViewModel GetViewModel => new() - { - Id = Id, - ComputerId = ComputerId, - ClientId = ClientId, - ImplementerId = ImplementerId, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement - }; + public OrderViewModel GetViewModel => new() + { + Id = Id, + ComputerId = ComputerId, + ClientId = ClientId, + ImplementerId = ImplementerId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; - public XElement GetXElement => new("Order", - new XAttribute("Id", Id), - new XElement("ComputerId", ComputerId), - new XElement("ClientId", ClientId), + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("ComputerId", ComputerId), + new XElement("ClientId", ClientId), new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), - new XElement("Sum", Sum.ToString()), - new XElement("Status", Status.ToString()), - new XElement("DateCreate", DateCreate.ToString()), - new XElement("DateImplement", DateImplement.ToString())); - } + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } } diff --git a/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj b/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj index 9805f44..0a0cb46 100644 --- a/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj +++ b/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/ComputersShop/ComputersShopListImplement/Implements/BackUpInfo.cs b/ComputersShop/ComputersShopListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..f501ec4 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using ComputersShopContracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/ComputersShop/ComputersShopListImplement/Implements/ClientStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ClientStorage.cs index 155b43b..eaeed7d 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ClientStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ClientStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopListImplement.Models; using System; diff --git a/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs index ed4e38d..2082944 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopListImplement.Models; using System; diff --git a/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs index 784574c..4564930 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopListImplement.Models; using System; diff --git a/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs index 462114a..71f616f 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopListImplement.Models; using System; diff --git a/ComputersShop/ComputersShopListImplement/Implements/MessageInfoStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/MessageInfoStorage.cs index bfa8252..d8efb0f 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/MessageInfoStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/MessageInfoStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopListImplement.Models; using System; diff --git a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs index d33cf81..282eca8 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs @@ -1,6 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopContracts.ViewModels; using ComputersShopListImplement; using ComputersShopListImplement.Models; @@ -10,104 +10,104 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace OrdersShopListImplement.Implements +namespace ComputersShopListImplement.Implements { - public class OrderStorage : IOrderStorage - { - private readonly DataListSingleton _source; - public OrderStorage() - { - _source = DataListSingleton.GetInstance(); - } - public List GetFullList() - { - var result = new List(); - foreach (var Order in _source.Orders) - { - result.Add(GetViewModel(Order)); - } - return result; - } - public List GetFilteredList(OrderSearchModel model) - { - var result = new List(); - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - return new() { GetViewModel(order) }; - } - else if (model.DateFrom.HasValue && model.DateTo.HasValue && model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo) - { - result.Add(GetViewModel(order)); - } - else if (model.ClientId.HasValue && order.ClientId == model.ClientId) - { - result.Add(GetViewModel(order)); - } - } - return result; - } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - foreach (var Order in _source.Orders) - { - if (model.Id.HasValue && Order.Id == model.Id) - { - return GetViewModel(Order); - } - } - return null; - } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = 1; - foreach (var Order in _source.Orders) - { - if (model.Id <= Order.Id) - { - model.Id = Order.Id + 1; - } - } - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - _source.Orders.Add(newOrder); - return GetViewModel(newOrder); - } - public OrderViewModel? Update(OrderBindingModel model) - { - foreach (var Order in _source.Orders) - { - if (Order.Id == model.Id) - { - Order.Update(model); - return GetViewModel(Order); - } - } - return null; - } - public OrderViewModel? Delete(OrderBindingModel model) - { - for (int i = 0; i < _source.Orders.Count; ++i) - { - if (_source.Orders[i].Id == model.Id) - { - var element = _source.Orders[i]; - _source.Orders.RemoveAt(i); - return GetViewModel(element); - } - } - return null; - } + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var Order in _source.Orders) + { + result.Add(GetViewModel(Order)); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + return new() { GetViewModel(order) }; + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue && model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo) + { + result.Add(GetViewModel(order)); + } + else if (model.ClientId.HasValue && order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var Order in _source.Orders) + { + if (model.Id.HasValue && Order.Id == model.Id) + { + return GetViewModel(Order); + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var Order in _source.Orders) + { + if (model.Id <= Order.Id) + { + model.Id = Order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return GetViewModel(newOrder); + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var Order in _source.Orders) + { + if (Order.Id == model.Id) + { + Order.Update(model); + return GetViewModel(Order); + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return GetViewModel(element); + } + } + return null; + } - private OrderViewModel GetViewModel(Order order) + private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; foreach (var comp in _source.Computers) @@ -118,15 +118,15 @@ namespace OrdersShopListImplement.Implements break; } } - foreach (var client in _source.Clients) - { - if (client.Id == order.ClientId) - { - viewModel.ClientFIO = client.ClientFIO; - break; - } - } - return viewModel; + foreach (var client in _source.Clients) + { + if (client.Id == order.ClientId) + { + viewModel.ClientFIO = client.ClientFIO; + break; + } + } + return viewModel; } - } + } } diff --git a/ComputersShop/ComputersShopListImplement/ListImplementationExtension.cs b/ComputersShop/ComputersShopListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..9a11007 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/ListImplementationExtension.cs @@ -0,0 +1,26 @@ +using ComputersShopContracts.DI; +using ComputersShopContracts.StorageContracts; +using ComputersShopListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/ComputersShop/ComputersShopListImplement/Models/Message.cs b/ComputersShop/ComputersShopListImplement/Models/Message.cs index da24fe7..7d4d2df 100644 --- a/ComputersShop/ComputersShopListImplement/Models/Message.cs +++ b/ComputersShop/ComputersShopListImplement/Models/Message.cs @@ -9,45 +9,47 @@ using System.Threading.Tasks; namespace ComputersShopListImplement.Models { - public class Message : IMessageInfoModel - { - public string MessageId { get; private set; } = string.Empty; + public class Message : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + public int? ClientId { get; private set; } - public string SenderName { get; private set; } = string.Empty; + public string SenderName { get; private set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + public DateTime DateDelivery { get; private set; } = DateTime.Now; - public string Subject { get; private set; } = string.Empty; + public string Subject { get; private set; } = string.Empty; - public string Body { get; private set; } = string.Empty; + public string Body { get; private set; } = string.Empty; - public static Message? Create(MessageInfoBindingModel model) - { - if (model == null) - { - return null; - } - return new() - { - Body = model.Body, - Subject = model.Subject, - ClientId = model.ClientId, - MessageId = model.MessageId, - SenderName = model.SenderName, - DateDelivery = model.DateDelivery, - }; - } + public int Id => throw new NotImplementedException(); - public MessageInfoViewModel GetViewModel => new() - { - Body = Body, - Subject = Subject, - ClientId = ClientId, - MessageId = MessageId, - SenderName = SenderName, - DateDelivery = DateDelivery, - }; - } + public static Message? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + } } diff --git a/ComputersShop/ComputersShopRestAPI/Program.cs b/ComputersShop/ComputersShopRestAPI/Program.cs index 02eb6d9..7ee1e97 100644 --- a/ComputersShop/ComputersShopRestAPI/Program.cs +++ b/ComputersShop/ComputersShopRestAPI/Program.cs @@ -2,7 +2,7 @@ using ComputersShopBusinessLogic.BusinessLogics; using ComputersShopBusinessLogic.MailWorker; using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopDataBaseImplement.Implements; using Microsoft.OpenApi.Models; diff --git a/ComputersShop/ComputersShopView/DataGridViewExtension.cs b/ComputersShop/ComputersShopView/DataGridViewExtension.cs new file mode 100644 index 0000000..d7ec64a --- /dev/null +++ b/ComputersShop/ComputersShopView/DataGridViewExtension.cs @@ -0,0 +1,52 @@ +using ComputersShopContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopView +{ + public static class DataGridViewExtension + { + public static void FillandConfigGrid(this DataGridView grid, List? data) + { + if (data == null) + { + return; + } + grid.DataSource = data; + var type = typeof(T); + var properties = type.GetProperties(); + foreach (DataGridViewColumn column in grid.Columns) + { + var property = properties.FirstOrDefault(x => x.Name == column.Name); + if (property == null) + { + throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}"); + } + var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault(); + if (attribute == null) + { + throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}"); + } + // ищем нужный нам атрибут + if (attribute is ColumnAttribute columnAttr) + { + column.HeaderText = columnAttr.Title; + column.Visible = columnAttr.Visible; + if (columnAttr.IsUseAutoSize) + { + column.AutoSizeMode = + (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode) + , columnAttr.GridViewAutoSize.ToString()); + } + else + { + column.Width = columnAttr.Width; + } + } + } + } + } +} diff --git a/ComputersShop/ComputersShopView/FormClients.cs b/ComputersShop/ComputersShopView/FormClients.cs index 685b170..8a44c1b 100644 --- a/ComputersShop/ComputersShopView/FormClients.cs +++ b/ComputersShop/ComputersShopView/FormClients.cs @@ -35,15 +35,9 @@ namespace ComputersShopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка клиентов"); - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка клиентов"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки клиентов"); diff --git a/ComputersShop/ComputersShopView/FormComponents.cs b/ComputersShop/ComputersShopView/FormComponents.cs index 7ce60da..03443dc 100644 --- a/ComputersShop/ComputersShopView/FormComponents.cs +++ b/ComputersShop/ComputersShopView/FormComponents.cs @@ -1,5 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; +using ComputersShopContracts.DI; using Microsoft.Extensions.Logging; using Microsoft.VisualBasic.Logging; using System; @@ -34,18 +35,12 @@ namespace ComputersShopView private void LoadData() { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); - } - catch (Exception ex) + try + { + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки компонентов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -54,8 +49,8 @@ namespace ComputersShopView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormComponent form) { if (form.ShowDialog() == DialogResult.OK) { @@ -68,8 +63,8 @@ namespace ComputersShopView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormComponent form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) diff --git a/ComputersShop/ComputersShopView/FormComputer.cs b/ComputersShop/ComputersShopView/FormComputer.cs index 687ffbb..855d0ef 100644 --- a/ComputersShop/ComputersShopView/FormComputer.cs +++ b/ComputersShop/ComputersShopView/FormComputer.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ComputersShopContracts.DI; namespace ComputersShopView { @@ -81,8 +82,8 @@ namespace ComputersShopView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComputerComponent)); - if (service is FormComputerComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormComputerComponent form) { if (form.ShowDialog() == DialogResult.OK) { @@ -109,8 +110,8 @@ namespace ComputersShopView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComputerComponent)); - if (service is FormComputerComponent form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormComputerComponent form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; diff --git a/ComputersShop/ComputersShopView/FormComputers.cs b/ComputersShop/ComputersShopView/FormComputers.cs index 1b39ed7..7cafaeb 100644 --- a/ComputersShop/ComputersShopView/FormComputers.cs +++ b/ComputersShop/ComputersShopView/FormComputers.cs @@ -1,5 +1,6 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; +using ComputersShopContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -34,15 +35,8 @@ namespace ComputersShopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComputerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ComputerComponents"].Visible = false; - } - _logger.LogInformation("Загрузка компьютеров"); + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компьютеров"); } catch (Exception ex) { @@ -53,8 +47,8 @@ namespace ComputersShopView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComputer)); - if (service is FormComputer form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormComputer form) { if (form.ShowDialog() == DialogResult.OK) { @@ -67,8 +61,8 @@ namespace ComputersShopView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComputer)); - if (service is FormComputer form) + var service = DependencyManager.Instance.Resolve(); + if (service is FormComputer form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) diff --git a/ComputersShop/ComputersShopView/FormImplementers.cs b/ComputersShop/ComputersShopView/FormImplementers.cs index b42b534..239570a 100644 --- a/ComputersShop/ComputersShopView/FormImplementers.cs +++ b/ComputersShop/ComputersShopView/FormImplementers.cs @@ -1,5 +1,7 @@ -using ComputersShopContracts.BindingModels; +using ComputersShopBusinessLogic.BusinessLogics; +using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; +using ComputersShopContracts.DI; using ComputersShopView; using Microsoft.Extensions.Logging; using System; @@ -33,16 +35,7 @@ namespace ComputersShopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) @@ -54,7 +47,7 @@ namespace ComputersShopView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -68,7 +61,7 @@ namespace ComputersShopView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/ComputersShop/ComputersShopView/FormMails.cs b/ComputersShop/ComputersShopView/FormMails.cs index 4baad03..386f4cd 100644 --- a/ComputersShop/ComputersShopView/FormMails.cs +++ b/ComputersShop/ComputersShopView/FormMails.cs @@ -1,4 +1,5 @@ -using ComputersShopContracts.BusinessLogicContracts; +using ComputersShopBusinessLogic.BusinessLogics; +using ComputersShopContracts.BusinessLogicContracts; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -28,15 +29,8 @@ namespace ComputersShopView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка писем"); + dataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка писем"); } catch (Exception ex) { diff --git a/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs index 9b2d5d4..6fb6b2a 100644 --- a/ComputersShop/ComputersShopView/FormMain.Designer.cs +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -39,18 +39,19 @@ componentsOfComputersToolStripMenuItem = new ToolStripMenuItem(); listOrderToolStripMenuItem = new ToolStripMenuItem(); doWorkToolStripMenuItem = new ToolStripMenuItem(); + почтаToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); - почтаToolStripMenuItem = new ToolStripMenuItem(); + CreateBackupToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // menuStrip // - menuStrip.Items.AddRange(new ToolStripItem[] { dictionaryToolStripMenuItem, отчётыToolStripMenuItem, doWorkToolStripMenuItem, почтаToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { dictionaryToolStripMenuItem, отчётыToolStripMenuItem, doWorkToolStripMenuItem, почтаToolStripMenuItem, CreateBackupToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1047, 24); @@ -127,6 +128,13 @@ doWorkToolStripMenuItem.Text = "Запуск работ"; doWorkToolStripMenuItem.Click += DoWorkToolStripMenuItem_Click; // + // почтаToolStripMenuItem + // + почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + почтаToolStripMenuItem.Size = new Size(53, 20); + почтаToolStripMenuItem.Text = "Почта"; + почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -166,12 +174,12 @@ buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += ButtonRef_Click; // - // почтаToolStripMenuItem + // CreateBackupToolStripMenuItem // - почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; - почтаToolStripMenuItem.Size = new Size(53, 20); - почтаToolStripMenuItem.Text = "Почта"; - почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; + CreateBackupToolStripMenuItem.Name = "CreateBackupToolStripMenuItem"; + CreateBackupToolStripMenuItem.Size = new Size(97, 20); + CreateBackupToolStripMenuItem.Text = "Создать Бекап"; + CreateBackupToolStripMenuItem.Click += CreateBackupToolStripMenuItem_Click; // // FormMain // @@ -212,5 +220,6 @@ private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem doWorkToolStripMenuItem; private ToolStripMenuItem почтаToolStripMenuItem; + private ToolStripMenuItem CreateBackupToolStripMenuItem; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormMain.cs b/ComputersShop/ComputersShopView/FormMain.cs index 8a0776d..c30825f 100644 --- a/ComputersShop/ComputersShopView/FormMain.cs +++ b/ComputersShop/ComputersShopView/FormMain.cs @@ -1,6 +1,7 @@ using ComputersShopBusinessLogic.BusinessLogics; using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicContracts; +using ComputersShopContracts.DI; using ComputersShopDataModels.Enums; using Microsoft.Extensions.Logging; using System; @@ -21,14 +22,16 @@ namespace ComputersShopView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportlogic, IWorkProcess workProcess) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportlogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportlogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -40,14 +43,7 @@ namespace ComputersShopView _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ComputerId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - } + dataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -58,7 +54,7 @@ namespace ComputersShopView } private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponents form) { form.ShowDialog(); @@ -66,7 +62,7 @@ namespace ComputersShopView } private void ComputersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComputers)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComputers form) { form.ShowDialog(); @@ -74,7 +70,7 @@ namespace ComputersShopView } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -186,7 +182,7 @@ namespace ComputersShopView private void ComputerComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportComputerComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportComputerComponents form) { form.ShowDialog(); @@ -195,7 +191,7 @@ namespace ComputersShopView private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportOrders form) { form.ShowDialog(); @@ -204,7 +200,7 @@ namespace ComputersShopView private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormClients form) { form.ShowDialog(); @@ -213,7 +209,7 @@ namespace ComputersShopView private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementers form) { form.ShowDialog(); @@ -222,8 +218,8 @@ namespace ComputersShopView private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork(( - Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, + _workProcess.DoWork( + DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -231,7 +227,7 @@ namespace ComputersShopView private void почтаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + var service = DependencyManager.Instance.Resolve(); if (service is FormMails form) { form.ShowDialog(); @@ -242,5 +238,31 @@ namespace ComputersShopView { LoadData(); } + + private void CreateBackupToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + } } } diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index e3edee7..cb699ec 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -2,20 +2,19 @@ using ComputersShopBusinessLogic.BusinessLogics; using ComputersShopBusinessLogic.OfficePackage.Implements; using ComputersShopBusinessLogic.OfficePackage; using ComputersShopContracts.BusinessLogicContracts; -using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.StorageContracts; using ComputersShopDataBaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using ComputersShopBusinessLogic.MailWorker; using ComputersShopContracts.BindingModels; +using ComputersShopContracts.DI; namespace ComputersShopView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -25,12 +24,10 @@ namespace ComputersShopView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -45,54 +42,92 @@ namespace ComputersShopView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "Error"); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) + /*private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddSingleton(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + }*/ + + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/ComputersShop/ImplementationExtensions/ComputersShopContracts.dll b/ComputersShop/ImplementationExtensions/ComputersShopContracts.dll new file mode 100644 index 0000000..975d73c Binary files /dev/null and b/ComputersShop/ImplementationExtensions/ComputersShopContracts.dll differ diff --git a/ComputersShop/ImplementationExtensions/ComputersShopDataBaseImplement.dll b/ComputersShop/ImplementationExtensions/ComputersShopDataBaseImplement.dll new file mode 100644 index 0000000..9cc3600 Binary files /dev/null and b/ComputersShop/ImplementationExtensions/ComputersShopDataBaseImplement.dll differ diff --git a/ComputersShop/ImplementationExtensions/ComputersShopFileImplement.dll b/ComputersShop/ImplementationExtensions/ComputersShopFileImplement.dll new file mode 100644 index 0000000..cdb47e3 Binary files /dev/null and b/ComputersShop/ImplementationExtensions/ComputersShopFileImplement.dll differ diff --git a/ComputersShop/ImplementationExtensions/СomputersShopDataModels.dll b/ComputersShop/ImplementationExtensions/СomputersShopDataModels.dll new file mode 100644 index 0000000..447c605 Binary files /dev/null and b/ComputersShop/ImplementationExtensions/СomputersShopDataModels.dll differ diff --git a/ComputersShop/СomputersShopDataModels/Models/IMessageInfoModel.cs b/ComputersShop/СomputersShopDataModels/Models/IMessageInfoModel.cs index 5985ff7..77f4620 100644 --- a/ComputersShop/СomputersShopDataModels/Models/IMessageInfoModel.cs +++ b/ComputersShop/СomputersShopDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ComputersShopDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; }