diff --git a/Device.sln b/Device.sln index 67b107d..b81ffa2 100644 --- a/Device.sln +++ b/Device.sln @@ -3,24 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceDataModels", "DeviceDataModels\DeviceDataModels.csproj", "{E4D8A5BF-C4ED-4E90-A630-A8880C4B4436}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceContracts", "DeviceContracts\DeviceContracts.csproj", "{FA3605A8-7525-47B5-BE3E-4A90001971B5}" - ProjectSection(ProjectDependencies) = postProject - {E4D8A5BF-C4ED-4E90-A630-A8880C4B4436} = {E4D8A5BF-C4ED-4E90-A630-A8880C4B4436} - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceBusinessLogic", "DeviceBusinessLogic\DeviceBusinessLogic.csproj", "{6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}" - ProjectSection(ProjectDependencies) = postProject - {FA3605A8-7525-47B5-BE3E-4A90001971B5} = {FA3605A8-7525-47B5-BE3E-4A90001971B5} - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceDatabaseImplement", "DeviceDatabaseImplement\DeviceDatabaseImplement.csproj", "{B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}" - ProjectSection(ProjectDependencies) = postProject - {E4D8A5BF-C4ED-4E90-A630-A8880C4B4436} = {E4D8A5BF-C4ED-4E90-A630-A8880C4B4436} - {FA3605A8-7525-47B5-BE3E-4A90001971B5} = {FA3605A8-7525-47B5-BE3E-4A90001971B5} - EndProjectSection -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceAdmin", "DeviceAdmin\DeviceAdmin.csproj", "{F86C47E2-B3BC-4A88-85F8-84ED1DC1E089}" EndProject Global @@ -29,22 +11,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E4D8A5BF-C4ED-4E90-A630-A8880C4B4436}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E4D8A5BF-C4ED-4E90-A630-A8880C4B4436}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E4D8A5BF-C4ED-4E90-A630-A8880C4B4436}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E4D8A5BF-C4ED-4E90-A630-A8880C4B4436}.Release|Any CPU.Build.0 = Release|Any CPU - {FA3605A8-7525-47B5-BE3E-4A90001971B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FA3605A8-7525-47B5-BE3E-4A90001971B5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FA3605A8-7525-47B5-BE3E-4A90001971B5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FA3605A8-7525-47B5-BE3E-4A90001971B5}.Release|Any CPU.Build.0 = Release|Any CPU - {6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6C1D1FDB-1C09-4A68-8EF3-F4899C7D6472}.Release|Any CPU.Build.0 = Release|Any CPU - {B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B3881967-AAD2-4E7E-BAD9-8F6267CCDA5E}.Release|Any CPU.Build.0 = Release|Any CPU {F86C47E2-B3BC-4A88-85F8-84ED1DC1E089}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F86C47E2-B3BC-4A88-85F8-84ED1DC1E089}.Debug|Any CPU.Build.0 = Debug|Any CPU {F86C47E2-B3BC-4A88-85F8-84ED1DC1E089}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/DeviceAdmin/DeviceAdmin.csproj b/DeviceAdmin/DeviceAdmin.csproj index d674b25..a5cfb65 100644 --- a/DeviceAdmin/DeviceAdmin.csproj +++ b/DeviceAdmin/DeviceAdmin.csproj @@ -13,11 +13,5 @@ - - - - - - \ No newline at end of file diff --git a/DeviceAdmin/FormCabinets.cs b/DeviceAdmin/FormCabinets.cs index 3c0b7f0..e2ae555 100644 --- a/DeviceAdmin/FormCabinets.cs +++ b/DeviceAdmin/FormCabinets.cs @@ -1,5 +1,4 @@ -using Microsoft.Data.SqlClient; -using Npgsql; +using Npgsql; using System; using System.Collections.Generic; using System.ComponentModel; diff --git a/DeviceAdmin/FormDevices.cs b/DeviceAdmin/FormDevices.cs index edbee6b..cb797a8 100644 --- a/DeviceAdmin/FormDevices.cs +++ b/DeviceAdmin/FormDevices.cs @@ -1,5 +1,4 @@ -using Microsoft.Data.SqlClient; -using Npgsql; +using Npgsql; using NpgsqlTypes; using Renci.SshNet; using System; diff --git a/DeviceAdmin/FormMain.cs b/DeviceAdmin/FormMain.cs index 860ca40..7703088 100644 --- a/DeviceAdmin/FormMain.cs +++ b/DeviceAdmin/FormMain.cs @@ -9,68 +9,54 @@ namespace DeviceAdmin { InitializeComponent(); } - private void ButtonCabinets_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService( - typeof(FormCabinets)); - if (service is FormCabinets form) - { - form.ShowDialog(); - } - } - private void ButtonDevices_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService( - typeof(FormDevices)); - if (service is FormDevices form) - { - form.ShowDialog(); - } - } - private void ButtonKinds_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService( - typeof(FormKinds)); - if (service is FormKinds form) - { - form.ShowDialog(); - } - } - private void ButtonKits_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService( - typeof(FormKits)); - if (service is FormKits form) - { - form.ShowDialog(); - } - } - private void ButtonOwnership_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService( - typeof(FormOwnership)); - if (service is FormOwnership form) - { - form.ShowDialog(); - } - } - private void ButtonService_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService( - typeof(FormServices)); - if (service is FormServices form) - { - form.ShowDialog(); - } - } - private void ButtonStaff_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService( - typeof(FormStaff)); - if (service is FormStaff form) - { - form.ShowDialog(); - } - } - } + private void ButtonCabinets_Click(object sender, EventArgs e) + { + using (var form = new FormCabinets()) + { + form.ShowDialog(); + } + } + private void ButtonDevices_Click(object sender, EventArgs e) + { + using (var form = new FormDevices()) + { + form.ShowDialog(); + } + } + private void ButtonKinds_Click(object sender, EventArgs e) + { + using (var form = new FormKinds()) + { + form.ShowDialog(); + } + } + private void ButtonKits_Click(object sender, EventArgs e) + { + using (var form = new FormKits()) + { + form.ShowDialog(); + } + } + private void ButtonOwnership_Click(object sender, EventArgs e) + { + using (var form = new FormOwnership()) + { + form.ShowDialog(); + } + } + private void ButtonService_Click(object sender, EventArgs e) + { + using (var form = new FormServices()) + { + form.ShowDialog(); + } + } + private void ButtonStaff_Click(object sender, EventArgs e) + { + using (var form = new FormStaff()) + { + form.ShowDialog(); + } + } + } } diff --git a/DeviceAdmin/Program.cs b/DeviceAdmin/Program.cs index 95d6f87..0469725 100644 --- a/DeviceAdmin/Program.cs +++ b/DeviceAdmin/Program.cs @@ -1,18 +1,11 @@ -using DeviceBusinessLogic.BusinessLogics; -using DeviceContracts.BusinessLogicsContracts; -using DeviceContracts.StoragesContracts; -using DeviceDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Renci.SshNet; using Npgsql; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace DeviceAdmin { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; public static NpgsqlConnection connection { get; set; } public static SshClient client; public static ForwardedPortLocal portForwarded; @@ -34,33 +27,7 @@ namespace DeviceAdmin portForwarded.Start(); connection = new NpgsqlConnection("Server=127.0.0.1;Port=15432;Database=device;User Id=postgres;Password=postgres;"); connection.Open(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) - { - 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.AddTransient(); - } + Application.Run(new FormMain()); + } } } \ No newline at end of file diff --git a/DeviceBusinessLogic/BusinessLogics/CabinetLogic.cs b/DeviceBusinessLogic/BusinessLogics/CabinetLogic.cs deleted file mode 100644 index dc90052..0000000 --- a/DeviceBusinessLogic/BusinessLogics/CabinetLogic.cs +++ /dev/null @@ -1,129 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.BusinessLogicsContracts; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using Microsoft.Extensions.Logging; - -namespace DeviceBusinessLogic.BusinessLogics -{ - public class CabinetLogic : ICabinetLogic - { - private readonly ILogger _logger; - private readonly ICabinetStorage _cabinetStorage; - public CabinetLogic(ILogger logger, - ICabinetStorage cabinetStorage) - { - _logger = logger; - _cabinetStorage = cabinetStorage; - } - public bool Create(CabinetBindingModel model) - { - CheckModel(model); - if (_cabinetStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(CabinetBindingModel model) - { - CheckModel(model); - if (_cabinetStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(CabinetBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id: {Id}", model.Id); - if (_cabinetStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public List? ReadList(CabinetSearchModel? model) - { - _logger.LogInformation( - "ReadList. Id: {Id}, Room: {Room}, Building: " + - "{Building}.", model?.Id, model?.Room, model?.Building); - var list = model == null ? _cabinetStorage.GetFullList() : - _cabinetStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; - } - public CabinetViewModel? ReadElement(CabinetSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation( - "ReadElemnt. Id: {Id}, Room: {Room}, Building: " + - "{Building}.", model?.Id, model?.Room, model?.Building); - var element = _cabinetStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id: {Id}", - element.Id); - return element; - } - private void CheckModel(CabinetBindingModel model, - bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Id <= 0) - { - throw new ArgumentNullException( - "Идентификатор должен быть больше 0", - nameof(model.Id)); - } - if (string.IsNullOrEmpty(model.Room)) - { - throw new ArgumentNullException( - "Отсутствует номер/название кабинета", - nameof(model.Room)); - } - if (model.Building < 1) - { - throw new ArgumentNullException( - "Номер корпуса должен быть больше 0", - nameof(model.Id)); - } - _logger.LogInformation( - "Id: {Id}, Room: {Room}, Building: " + - "{Building}.", model?.Id, model?.Room, model?.Building); - var elementByRoom = _cabinetStorage.GetElement( - new CabinetSearchModel - { - Room = model.Room, - }); - var elementByBuilding = _cabinetStorage.GetElement( - new CabinetSearchModel - { - Building = model.Building, - }); - } - } -} \ No newline at end of file diff --git a/DeviceBusinessLogic/BusinessLogics/DeviceLogic.cs b/DeviceBusinessLogic/BusinessLogics/DeviceLogic.cs deleted file mode 100644 index cdb2cbf..0000000 --- a/DeviceBusinessLogic/BusinessLogics/DeviceLogic.cs +++ /dev/null @@ -1,176 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.BusinessLogicsContracts; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using DeviceDataModels; -using Microsoft.Extensions.Logging; - -namespace DeviceBusinessLogic.BusinessLogics -{ - public class DeviceLogic : IDeviceLogic - { - private readonly ILogger _logger; - private readonly IDeviceStorage _deviceStorage; - public DeviceLogic(ILogger logger, - IDeviceStorage deviceStorage) - { - _logger = logger; - _deviceStorage = deviceStorage; - } - public bool Create(DeviceBindingModel model) - { - CheckModel(model); - if (_deviceStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(DeviceBindingModel model) - { - CheckModel(model); - if (_deviceStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(DeviceBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id: {Id}", model.Id); - if (_deviceStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public List? ReadList(DeviceSearchModel? model) - { - _logger.LogInformation( - "ReadList. Id: {Id}, Model: {Model}, SerialNumber: " + - "{SerialNumber}, ProductionDate: {ProductionDate}, " + - "WarrantyPeriod: {WarrantyPeriod}, Condition: {Condition}, " + - "KindId: {KindId}, KitId: {KitId}", model?.Id, model?.Model, - model?.SerialNumber, model?.ProductionDate, - model?.WarrantyPeriod, model?.Condition, - model?.KindId, model?.KitId); - var list = model == null ? _deviceStorage.GetFullList() : - _deviceStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; - } - public DeviceViewModel? ReadElement(DeviceSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation( - "ReadElement. Id: {Id}, Model: {Model}, SerialNumber: " + - "{SerialNumber}, ProductionDate: {ProductionDate}, " + - "WarrantyPeriod: {WarrantyPeriod}, Condition: {Condition}, " + - "KindId: {KindId}, KitId: {KitId}", model?.Id, model?.Model, - model?.SerialNumber, model?.ProductionDate, - model?.WarrantyPeriod, model?.Condition, - model?.KindId, model?.KitId); - var element = _deviceStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id: {Id}", - element.Id); - return element; - } - private void CheckModel(DeviceBindingModel model, - bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Id <= 0) - { - throw new ArgumentNullException( - "Идентификатор должен быть больше 0", - nameof(model.Id)); - } - if (string.IsNullOrEmpty(model.Model)) - { - throw new ArgumentNullException( - "Отсутствует название модели", - nameof(model.Model)); - } - if ((model.Condition != true) && (model.Condition != false)) - { - throw new ArgumentNullException( - "Отсутствует показатель работоспособности", - nameof(model.Model)); - } - if (model.KindId <= 0) - { - throw new ArgumentNullException( - "Идентификатор вида должен быть больше 0", - nameof(model.Id)); - } - _logger.LogInformation( - "ReadElement. Id: {Id}, Model: {Model}, SerialNumber: " + - "{SerialNumber}, ProductionDate: {ProductionDate}, " + - "WarrantyPeriod: {WarrantyPeriod}, Condition: {Condition}, " + - "KindId: {KindId}, KitId: {KitId}", model?.Id, model?.Model, - model?.SerialNumber, model?.ProductionDate, - model?.WarrantyPeriod, model?.Condition, - model?.KindId, model?.KitId); - var elementByModel = _deviceStorage.GetElement( - new DeviceSearchModel - { - Model = model.Model, - }); - var elementBySerialNumber = _deviceStorage.GetElement( - new DeviceSearchModel - { - SerialNumber = model.SerialNumber, - }); - var elementByProductionDate = _deviceStorage.GetElement( - new DeviceSearchModel - { - ProductionDate = model.ProductionDate, - }); - var elementByWarrantyPeriod = _deviceStorage.GetElement( - new DeviceSearchModel - { - WarrantyPeriod = model.WarrantyPeriod, - }); - var elementByCondition = _deviceStorage.GetElement( - new DeviceSearchModel - { - Condition = model.Condition, - }); - var elementByKindId = _deviceStorage.GetElement( - new DeviceSearchModel - { - KindId = model.KindId, - }); - var elementByKitId = _deviceStorage.GetElement( - new DeviceSearchModel - { - KitId = model.KitId, - }); - } - } -} \ No newline at end of file diff --git a/DeviceBusinessLogic/BusinessLogics/KindLogic.cs b/DeviceBusinessLogic/BusinessLogics/KindLogic.cs deleted file mode 100644 index 98a1d0a..0000000 --- a/DeviceBusinessLogic/BusinessLogics/KindLogic.cs +++ /dev/null @@ -1,135 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.BusinessLogicsContracts; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using Microsoft.Extensions.Logging; - -namespace DeviceBusinessLogic.BusinessLogics -{ - public class KindLogic : IKindLogic - { - private readonly ILogger _logger; - private readonly IKindStorage _kindStorage; - public KindLogic(ILogger logger, - IKindStorage kindStorage) - { - _logger = logger; - _kindStorage = kindStorage; - } - public bool Create(KindBindingModel model) - { - CheckModel(model); - if (_kindStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(KindBindingModel model) - { - CheckModel(model); - if (_kindStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(KindBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id: {Id}", model.Id); - if (_kindStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public List? ReadList(KindSearchModel? model) - { - _logger.LogInformation( - "ReadList. Id: {Id}, Title: {Title}, Frequency: " + - "{Frequency}.", model?.Id, model?.Title, model?.Frequency); - var list = model == null ? _kindStorage.GetFullList() : - _kindStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; - } - public KindViewModel? ReadElement(KindSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation( - "ReadElement. Id: {Id}, Title: {Title}, Frequency: " + - "{Frequency}.", model?.Id, model?.Title, model?.Frequency); - var element = _kindStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id: {Id}", - element.Id); - return element; - } - private void CheckModel(KindBindingModel model, - bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Id <= 0) - { - throw new ArgumentNullException( - "Идентификатор должен быть больше 0", - nameof(model.Id)); - } - if (string.IsNullOrEmpty(model.Title)) - { - throw new ArgumentNullException( - "Отсутствует название вида устройства", - nameof(model.Title)); - } - if (string.IsNullOrEmpty(model.Title)) - { - throw new ArgumentNullException( - "Отсутствует название вида устройства", - nameof(model.Title)); - } - if (model.Frequency > 0) - { - throw new ArgumentNullException( - "Частота обслуживания должна быть больше 0 месяцев", - nameof(model.Frequency)); - } - _logger.LogInformation( - "Id: {Id}, Title: {Title}, Frequency: " + - "{Frequency}.", model?.Id, model?.Title, model?.Frequency); - var elementByTitle = _kindStorage.GetElement( - new KindSearchModel - { - Title = model.Title, - }); - var elementByFrequency = _kindStorage.GetElement( - new KindSearchModel - { - Frequency = model.Frequency, - }); - } - } -} \ No newline at end of file diff --git a/DeviceBusinessLogic/BusinessLogics/KitLogic.cs b/DeviceBusinessLogic/BusinessLogics/KitLogic.cs deleted file mode 100644 index c7a1866..0000000 --- a/DeviceBusinessLogic/BusinessLogics/KitLogic.cs +++ /dev/null @@ -1,118 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.BusinessLogicsContracts; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using Microsoft.Extensions.Logging; - -namespace DeviceBusinessLogic.BusinessLogics -{ - public class KitLogic : IKitLogic - { - private readonly ILogger _logger; - private readonly IKitStorage _kitStorage; - public KitLogic(ILogger logger, - IKitStorage kitStorage) - { - _logger = logger; - _kitStorage = kitStorage; - } - public bool Create(KitBindingModel model) - { - CheckModel(model); - if (_kitStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(KitBindingModel model) - { - CheckModel(model); - if (_kitStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(KitBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id: {Id}", model.Id); - if (_kitStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public List? ReadList(KitSearchModel? model) - { - _logger.LogInformation( - "ReadList. Id: {Id}, Title: {Title}, CabinetId: " + - "{CabinetId}.", model?.Id, model?.Title, model?.CabinetId); - var list = model == null ? _kitStorage.GetFullList() : - _kitStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; - } - public KitViewModel? ReadElement(KitSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation( - "ReadElement. Id: {Id}, Title: {Title}, CabinetId: " + - "{CabinetId}.", model?.Id, model?.Title, model?.CabinetId); - var element = _kitStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id: {Id}", - element.Id); - return element; - } - private void CheckModel(KitBindingModel model, - bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Id <= 0) - { - throw new ArgumentNullException( - "Идентификатор должен быть больше 0", - nameof(model.Id)); - } - if (string.IsNullOrEmpty(model.Title)) - { - throw new ArgumentNullException( - "Отсутствует номер/название кабинета", - nameof(model.Title)); - } - _logger.LogInformation( - "Id: {Id}, Title: {Title}, CabinetId: " + - "{CabinetId}.", model?.Id, model?.Title, model?.CabinetId); - var elementByTitle = _kitStorage.GetElement( - new KitSearchModel - { - Title = model.Title, - }); - } - } -} \ No newline at end of file diff --git a/DeviceBusinessLogic/BusinessLogics/ServiceLogic.cs b/DeviceBusinessLogic/BusinessLogics/ServiceLogic.cs deleted file mode 100644 index d51e24b..0000000 --- a/DeviceBusinessLogic/BusinessLogics/ServiceLogic.cs +++ /dev/null @@ -1,147 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.BusinessLogicsContracts; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using Microsoft.Extensions.Logging; - -namespace DeviceBusinessLogic.BusinessLogics -{ - public class ServiceLogic : IServiceLogic - { - private readonly ILogger _logger; - private readonly IServiceStorage _serviceStorage; - public ServiceLogic(ILogger logger, - IServiceStorage serviceStorage) - { - _logger = logger; - _serviceStorage = serviceStorage; - } - public bool Create(ServiceBindingModel model) - { - CheckModel(model); - if (_serviceStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(ServiceBindingModel model) - { - CheckModel(model); - if (_serviceStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(ServiceBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id: {Id}", model.Id); - if (_serviceStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public List? ReadList(ServiceSearchModel? model) - { - _logger.LogInformation( - "ReadList. Id: {Id}, Description: {Description}, StartDate: " + - "{StartDate}, EndDate: {EndDate}, DeviceId: {DeviceId}.", - model?.Id, model?.Description, model?.StartDate, - model?.EndDate, model?.DeviceId); - var list = model == null ? _serviceStorage.GetFullList() : - _serviceStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; - } - public ServiceViewModel? ReadElement(ServiceSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation( - "ReadElement. Id: {Id}, Description: {Description}, " + - "StartDate: {StartDate}, EndDate: " + - "{EndDate}, DeviceId: {DeviceId}.", - model?.Id, model?.Description, model?.StartDate, - model?.EndDate, model?.DeviceId); - var element = _serviceStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id: {Id}", - element.Id); - return element; - } - private void CheckModel(ServiceBindingModel model, - bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Id <= 0) - { - throw new ArgumentNullException( - "Идентификатор должен быть больше 0", - nameof(model.Id)); - } - if (string.IsNullOrEmpty(model.Description)) - { - throw new ArgumentNullException( - "Отсутствует описание", - nameof(model.Description)); - } - if (model.DeviceId <= 0) - { - throw new ArgumentNullException( - "Идентификатор устройства должен быть больше 0", - nameof(model.Id)); - } - _logger.LogInformation( - "Id: {Id}, Description: {Description}, " + - "StartDate: {StartDate}, EndDate: " + - "{EndDate}, DeviceId: {DeviceId}.", - model?.Id, model?.Description, model?.StartDate, - model?.EndDate, model?.DeviceId); - var elementByDescription = _serviceStorage.GetElement( - new ServiceSearchModel - { - Description = model.Description, - }); - var elementByDeviceId = _serviceStorage.GetElement( - new ServiceSearchModel - { - DeviceId = model.DeviceId, - }); - var elementByStartDate = _serviceStorage.GetElement( - new ServiceSearchModel - { - StartDate = model.StartDate, - }); - var elementByEndDate = _serviceStorage.GetElement( - new ServiceSearchModel - { - EndDate = model.EndDate, - }); - } - } -} \ No newline at end of file diff --git a/DeviceBusinessLogic/BusinessLogics/StaffLogic.cs b/DeviceBusinessLogic/BusinessLogics/StaffLogic.cs deleted file mode 100644 index 77cad1b..0000000 --- a/DeviceBusinessLogic/BusinessLogics/StaffLogic.cs +++ /dev/null @@ -1,152 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.BusinessLogicsContracts; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using Microsoft.Extensions.Logging; - -namespace DeviceBusinessLogic.BusinessLogics -{ - public class StaffLogic : IStaffLogic - { - private readonly ILogger _logger; - private readonly IStaffStorage _staffStorage; - public StaffLogic(ILogger logger, - IStaffStorage staffStorage) - { - _logger = logger; - _staffStorage = staffStorage; - } - public bool Create(StaffBindingModel model) - { - CheckModel(model); - if (_staffStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(StaffBindingModel model) - { - CheckModel(model); - if (_staffStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(StaffBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id: {Id}", model.Id); - if (_staffStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public List? ReadList(StaffSearchModel? model) - { - _logger.LogInformation( - "ReadList. Id: {Id}, FullName: {FullName}, Department: " + - "{Department}, Email: {Email}, AccessLevel: {AccessLevel},", - model?.Id, model?.FullName, - model?.Department, model?.Email, model?.AccessLevel); - var list = model == null ? _staffStorage.GetFullList() : - _staffStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; - } - public StaffViewModel? ReadElement(StaffSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation( - "ReadList. Id: {Id}, FullName: {FullName}, Department: " + - "{Department}, Email: {Email}, AccessLevel: {AccessLevel},", - model?.Id, model?.FullName, - model?.Department, model?.Email, model?.AccessLevel); - var element = _staffStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id: {Id}", - element.Id); - return element; - } - private void CheckModel(StaffBindingModel model, - bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Id <= 0) - { - throw new ArgumentNullException( - "Идентификатор должен быть больше 0", - nameof(model.Id)); - } - if (string.IsNullOrEmpty(model.FullName)) - { - throw new ArgumentNullException( - "Отсутствует ФИО", - nameof(model.FullName)); - } - if (string.IsNullOrEmpty(model.Department)) - { - throw new ArgumentNullException( - "Отсутствует ФИО", - nameof(model.Department)); - } - if (string.IsNullOrEmpty(model.Email)) - { - throw new ArgumentNullException( - "Отсутствует ФИО", - nameof(model.Email)); - } - if (string.IsNullOrEmpty(model.Password)) - { - throw new ArgumentNullException( - "Отсутствует ФИО", - nameof(model.Password)); - } - _logger.LogInformation( - "ReadList. Id: {Id}, FullName: {FullName}, Department: " + - "{Department}, Email: {Email}, AccessLevel: {AccessLevel},", - model?.Id, model?.FullName, - model?.Department, model?.Email, model?.AccessLevel); - var elementByFullName = _staffStorage.GetElement( - new StaffSearchModel - { - FullName = model.FullName, - }); - var elementByDepartment = _staffStorage.GetElement( - new StaffSearchModel - { - Department = model.Department, - }); - var elementByEmail = _staffStorage.GetElement( - new StaffSearchModel - { - Email = model.Email, - }); - } - } -} \ No newline at end of file diff --git a/DeviceBusinessLogic/DeviceBusinessLogic.csproj b/DeviceBusinessLogic/DeviceBusinessLogic.csproj deleted file mode 100644 index f1e2d50..0000000 --- a/DeviceBusinessLogic/DeviceBusinessLogic.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - - - - diff --git a/DeviceContracts/BindingModels/CabinetBindingModel.cs b/DeviceContracts/BindingModels/CabinetBindingModel.cs deleted file mode 100644 index 0e6d575..0000000 --- a/DeviceContracts/BindingModels/CabinetBindingModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -using DeviceDataModels.Models; -namespace DeviceContracts.BindingModels -{ - public class CabinetBindingModel : ICabinetModel - { - public int Id { get; set; } - public string Room { get; set; } = string.Empty; - public int Building { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/BindingModels/DeviceBindingModel.cs b/DeviceContracts/BindingModels/DeviceBindingModel.cs deleted file mode 100644 index 994b4a7..0000000 --- a/DeviceContracts/BindingModels/DeviceBindingModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DeviceDataModels.Models; -namespace DeviceContracts.BindingModels -{ - public class DeviceBindingModel : IDeviceModel - { - public int Id { get; set; } - public string Model { get; set; } = string.Empty; - public string? SerialNumber { get; set; } = string.Empty; - public DateOnly? ProductionDate { get; set; } - public int? WarrantyPeriod { get; set; } - public bool Condition { get; set; } - public int KindId { get; set; } - public int? KitId { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/BindingModels/KindBindingModel.cs b/DeviceContracts/BindingModels/KindBindingModel.cs deleted file mode 100644 index 60ec66b..0000000 --- a/DeviceContracts/BindingModels/KindBindingModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -using DeviceDataModels.Models; -namespace DeviceContracts.BindingModels -{ - public class KindBindingModel : IKindModel - { - public int Id { get; set; } - public string Title { get; set; } = string.Empty; - public int Frequency { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/BindingModels/KitBindingModel.cs b/DeviceContracts/BindingModels/KitBindingModel.cs deleted file mode 100644 index 1309d79..0000000 --- a/DeviceContracts/BindingModels/KitBindingModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -using DeviceDataModels.Models; -namespace DeviceContracts.BindingModels -{ - public class KitBindingModel : IKitModel - { - public int Id { get; set; } - public string Title { get; set; } = string.Empty; - public int? CabinetId { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/BindingModels/ServiceBindingModel.cs b/DeviceContracts/BindingModels/ServiceBindingModel.cs deleted file mode 100644 index e699fe9..0000000 --- a/DeviceContracts/BindingModels/ServiceBindingModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using DeviceDataModels.Models; -namespace DeviceContracts.BindingModels -{ - public class ServiceBindingModel : IServiceModel - { - public int Id { get; set; } - public string Description { get; set; } = string.Empty; - public DateOnly StartDate { get; set; } - public DateOnly? EndDate { get; set; } - public int DeviceId { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/BindingModels/StaffBindingModel.cs b/DeviceContracts/BindingModels/StaffBindingModel.cs deleted file mode 100644 index e730b55..0000000 --- a/DeviceContracts/BindingModels/StaffBindingModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using DeviceDataModels.Enums; -using DeviceDataModels.Models; -namespace DeviceContracts.BindingModels -{ - public class StaffBindingModel : IStaffModel - { - public int Id { get; set; } - public string FullName { get; set; } = string.Empty; - public string Department { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public AccessLevel AccessLevel { get; } - public Dictionary Ownership { get; set; } - = new(); - } -} \ No newline at end of file diff --git a/DeviceContracts/BusinessLogicsContracts/ICabinetLogic.cs b/DeviceContracts/BusinessLogicsContracts/ICabinetLogic.cs deleted file mode 100644 index 1f0fe86..0000000 --- a/DeviceContracts/BusinessLogicsContracts/ICabinetLogic.cs +++ /dev/null @@ -1,14 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.BusinessLogicsContracts -{ - public interface ICabinetLogic - { - List? ReadList(CabinetSearchModel? model); - CabinetViewModel? ReadElement(CabinetSearchModel model); - bool Create(CabinetBindingModel model); - bool Update(CabinetBindingModel model); - bool Delete(CabinetBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/BusinessLogicsContracts/IDeviceLogic.cs b/DeviceContracts/BusinessLogicsContracts/IDeviceLogic.cs deleted file mode 100644 index 07fa854..0000000 --- a/DeviceContracts/BusinessLogicsContracts/IDeviceLogic.cs +++ /dev/null @@ -1,14 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.BusinessLogicsContracts -{ - public interface IDeviceLogic - { - List? ReadList(DeviceSearchModel? model); - DeviceViewModel? ReadElement(DeviceSearchModel model); - bool Create(DeviceBindingModel model); - bool Update(DeviceBindingModel model); - bool Delete(DeviceBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/BusinessLogicsContracts/IKindLogic.cs b/DeviceContracts/BusinessLogicsContracts/IKindLogic.cs deleted file mode 100644 index 816cd67..0000000 --- a/DeviceContracts/BusinessLogicsContracts/IKindLogic.cs +++ /dev/null @@ -1,14 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.BusinessLogicsContracts -{ - public interface IKindLogic - { - List? ReadList(KindSearchModel? model); - KindViewModel? ReadElement(KindSearchModel model); - bool Create(KindBindingModel model); - bool Update(KindBindingModel model); - bool Delete(KindBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/BusinessLogicsContracts/IKitLogic.cs b/DeviceContracts/BusinessLogicsContracts/IKitLogic.cs deleted file mode 100644 index 05d8550..0000000 --- a/DeviceContracts/BusinessLogicsContracts/IKitLogic.cs +++ /dev/null @@ -1,14 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.BusinessLogicsContracts -{ - public interface IKitLogic - { - List? ReadList(KitSearchModel? model); - KitViewModel? ReadElement(KitSearchModel model); - bool Create(KitBindingModel model); - bool Update(KitBindingModel model); - bool Delete(KitBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/BusinessLogicsContracts/IServiceLogic.cs b/DeviceContracts/BusinessLogicsContracts/IServiceLogic.cs deleted file mode 100644 index e94971f..0000000 --- a/DeviceContracts/BusinessLogicsContracts/IServiceLogic.cs +++ /dev/null @@ -1,14 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.BusinessLogicsContracts -{ - public interface IServiceLogic - { - List? ReadList(ServiceSearchModel? model); - ServiceViewModel? ReadElement(ServiceSearchModel model); - bool Create(ServiceBindingModel model); - bool Update(ServiceBindingModel model); - bool Delete(ServiceBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/BusinessLogicsContracts/IStaffLogic.cs b/DeviceContracts/BusinessLogicsContracts/IStaffLogic.cs deleted file mode 100644 index 6720c5b..0000000 --- a/DeviceContracts/BusinessLogicsContracts/IStaffLogic.cs +++ /dev/null @@ -1,14 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.BusinessLogicsContracts -{ - public interface IStaffLogic - { - List? ReadList(StaffSearchModel? model); - StaffViewModel? ReadElement(StaffSearchModel model); - bool Create(StaffBindingModel model); - bool Update(StaffBindingModel model); - bool Delete(StaffBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/DeviceContracts.csproj b/DeviceContracts/DeviceContracts.csproj deleted file mode 100644 index b4186cc..0000000 --- a/DeviceContracts/DeviceContracts.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - diff --git a/DeviceContracts/SearchModels/CabinetSearchModel.cs b/DeviceContracts/SearchModels/CabinetSearchModel.cs deleted file mode 100644 index 61b812d..0000000 --- a/DeviceContracts/SearchModels/CabinetSearchModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace DeviceContracts.SearchModels -{ - public class CabinetSearchModel - { - public int? Id { get; set; } - public string? Room { get; set; } - public int? Building { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/SearchModels/DeviceSearchModel.cs b/DeviceContracts/SearchModels/DeviceSearchModel.cs deleted file mode 100644 index 4e8a21a..0000000 --- a/DeviceContracts/SearchModels/DeviceSearchModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace DeviceContracts.SearchModels -{ - public class DeviceSearchModel - { - public int? Id { get; set; } - public string? Model { get; set; } - public string? SerialNumber { get; set; } - public DateOnly? ProductionDate { get; set; } - public int? WarrantyPeriod { get; set; } - public bool? Condition { get; set; } - public int KindId { get; set; } - public int? KitId { get; set; } - - } -} \ No newline at end of file diff --git a/DeviceContracts/SearchModels/KindSearchModel.cs b/DeviceContracts/SearchModels/KindSearchModel.cs deleted file mode 100644 index fa790b4..0000000 --- a/DeviceContracts/SearchModels/KindSearchModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace DeviceContracts.SearchModels -{ - public class KindSearchModel - { - public int? Id { get; set; } - public string? Title { get; set; } - public int? Frequency { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/SearchModels/KitSearchModel.cs b/DeviceContracts/SearchModels/KitSearchModel.cs deleted file mode 100644 index d22ddc3..0000000 --- a/DeviceContracts/SearchModels/KitSearchModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace DeviceContracts.SearchModels -{ - public class KitSearchModel - { - public int? Id { get; set; } - public string? Title { get; set; } - public int? CabinetId { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/SearchModels/ServiceSearchModel.cs b/DeviceContracts/SearchModels/ServiceSearchModel.cs deleted file mode 100644 index 6d702fb..0000000 --- a/DeviceContracts/SearchModels/ServiceSearchModel.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace DeviceContracts.SearchModels -{ - public class ServiceSearchModel - { - public int? Id { get; set; } - public string? Description { get; set; } - public DateOnly? StartDate { get; set; } - public DateOnly? EndDate { get; set; } - public int? DeviceId { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/SearchModels/StaffSearchModel.cs b/DeviceContracts/SearchModels/StaffSearchModel.cs deleted file mode 100644 index 4870df1..0000000 --- a/DeviceContracts/SearchModels/StaffSearchModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using DeviceDataModels.Enums; -namespace DeviceContracts.SearchModels -{ - public class StaffSearchModel - { - public int? Id { get; set; } - public string? FullName { get; set; } - public string? Department { get; set; } - public string? Email { get; set; } - public string? Password { get; set; } - public AccessLevel? AccessLevel { get; } - } -} \ No newline at end of file diff --git a/DeviceContracts/StoragesContracts/ICabinetStorage.cs b/DeviceContracts/StoragesContracts/ICabinetStorage.cs deleted file mode 100644 index ff68016..0000000 --- a/DeviceContracts/StoragesContracts/ICabinetStorage.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.StoragesContracts -{ - public interface ICabinetStorage - { - List GetFullList(); - List GetFilteredList(CabinetSearchModel model); - CabinetViewModel? GetElement(CabinetSearchModel model); - CabinetViewModel? Insert(CabinetBindingModel model); - CabinetViewModel? Update(CabinetBindingModel model); - CabinetViewModel? Delete(CabinetBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/StoragesContracts/IDeviceStorage.cs b/DeviceContracts/StoragesContracts/IDeviceStorage.cs deleted file mode 100644 index 6c00536..0000000 --- a/DeviceContracts/StoragesContracts/IDeviceStorage.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.StoragesContracts -{ - public interface IDeviceStorage - { - List GetFullList(); - List GetFilteredList(DeviceSearchModel model); - DeviceViewModel? GetElement(DeviceSearchModel model); - DeviceViewModel? Insert(DeviceBindingModel model); - DeviceViewModel? Update(DeviceBindingModel model); - DeviceViewModel? Delete(DeviceBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/StoragesContracts/IKindStorage.cs b/DeviceContracts/StoragesContracts/IKindStorage.cs deleted file mode 100644 index ad5c508..0000000 --- a/DeviceContracts/StoragesContracts/IKindStorage.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.StoragesContracts -{ - public interface IKindStorage - { - List GetFullList(); - List GetFilteredList(KindSearchModel model); - KindViewModel? GetElement(KindSearchModel model); - KindViewModel? Insert(KindBindingModel model); - KindViewModel? Update(KindBindingModel model); - KindViewModel? Delete(KindBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/StoragesContracts/IKitStorage.cs b/DeviceContracts/StoragesContracts/IKitStorage.cs deleted file mode 100644 index ede8f6b..0000000 --- a/DeviceContracts/StoragesContracts/IKitStorage.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.StoragesContracts -{ - public interface IKitStorage - { - List GetFullList(); - List GetFilteredList(KitSearchModel model); - KitViewModel? GetElement(KitSearchModel model); - KitViewModel? Insert(KitBindingModel model); - KitViewModel? Update(KitBindingModel model); - KitViewModel? Delete(KitBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/StoragesContracts/IServiceStorage.cs b/DeviceContracts/StoragesContracts/IServiceStorage.cs deleted file mode 100644 index 5a240e7..0000000 --- a/DeviceContracts/StoragesContracts/IServiceStorage.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.StoragesContracts -{ - public interface IServiceStorage - { - List GetFullList(); - List GetFilteredList(ServiceSearchModel model); - ServiceViewModel? GetElement(ServiceSearchModel model); - ServiceViewModel? Insert(ServiceBindingModel model); - ServiceViewModel? Update(ServiceBindingModel model); - ServiceViewModel? Delete(ServiceBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/StoragesContracts/IStaffStorage.cs b/DeviceContracts/StoragesContracts/IStaffStorage.cs deleted file mode 100644 index 056e1e9..0000000 --- a/DeviceContracts/StoragesContracts/IStaffStorage.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.ViewModels; -namespace DeviceContracts.StoragesContracts -{ - public interface IStaffStorage - { - List GetFullList(); - List GetFilteredList(StaffSearchModel model); - StaffViewModel? GetElement(StaffSearchModel model); - StaffViewModel? Insert(StaffBindingModel model); - StaffViewModel? Update(StaffBindingModel model); - StaffViewModel? Delete(StaffBindingModel model); - } -} \ No newline at end of file diff --git a/DeviceContracts/ViewModels/CabinetViewModel.cs b/DeviceContracts/ViewModels/CabinetViewModel.cs deleted file mode 100644 index fa29b3b..0000000 --- a/DeviceContracts/ViewModels/CabinetViewModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel; -namespace DeviceContracts.ViewModels -{ - public class CabinetViewModel : ICabinetModel - { - public int Id { get; set; } - [DisplayName("Кабинет")] - public string Room { get; set; } = string.Empty; - [DisplayName("Корпус")] - public int Building { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/ViewModels/DeviceViewModel.cs b/DeviceContracts/ViewModels/DeviceViewModel.cs deleted file mode 100644 index 96af890..0000000 --- a/DeviceContracts/ViewModels/DeviceViewModel.cs +++ /dev/null @@ -1,23 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel; -namespace DeviceContracts.ViewModels -{ - public class DeviceViewModel : IDeviceModel - { - public int Id { get; set; } - [DisplayName("Модель")] - public string? Model { get; set; } = string.Empty; - [DisplayName("Серийный номер")] - public string? SerialNumber { get; set; } = string.Empty; - [DisplayName("Дата изготовления")] - public DateOnly? ProductionDate { get; set; } - [DisplayName("Гарантийный период")] - public int? WarrantyPeriod { get; set; } - [DisplayName("Работоспособность")] - public bool Condition { get; set; } - [DisplayName("Идентификатор вида")] - public int KindId { get; set; } - [DisplayName("Идентификатор комплекта")] - public int? KitId { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/ViewModels/KindViewModel.cs b/DeviceContracts/ViewModels/KindViewModel.cs deleted file mode 100644 index 493feb9..0000000 --- a/DeviceContracts/ViewModels/KindViewModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel; -namespace DeviceContracts.ViewModels -{ - public class KindViewModel : IKindModel - { - public int Id { get; set; } - [DisplayName("Название")] - public string Title { get; set; } = string.Empty; - [DisplayName("Частота обслуживания")] - public int Frequency { get; set; } - [DisplayName("Идентификатор вида")] - public int KindId { get; set; } - [DisplayName("Идентификатор комплекта")] - public int? KitId { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/ViewModels/KitViewModel.cs b/DeviceContracts/ViewModels/KitViewModel.cs deleted file mode 100644 index 58b2d69..0000000 --- a/DeviceContracts/ViewModels/KitViewModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel; -namespace DeviceContracts.ViewModels -{ - public class KitViewModel : IKitModel - { - public int Id { get; set; } - [DisplayName("Название")] - public string Title { get; set; } = string.Empty; - [DisplayName("Идентификатор кабинета")] - public int? CabinetId { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/ViewModels/ServiceViewModel.cs b/DeviceContracts/ViewModels/ServiceViewModel.cs deleted file mode 100644 index 4a1c830..0000000 --- a/DeviceContracts/ViewModels/ServiceViewModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel; -namespace DeviceContracts.ViewModels -{ - public class ServiceViewModel : IServiceModel - { - public int Id { get; set; } - [DisplayName("Описание")] - public string Description { get; set; } = string.Empty; - [DisplayName("Дата начала")] - public DateOnly StartDate { get; set; } - [DisplayName("Дата конца")] - public DateOnly? EndDate { get; set; } - [DisplayName("Идентификатор устройства")] - public int DeviceId { get; set; } - } -} \ No newline at end of file diff --git a/DeviceContracts/ViewModels/StaffViewModel.cs b/DeviceContracts/ViewModels/StaffViewModel.cs deleted file mode 100644 index 48c859c..0000000 --- a/DeviceContracts/ViewModels/StaffViewModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using DeviceDataModels.Enums; -using DeviceDataModels.Models; -using System.ComponentModel; -namespace DeviceContracts.ViewModels -{ - public class StaffViewModel : IStaffModel - { - public int Id { get; set; } - [DisplayName("ФИО")] - public string FullName { get; set; } = string.Empty; - [DisplayName("Отдел")] - public string Department { get; set; } = string.Empty; - [DisplayName("Почта")] - public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; - [DisplayName("Уровень доступа")] - public AccessLevel AccessLevel { get; set; } - public Dictionary Ownership { get; set; } - = new(); - } -} \ No newline at end of file diff --git a/DeviceDataModels/DeviceDataModels.csproj b/DeviceDataModels/DeviceDataModels.csproj deleted file mode 100644 index fa71b7a..0000000 --- a/DeviceDataModels/DeviceDataModels.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net8.0 - enable - enable - - - diff --git a/DeviceDataModels/Enums/AccessLevel.cs b/DeviceDataModels/Enums/AccessLevel.cs deleted file mode 100644 index e39aa51..0000000 --- a/DeviceDataModels/Enums/AccessLevel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace DeviceDataModels.Enums -{ - public enum AccessLevel - { - Сотрудник = 0, - Техник = 1, - Админ = 2 - } -} \ No newline at end of file diff --git a/DeviceDataModels/IId.cs b/DeviceDataModels/IId.cs deleted file mode 100644 index 6d52f8b..0000000 --- a/DeviceDataModels/IId.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace DeviceDataModels -{ - public interface IId - { - int Id { get; } - } -} diff --git a/DeviceDataModels/Models/ICabinetModel.cs b/DeviceDataModels/Models/ICabinetModel.cs deleted file mode 100644 index 85cdf6a..0000000 --- a/DeviceDataModels/Models/ICabinetModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace DeviceDataModels.Models -{ - public interface ICabinetModel : IId - { - string Room { get; } - int Building { get; } - } -} \ No newline at end of file diff --git a/DeviceDataModels/Models/IDeviceModel.cs b/DeviceDataModels/Models/IDeviceModel.cs deleted file mode 100644 index 73eedf3..0000000 --- a/DeviceDataModels/Models/IDeviceModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace DeviceDataModels.Models -{ - public interface IDeviceModel : IId - { - string Model { get; } - string? SerialNumber { get; } - DateOnly? ProductionDate { get; } - int? WarrantyPeriod { get; } - bool Condition { get; } - int KindId { get; } - int? KitId { get; } - } -} \ No newline at end of file diff --git a/DeviceDataModels/Models/IKindModel.cs b/DeviceDataModels/Models/IKindModel.cs deleted file mode 100644 index a468708..0000000 --- a/DeviceDataModels/Models/IKindModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace DeviceDataModels.Models -{ - public interface IKindModel : IId - { - string Title { get; } - int Frequency { get; } - } -} \ No newline at end of file diff --git a/DeviceDataModels/Models/IKitModel.cs b/DeviceDataModels/Models/IKitModel.cs deleted file mode 100644 index 7832772..0000000 --- a/DeviceDataModels/Models/IKitModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace DeviceDataModels.Models -{ - public interface IKitModel : IId - { - string Title { get; } - int? CabinetId { get; } - } -} \ No newline at end of file diff --git a/DeviceDataModels/Models/IServiceModel.cs b/DeviceDataModels/Models/IServiceModel.cs deleted file mode 100644 index 6055ce3..0000000 --- a/DeviceDataModels/Models/IServiceModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DeviceDataModels.Models -{ - public interface IServiceModel : IId - { - string Description { get; } - DateOnly StartDate { get; } - DateOnly? EndDate { get; } - int DeviceId { get; } - } -} \ No newline at end of file diff --git a/DeviceDataModels/Models/IStaffModel.cs b/DeviceDataModels/Models/IStaffModel.cs deleted file mode 100644 index 52509db..0000000 --- a/DeviceDataModels/Models/IStaffModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using DeviceDataModels.Enums; -namespace DeviceDataModels.Models -{ - public interface IStaffModel : IId - { - string FullName { get; } - string Department { get; } - string Email { get; } - string Password { get; } - AccessLevel AccessLevel { get; } - } -} \ No newline at end of file diff --git a/DeviceDatabaseImplement/DeviceDataModels.cs b/DeviceDatabaseImplement/DeviceDataModels.cs deleted file mode 100644 index 44ff898..0000000 --- a/DeviceDatabaseImplement/DeviceDataModels.cs +++ /dev/null @@ -1,30 +0,0 @@ -using DeviceDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; - -namespace DeviceDatabaseImplement -{ - public class DeviceDatabase : DbContext - { - protected override void OnConfiguring( - DbContextOptionsBuilder optionsBuilder) - { - if (optionsBuilder.IsConfigured == false) - { - optionsBuilder.UseSqlServer(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ConfectioneryDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); - } - base.OnConfiguring(optionsBuilder); - } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity() - .HasKey(sc => new { sc.StaffId, sc.KitId }); - } - public virtual DbSet Cabinets { set; get; } - public virtual DbSet Devices { set; get; } - public virtual DbSet Kinds { set; get; } - public virtual DbSet Kits { set; get; } - public virtual DbSet Services { set; get; } - public virtual DbSet Staff { set; get; } - public virtual DbSet Ownership { set; get; } - } -} \ No newline at end of file diff --git a/DeviceDatabaseImplement/DeviceDatabaseImplement.csproj b/DeviceDatabaseImplement/DeviceDatabaseImplement.csproj deleted file mode 100644 index aee7a7a..0000000 --- a/DeviceDatabaseImplement/DeviceDatabaseImplement.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - diff --git a/DeviceDatabaseImplement/Implements/CabinetStorage.cs b/DeviceDatabaseImplement/Implements/CabinetStorage.cs deleted file mode 100644 index 7caf71f..0000000 --- a/DeviceDatabaseImplement/Implements/CabinetStorage.cs +++ /dev/null @@ -1,96 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using DeviceDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; - -namespace DeviceDatabaseImplement.Implements -{ - public class CabinetStorage : ICabinetStorage - { - public List GetFullList() - { - using var context = new DeviceDatabase(); - return context.Cabinets.Select(x => x.GetViewModel).ToList(); - } - - public List GetFilteredList(CabinetSearchModel model) - { - if (string.IsNullOrEmpty(model.Room) && - model.Building == 0) - { - return new(); - } - - using var context = new DeviceDatabase(); - return context.Cabinets - .Where(x => (string.IsNullOrEmpty(model.Room) || - x.Room == model.Room) && (model.Building == 0 || - x.Building == model.Building)) - .Select(x => x.GetViewModel).ToList(); - } - - public CabinetViewModel? GetElement(CabinetSearchModel model) - { - if (string.IsNullOrEmpty(model.Room) && - model.Building == 0) - { - return null; - } - - using var context = new DeviceDatabase(); - return context.Cabinets - .FirstOrDefault(x => (string.IsNullOrEmpty(model.Room) || - x.Room == model.Room) && (model.Building == 0 || - x.Building == model.Building)) - ?.GetViewModel; - } - - public CabinetViewModel? Insert(CabinetBindingModel model) - { - var newCabinet = Cabinet.Create(model); - if (newCabinet == null) - { - return null; - } - - using var context = new DeviceDatabase(); - context.Cabinets.Add(newCabinet); - context.SaveChanges(); - return newCabinet.GetViewModel; - } - - public CabinetViewModel? Update(CabinetBindingModel model) - { - using var context = new DeviceDatabase(); - var cabinet = context.Cabinets - .FirstOrDefault(x => x.Id == model.Id); - - if (cabinet == null) - { - return null; - } - - cabinet.Update(model); - context.SaveChanges(); - return cabinet.GetViewModel; - } - - public CabinetViewModel? Delete(CabinetBindingModel model) - { - using var context = new DeviceDatabase(); - var cabinet = context.Cabinets - .FirstOrDefault(x => x.Id == model.Id); - - if (cabinet != null) - { - context.Cabinets.Remove(cabinet); - context.SaveChanges(); - return cabinet.GetViewModel; - } - - return null; - } - } -} diff --git a/DeviceDatabaseImplement/Implements/DeviceStorage.cs b/DeviceDatabaseImplement/Implements/DeviceStorage.cs deleted file mode 100644 index 3aac99a..0000000 --- a/DeviceDatabaseImplement/Implements/DeviceStorage.cs +++ /dev/null @@ -1,113 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using DeviceDatabaseImplement.Models; - -namespace DeviceDatabaseImplement.Implements -{ - public class DeviceStorage : IDeviceStorage - { - public List GetFullList() - { - using var context = new DeviceDatabase(); - return context.Devices.Select(x => x.GetViewModel).ToList(); - } - - public List GetFilteredList(DeviceSearchModel model) - { - if (string.IsNullOrEmpty(model.Model) && - string.IsNullOrEmpty(model.SerialNumber) && - model.ProductionDate == null && - model.WarrantyPeriod == 0 && - model.Condition == null && - model.KindId == 0 && - model.KitId == 0) - { - return new(); - } - - using var context = new DeviceDatabase(); - return context.Devices - .Where(x => (string.IsNullOrEmpty(model.Model) || x.Model == model.Model) && - (string.IsNullOrEmpty(model.SerialNumber) || x.SerialNumber == model.SerialNumber) && - (model.ProductionDate == null || x.ProductionDate == model.ProductionDate) && - (model.WarrantyPeriod == 0 || x.WarrantyPeriod == model.WarrantyPeriod) && - (model.Condition == null || x.Condition == model.Condition) && - (model.KindId == 0 || x.KindId == model.KindId) && - (model.KitId == 0 || x.KitId == model.KitId)) - .Select(x => x.GetViewModel).ToList(); - } - - public DeviceViewModel? GetElement(DeviceSearchModel model) - { - if (string.IsNullOrEmpty(model.Model) && - string.IsNullOrEmpty(model.SerialNumber) && - model.ProductionDate == null && - model.WarrantyPeriod == 0 && - model.Condition == null && - model.KindId == 0 && - model.KitId == 0) - { - return null; - } - - using var context = new DeviceDatabase(); - return context.Devices - .FirstOrDefault(x => (string.IsNullOrEmpty(model.Model) || x.Model == model.Model) && - (string.IsNullOrEmpty(model.SerialNumber) || x.SerialNumber == model.SerialNumber) && - (model.ProductionDate == null || x.ProductionDate == model.ProductionDate) && - (model.WarrantyPeriod == 0 || x.WarrantyPeriod == model.WarrantyPeriod) && - (model.Condition == null || x.Condition == model.Condition) && - (model.KindId == 0 || x.KindId == model.KindId) && - (model.KitId == 0 || x.KitId == model.KitId)) - ?.GetViewModel; - } - - public DeviceViewModel? Insert(DeviceBindingModel model) - { - var newDevice = Device.Create(model); - if (newDevice == null) - { - return null; - } - - using var context = new DeviceDatabase(); - context.Devices.Add(newDevice); - context.SaveChanges(); - return newDevice.GetViewModel; - } - - public DeviceViewModel? Update(DeviceBindingModel model) - { - using var context = new DeviceDatabase(); - var device = context.Devices - .FirstOrDefault(x => x.Id == model.Id); - - if (device == null) - { - return null; - } - - device.Update(model); - context.SaveChanges(); - return device.GetViewModel; - } - - public DeviceViewModel? Delete(DeviceBindingModel model) - { - using var context = new DeviceDatabase(); - var device = context.Devices - .FirstOrDefault(x => x.Id == model.Id); - - if (device != null) - { - context.Devices.Remove(device); - context.SaveChanges(); - return device.GetViewModel; - } - - return null; - } - } -} diff --git a/DeviceDatabaseImplement/Implements/KindStorage.cs b/DeviceDatabaseImplement/Implements/KindStorage.cs deleted file mode 100644 index 7355c3d..0000000 --- a/DeviceDatabaseImplement/Implements/KindStorage.cs +++ /dev/null @@ -1,100 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using DeviceDatabaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DeviceDatabaseImplement.Implements -{ - public class KindStorage : IKindStorage - { - public List GetFullList() - { - using var context = new DeviceDatabase(); - return context.Kinds.Select(x => x.GetViewModel).ToList(); - } - - public List GetFilteredList(KindSearchModel model) - { - if (string.IsNullOrEmpty(model.Title) && - model.Frequency == 0) - { - return new(); - } - - using var context = new DeviceDatabase(); - return context.Kinds - .Where(x => (string.IsNullOrEmpty(model.Title) || - x.Title == model.Title) && (model.Frequency == 0 || - x.Frequency == model.Frequency)) - .Select(x => x.GetViewModel).ToList(); - } - - public KindViewModel? GetElement(KindSearchModel model) - { - if (string.IsNullOrEmpty(model.Title) && - model.Frequency == 0) - { - return null; - } - - using var context = new DeviceDatabase(); - return context.Kinds - .FirstOrDefault(x => (string.IsNullOrEmpty(model.Title) || - x.Title == model.Title) && (model.Frequency == 0 || - x.Frequency == model.Frequency)) - ?.GetViewModel; - } - - public KindViewModel? Insert(KindBindingModel model) - { - var newKind = Kind.Create(model); - if (newKind == null) - { - return null; - } - - using var context = new DeviceDatabase(); - context.Kinds.Add(newKind); - context.SaveChanges(); - return newKind.GetViewModel; - } - - public KindViewModel? Update(KindBindingModel model) - { - using var context = new DeviceDatabase(); - var kind = context.Kinds - .FirstOrDefault(x => x.Id == model.Id); - - if (kind == null) - { - return null; - } - - kind.Update(model); - context.SaveChanges(); - return kind.GetViewModel; - } - - public KindViewModel? Delete(KindBindingModel model) - { - using var context = new DeviceDatabase(); - var kind = context.Kinds - .FirstOrDefault(x => x.Id == model.Id); - - if (kind != null) - { - context.Kinds.Remove(kind); - context.SaveChanges(); - return kind.GetViewModel; - } - - return null; - } - } -} diff --git a/DeviceDatabaseImplement/Implements/KitStorage.cs b/DeviceDatabaseImplement/Implements/KitStorage.cs deleted file mode 100644 index 3bed79a..0000000 --- a/DeviceDatabaseImplement/Implements/KitStorage.cs +++ /dev/null @@ -1,100 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using DeviceDatabaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DeviceDatabaseImplement.Implements -{ - public class KitStorage : IKitStorage - { - public List GetFullList() - { - using var context = new DeviceDatabase(); - return context.Kits.Select(x => x.GetViewModel).ToList(); - } - - public List GetFilteredList(KitSearchModel model) - { - if (string.IsNullOrEmpty(model.Title) && - model.CabinetId == 0) - { - return new(); - } - - using var context = new DeviceDatabase(); - return context.Kits - .Where(x => (string.IsNullOrEmpty(model.Title) || - x.Title == model.Title) && (model.CabinetId == 0 || - x.CabinetId == model.CabinetId)) - .Select(x => x.GetViewModel).ToList(); - } - - public KitViewModel? GetElement(KitSearchModel model) - { - if (string.IsNullOrEmpty(model.Title) && - model.CabinetId == 0) - { - return null; - } - - using var context = new DeviceDatabase(); - return context.Kits - .FirstOrDefault(x => (string.IsNullOrEmpty(model.Title) || - x.Title == model.Title) && (model.CabinetId == 0 || - x.CabinetId == model.CabinetId)) - ?.GetViewModel; - } - - public KitViewModel? Insert(KitBindingModel model) - { - var newKit = Kit.Create(model); - if (newKit == null) - { - return null; - } - - using var context = new DeviceDatabase(); - context.Kits.Add(newKit); - context.SaveChanges(); - return newKit.GetViewModel; - } - - public KitViewModel? Update(KitBindingModel model) - { - using var context = new DeviceDatabase(); - var kit = context.Kits - .FirstOrDefault(x => x.Id == model.Id); - - if (kit == null) - { - return null; - } - - kit.Update(model); - context.SaveChanges(); - return kit.GetViewModel; - } - - public KitViewModel? Delete(KitBindingModel model) - { - using var context = new DeviceDatabase(); - var kit = context.Kits - .FirstOrDefault(x => x.Id == model.Id); - - if (kit != null) - { - context.Kits.Remove(kit); - context.SaveChanges(); - return kit.GetViewModel; - } - - return null; - } - } -} diff --git a/DeviceDatabaseImplement/Implements/ServiceStorage.cs b/DeviceDatabaseImplement/Implements/ServiceStorage.cs deleted file mode 100644 index 26f146f..0000000 --- a/DeviceDatabaseImplement/Implements/ServiceStorage.cs +++ /dev/null @@ -1,108 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using DeviceDatabaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DeviceDatabaseImplement.Implements -{ - public class ServiceStorage : IServiceStorage - { - public List GetFullList() - { - using var context = new DeviceDatabase(); - return context.Services.Select(x => x.GetViewModel).ToList(); - } - - public List GetFilteredList(ServiceSearchModel model) - { - if (string.IsNullOrEmpty(model.Description) && - model.DeviceId == 0 && - model.StartDate == null && - model.EndDate == null) - { - return new(); - } - - using var context = new DeviceDatabase(); - return context.Services - .Where(x => (string.IsNullOrEmpty(model.Description) || - x.Description == model.Description) && (model.DeviceId == 0 || - x.DeviceId == model.DeviceId) && (model.StartDate == null || - x.StartDate >= model.StartDate) && (model.EndDate == null || - x.EndDate <= model.EndDate)) - .Select(x => x.GetViewModel).ToList(); - } - - public ServiceViewModel? GetElement(ServiceSearchModel model) - { - if (string.IsNullOrEmpty(model.Description) && - model.DeviceId == 0 && - model.StartDate == null && - model.EndDate == null) - { - return null; - } - - using var context = new DeviceDatabase(); - return context.Services - .FirstOrDefault(x => (string.IsNullOrEmpty(model.Description) || - x.Description == model.Description) && (model.DeviceId == 0 || - x.DeviceId == model.DeviceId) && (model.StartDate == null || - x.StartDate >= model.StartDate) && (model.EndDate == null || - x.EndDate <= model.EndDate)) - ?.GetViewModel; - } - - public ServiceViewModel? Insert(ServiceBindingModel model) - { - var newService = Service.Create(model); - if (newService == null) - { - return null; - } - - using var context = new DeviceDatabase(); - context.Services.Add(newService); - context.SaveChanges(); - return newService.GetViewModel; - } - - public ServiceViewModel? Update(ServiceBindingModel model) - { - using var context = new DeviceDatabase(); - var service = context.Services - .FirstOrDefault(x => x.Id == model.Id); - - if (service == null) - { - return null; - } - - service.Update(model); - context.SaveChanges(); - return service.GetViewModel; - } - - public ServiceViewModel? Delete(ServiceBindingModel model) - { - using var context = new DeviceDatabase(); - var service = context.Services - .FirstOrDefault(x => x.Id == model.Id); - - if (service != null) - { - context.Services.Remove(service); - context.SaveChanges(); - return service.GetViewModel; - } - - return null; - } - } -} diff --git a/DeviceDatabaseImplement/Implements/StaffStorage.cs b/DeviceDatabaseImplement/Implements/StaffStorage.cs deleted file mode 100644 index d24926a..0000000 --- a/DeviceDatabaseImplement/Implements/StaffStorage.cs +++ /dev/null @@ -1,108 +0,0 @@ -using DeviceContracts.BindingModels; -using DeviceContracts.SearchModels; -using DeviceContracts.StoragesContracts; -using DeviceContracts.ViewModels; -using DeviceDatabaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DeviceDatabaseImplement.Implements -{ - public class StaffStorage : IStaffStorage - { - public List GetFullList() - { - using var context = new DeviceDatabase(); - return context.Staff.Select(x => x.GetViewModel).ToList(); - } - - public List GetFilteredList(StaffSearchModel model) - { - if (string.IsNullOrEmpty(model.FullName) && - string.IsNullOrEmpty(model.Department) && - string.IsNullOrEmpty(model.Email) && - model.AccessLevel == 0) - { - return new(); - } - - using var context = new DeviceDatabase(); - return context.Staff - .Where(x => (string.IsNullOrEmpty(model.FullName) || - x.FullName == model.FullName) && (string.IsNullOrEmpty(model.Department) || - x.Department == model.Department) && (string.IsNullOrEmpty(model.Email) || - x.Email == model.Email) && (model.AccessLevel == 0 || - x.AccessLevel == model.AccessLevel)) - .Select(x => x.GetViewModel).ToList(); - } - - public StaffViewModel? GetElement(StaffSearchModel model) - { - if (string.IsNullOrEmpty(model.FullName) && - string.IsNullOrEmpty(model.Department) && - string.IsNullOrEmpty(model.Email) && - model.AccessLevel == 0) - { - return null; - } - - using var context = new DeviceDatabase(); - return context.Staff - .FirstOrDefault(x => (string.IsNullOrEmpty(model.FullName) || - x.FullName == model.FullName) && (string.IsNullOrEmpty(model.Department) || - x.Department == model.Department) && (string.IsNullOrEmpty(model.Email) || - x.Email == model.Email) && (model.AccessLevel == 0 || - x.AccessLevel == model.AccessLevel)) - ?.GetViewModel; - } - - public StaffViewModel? Insert(StaffBindingModel model) - { - var newStaffMember = Staff.Create(model); - if (newStaffMember == null) - { - return null; - } - - using var context = new DeviceDatabase(); - context.Staff.Add(newStaffMember); - context.SaveChanges(); - return newStaffMember.GetViewModel; - } - - public StaffViewModel? Update(StaffBindingModel model) - { - using var context = new DeviceDatabase(); - var staffMember = context.Staff - .FirstOrDefault(x => x.Id == model.Id); - - if (staffMember == null) - { - return null; - } - - staffMember.Update(model); - context.SaveChanges(); - return staffMember.GetViewModel; - } - - public StaffViewModel? Delete(StaffBindingModel model) - { - using var context = new DeviceDatabase(); - var staffMember = context.Staff - .FirstOrDefault(x => x.Id == model.Id); - - if (staffMember != null) - { - context.Staff.Remove(staffMember); - context.SaveChanges(); - return staffMember.GetViewModel; - } - - return null; - } - } -} diff --git a/DeviceDatabaseImplement/Migrations/20240520003028_InitialCreate.Designer.cs b/DeviceDatabaseImplement/Migrations/20240520003028_InitialCreate.Designer.cs deleted file mode 100644 index bc54a24..0000000 --- a/DeviceDatabaseImplement/Migrations/20240520003028_InitialCreate.Designer.cs +++ /dev/null @@ -1,300 +0,0 @@ -// -using System; -using DeviceDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DeviceDatabaseImplement.Migrations -{ - [DbContext(typeof(DeviceDatabase))] - [Migration("20240520003027_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Cabinet", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Building") - .HasColumnType("int"); - - b.Property("CabinetId") - .HasColumnType("int"); - - b.Property("Room") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("CabinetId"); - - b.ToTable("Cabinets"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Device", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Condition") - .HasColumnType("bit"); - - b.Property("KindId") - .HasColumnType("int"); - - b.Property("KitId") - .HasColumnType("int"); - - b.Property("Model") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ProductionDate") - .HasColumnType("date"); - - b.Property("SerialNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("WarrantyPeriod") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("KindId"); - - b.HasIndex("KitId"); - - b.ToTable("Devices"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Kind", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Frequency") - .HasColumnType("int"); - - b.Property("Title") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Kinds"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Kit", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CabinetId") - .HasColumnType("int"); - - b.Property("Title") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("CabinetId"); - - b.ToTable("Kits"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Ownership", b => - { - b.Property("StaffId") - .HasColumnType("int"); - - b.Property("KitId") - .HasColumnType("int"); - - b.HasKey("StaffId", "KitId"); - - b.HasIndex("KitId"); - - b.ToTable("Ownership"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Service", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Description") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("DeviceId") - .HasColumnType("int"); - - b.Property("EndDate") - .HasColumnType("date"); - - b.Property("ServiceId") - .HasColumnType("int"); - - b.Property("StartDate") - .HasColumnType("date"); - - b.HasKey("Id"); - - b.HasIndex("ServiceId"); - - b.ToTable("Services"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Staff", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AccessLevel") - .HasColumnType("int"); - - b.Property("Department") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("FullName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Staff"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Cabinet", b => - { - b.HasOne("DeviceDatabaseImplement.Models.Cabinet", null) - .WithMany("Cabinets") - .HasForeignKey("CabinetId"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Device", b => - { - b.HasOne("DeviceDatabaseImplement.Models.Kind", "Kind") - .WithMany("Devices") - .HasForeignKey("KindId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DeviceDatabaseImplement.Models.Kit", "Kit") - .WithMany("Devices") - .HasForeignKey("KitId"); - - b.Navigation("Kind"); - - b.Navigation("Kit"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Kit", b => - { - b.HasOne("DeviceDatabaseImplement.Models.Cabinet", "Cabinet") - .WithMany() - .HasForeignKey("CabinetId"); - - b.Navigation("Cabinet"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Ownership", b => - { - b.HasOne("DeviceDatabaseImplement.Models.Kit", "Kits") - .WithMany("Ownership") - .HasForeignKey("KitId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DeviceDatabaseImplement.Models.Staff", "Staff") - .WithMany("Ownership") - .HasForeignKey("StaffId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Kits"); - - b.Navigation("Staff"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Service", b => - { - b.HasOne("DeviceDatabaseImplement.Models.Service", null) - .WithMany("Services") - .HasForeignKey("ServiceId"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Cabinet", b => - { - b.Navigation("Cabinets"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Kind", b => - { - b.Navigation("Devices"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Kit", b => - { - b.Navigation("Devices"); - - b.Navigation("Ownership"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Service", b => - { - b.Navigation("Services"); - }); - - modelBuilder.Entity("DeviceDatabaseImplement.Models.Staff", b => - { - b.Navigation("Ownership"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DeviceDatabaseImplement/Migrations/20240520003028_InitialCreate.cs b/DeviceDatabaseImplement/Migrations/20240520003028_InitialCreate.cs deleted file mode 100644 index fbd715e..0000000 --- a/DeviceDatabaseImplement/Migrations/20240520003028_InitialCreate.cs +++ /dev/null @@ -1,218 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DeviceDatabaseImplement.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Cabinets", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Room = table.Column(type: "nvarchar(max)", nullable: false), - Building = table.Column(type: "int", nullable: false), - }, - constraints: table => - { - table.PrimaryKey("Cabinets_PKey", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Kits", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Title = table.Column(type: "nvarchar(max)", nullable: false), - Cabinet_Id = table.Column(type: "int", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("Kits_PKey", x => x.Id); - table.ForeignKey( - name: "Kits_Cabinet_Id_FKey", - column: x => x.Cabinet_Id, - principalTable: "Cabinets", - principalColumn: "Id", - onDelete: ReferentialAction.SetNull, - onUpdate: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Kinds", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Title = table.Column(type: "nvarchar(max)", nullable: false), - Frequency = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("Kinds_PKey", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Devices", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Model = table.Column(type: "nvarchar(max)", nullable: false), - Serial_Number = table.Column(type: "nvarchar(max)", nullable: true), - Production_Date = table.Column(type: "date", nullable: true), - Warranty_Period = table.Column(type: "int", nullable: true), - Condition = table.Column(type: "bit", nullable: false), - Kind_Id = table.Column(type: "int", nullable: false), - Kit_Id = table.Column(type: "int", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("Devices_Pkey", x => x.Id); - table.ForeignKey( - name: "Devices_Kind_Id_FKey", - column: x => x.Kind_Id, - principalTable: "Kinds", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict, - onUpdate: ReferentialAction.Cascade); - table.ForeignKey( - name: "Devices_Kit_Id_FKey", - column: x => x.Kit_Id, - principalTable: "Kits", - principalColumn: "Id", - onDelete: ReferentialAction.SetNull, - onUpdate: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Services", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Description = table.Column(type: "nvarchar(max)", nullable: false), - Start_Date = table.Column(type: "date", nullable: false), - End_Date = table.Column(type: "date", nullable: true), - Device_Id = table.Column(type: "int", nullable: false), - }, - constraints: table => - { - table.PrimaryKey("Services_PKey", x => x.Id); - table.ForeignKey( - name: "Services_Device_Id_FKey", - column: x => x.Device_Id, - principalTable: "Devices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade, - onUpdate: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Staff", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Full_Name = table.Column(type: "nvarchar(max)", nullable: false), - Department = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false), - Access_Level = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("Staff_PKey", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Ownership", - columns: table => new - { - Kit_Id = table.Column(type: "int", nullable: false), - Staff_Id = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Ownership", x => new { x.Staff_Id, x.Kit_Id }); - table.ForeignKey( - name: "Ownership_Kit_Id_FKey", - column: x => x.Kit_Id, - principalTable: "Kits", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade, - onUpdate: ReferentialAction.Cascade); - table.ForeignKey( - name: "Ownership_Staff_Id_FKey", - column: x => x.Staff_Id, - principalTable: "Staff", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade, - onUpdate: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Devices_Kind_Id", - table: "Devices", - column: "Kind_Id"); - - migrationBuilder.CreateIndex( - name: "IX_Devices_Kit_Id", - table: "Devices", - column: "Kit_Id"); - - migrationBuilder.CreateIndex( - name: "IX_Kits_Cabinet_Id", - table: "Kits", - column: "Cabinet_Id"); - - migrationBuilder.CreateIndex( - name: "IX_Ownership_Kit_Id", - table: "Ownership", - column: "Kit_Id"); - - migrationBuilder.CreateIndex( - name: "IX_Ownership_Staff_Id", - table: "Ownership", - column: "Staff_Id"); - - migrationBuilder.CreateIndex( - name: "IX_Services_Device_Id", - table: "Services", - column: "Device_Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Devices"); - - migrationBuilder.DropTable( - name: "Ownership"); - - migrationBuilder.DropTable( - name: "Services"); - - migrationBuilder.DropTable( - name: "Kinds"); - - migrationBuilder.DropTable( - name: "Kits"); - - migrationBuilder.DropTable( - name: "Staff"); - - migrationBuilder.DropTable( - name: "Cabinets"); - } - } -} diff --git a/DeviceDatabaseImplement/Models/Cabinet.cs b/DeviceDatabaseImplement/Models/Cabinet.cs deleted file mode 100644 index b8e638c..0000000 --- a/DeviceDatabaseImplement/Models/Cabinet.cs +++ /dev/null @@ -1,42 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using DeviceContracts.BindingModels; -using DeviceContracts.ViewModels; - -namespace DeviceDatabaseImplement.Models -{ - public class Cabinet : ICabinetModel - { - public int Id { get; set; } - [Required] - public string Room { get; set; } = string.Empty; - [Required] - public int Building { get; set; } - public static Cabinet? Create(CabinetBindingModel model) - { - if (model == null) - return null; - return new Cabinet - { - Id = model.Id, - Room = model.Room, - Building = model.Building, - }; - } - public void Update(CabinetBindingModel model) - { - if (model == null) - return; - Id = model.Id; - Room = model.Room; - Building = model.Building; - } - public CabinetViewModel GetViewModel => new() - { - Id = Id, - Room = Room, - Building = Building, - }; - } -} \ No newline at end of file diff --git a/DeviceDatabaseImplement/Models/Device.cs b/DeviceDatabaseImplement/Models/Device.cs deleted file mode 100644 index 602f34a..0000000 --- a/DeviceDatabaseImplement/Models/Device.cs +++ /dev/null @@ -1,66 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using DeviceContracts.BindingModels; -using DeviceContracts.ViewModels; -using System.ComponentModel; - -namespace DeviceDatabaseImplement.Models -{ - public class Device : IDeviceModel - { - public int Id { get; set; } - [Required] - public string Model { get; set; } = string.Empty; - public string? SerialNumber { get; set; } - public DateOnly? ProductionDate { get; set; } - public int? WarrantyPeriod { get; set; } - public bool Condition { get; set; } - [ForeignKey("Kind")] - public int KindId { get; set; } - public Kind? Kind { get; set; } - [ForeignKey("Kit")] - public int? KitId { get; set; } - public Kit? Kit { get; set; } - public static Device? Create(DeviceBindingModel model) - { - if (model == null) - return null; - return new Device - { - Id = model.Id, - Model = model.Model, - SerialNumber = model.SerialNumber, - ProductionDate = model.ProductionDate, - WarrantyPeriod = model.WarrantyPeriod, - Condition = model.Condition, - KindId = model.KindId, - KitId = model.KitId, - }; - } - public void Update(DeviceBindingModel model) - { - if (model == null) - return; - Id = model.Id; - Model = model.Model; - SerialNumber = model.SerialNumber; - ProductionDate = model.ProductionDate; - WarrantyPeriod = model.WarrantyPeriod; - Condition = model.Condition; - KindId = model.KindId; - KitId = model.KitId; - } - public DeviceViewModel GetViewModel => new() - { - Id = Id, - Model = Model, - SerialNumber = SerialNumber, - ProductionDate = ProductionDate, - WarrantyPeriod = WarrantyPeriod, - Condition = Condition, - KindId = KindId, - KitId = KitId, - }; - } -} \ No newline at end of file diff --git a/DeviceDatabaseImplement/Models/Kind.cs b/DeviceDatabaseImplement/Models/Kind.cs deleted file mode 100644 index c0ee6b2..0000000 --- a/DeviceDatabaseImplement/Models/Kind.cs +++ /dev/null @@ -1,42 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using DeviceContracts.BindingModels; -using DeviceContracts.ViewModels; - -namespace DeviceDatabaseImplement.Models -{ - public class Kind : IKindModel - { - public int Id { get; set; } - [Required] - public string Title { get; set; } = string.Empty; - [Required] - public int Frequency { get; set; } - public static Kind? Create(KindBindingModel model) - { - if (model == null) - return null; - return new Kind - { - Id = model.Id, - Title = model.Title, - Frequency = model.Frequency, - }; - } - public void Update(KindBindingModel model) - { - if (model == null) - return; - Id = model.Id; - Title = model.Title; - Frequency = model.Frequency; - } - public KindViewModel GetViewModel => new() - { - Id = Id, - Title = Title, - Frequency = Frequency, - }; - } -} \ No newline at end of file diff --git a/DeviceDatabaseImplement/Models/Kit.cs b/DeviceDatabaseImplement/Models/Kit.cs deleted file mode 100644 index 042c1ef..0000000 --- a/DeviceDatabaseImplement/Models/Kit.cs +++ /dev/null @@ -1,43 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using DeviceContracts.BindingModels; -using DeviceContracts.ViewModels; - -namespace DeviceDatabaseImplement.Models -{ - public class Kit : IKitModel - { - public int Id { get; set; } - [Required] - public string Title { get; set; } = string.Empty; - [ForeignKey("Cabinet")] - public int? CabinetId { get; set; } - public Cabinet? Cabinet { get; set; } - public static Kit? Create(KitBindingModel model) - { - if (model == null) - return null; - return new Kit - { - Id = model.Id, - Title = model.Title, - CabinetId = model.CabinetId, - }; - } - public void Update(KitBindingModel model) - { - if (model == null) - return; - Id = model.Id; - Title = model.Title; - CabinetId = model.CabinetId; - } - public KitViewModel GetViewModel => new() - { - Id = Id, - Title = Title, - CabinetId = CabinetId, - }; - } -} \ No newline at end of file diff --git a/DeviceDatabaseImplement/Models/Ownership.cs b/DeviceDatabaseImplement/Models/Ownership.cs deleted file mode 100644 index 05600d5..0000000 --- a/DeviceDatabaseImplement/Models/Ownership.cs +++ /dev/null @@ -1,18 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using DeviceContracts.BindingModels; -using DeviceContracts.ViewModels; - -namespace DeviceDatabaseImplement.Models -{ - public class Ownership - { - [ForeignKey("Kit")] - public int KitId { get; set; } - public Kit Kit { get; set; } = null!; - [ForeignKey("Staff")] - public int StaffId { get; set; } - public Staff Staff { get; set; } = null!; - } -} diff --git a/DeviceDatabaseImplement/Models/Service.cs b/DeviceDatabaseImplement/Models/Service.cs deleted file mode 100644 index 51c9b6c..0000000 --- a/DeviceDatabaseImplement/Models/Service.cs +++ /dev/null @@ -1,52 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using DeviceContracts.BindingModels; -using DeviceContracts.ViewModels; - -namespace DeviceDatabaseImplement.Models -{ - public class Service : IServiceModel - { - public int Id { get; set; } - [Required] - public string Description { get; set; } = string.Empty; - [Required] - public DateOnly StartDate { get; set; } - public DateOnly? EndDate { get; set; } - [ForeignKey("Device")] - public int DeviceId { get; set; } - public Device? Device { get; set; } - public static Service? Create(ServiceBindingModel model) - { - if (model == null) - return null; - return new Service - { - Id = model.Id, - Description = model.Description, - StartDate = model.StartDate, - EndDate = model.EndDate, - DeviceId = model.DeviceId, - }; - } - public void Update(ServiceBindingModel model) - { - if (model == null) - return; - Id = model.Id; - Description = model.Description; - StartDate = model.StartDate; - EndDate = model.EndDate; - DeviceId = model.DeviceId; - } - public ServiceViewModel GetViewModel => new() - { - Id = Id, - Description = Description, - StartDate = StartDate, - EndDate = EndDate, - DeviceId = DeviceId, - }; - } -} \ No newline at end of file diff --git a/DeviceDatabaseImplement/Models/Staff.cs b/DeviceDatabaseImplement/Models/Staff.cs deleted file mode 100644 index 7f3ba8f..0000000 --- a/DeviceDatabaseImplement/Models/Staff.cs +++ /dev/null @@ -1,58 +0,0 @@ -using DeviceDataModels.Models; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using DeviceContracts.BindingModels; -using DeviceContracts.ViewModels; -using DeviceDataModels.Enums; - -namespace DeviceDatabaseImplement.Models -{ - public class Staff : IStaffModel - { - public int Id { get; set; } - [Required] - public string FullName { get; set; } = string.Empty; - [Required] - public string Department { get; set; } = string.Empty; - [Required] - public string Email { get; set; } = string.Empty; - [Required] - public string Password { get; set; } = string.Empty; - [Required] - public AccessLevel AccessLevel { get; set; } - public static Staff? Create(StaffBindingModel model) - { - if (model == null) - return null; - return new Staff - { - Id = model.Id, - FullName = model.FullName, - Department = model.Department, - Email = model.Email, - Password = model.Password, - AccessLevel = model.AccessLevel, - }; - } - public void Update(StaffBindingModel model) - { - if (model == null) - return; - Id = model.Id; - FullName = model.FullName; - Department = model.Department; - Email = model.Email; - Password = model.Password; - AccessLevel = model.AccessLevel; - } - public StaffViewModel GetViewModel => new() - { - Id = Id, - FullName = FullName, - Department = Department, - Email = Email, - Password = Password, - AccessLevel = AccessLevel, - }; - } -} \ No newline at end of file