подчистил

This commit is contained in:
DeerElk 2024-05-29 00:58:18 +04:00
parent 9097ccb12d
commit 97c0475168
70 changed files with 54 additions and 3047 deletions

View File

@ -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

View File

@ -13,11 +13,5 @@
<PackageReference Include="Renci.SshNet.Async" Version="1.4.0" />
<PackageReference Include="SSH.NET" Version="2024.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DeviceBusinessLogic\DeviceBusinessLogic.csproj" />
<ProjectReference Include="..\DeviceDatabaseImplement\DeviceDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,4 @@
using Microsoft.Data.SqlClient;
using Npgsql;
using Npgsql;
using System;
using System.Collections.Generic;
using System.ComponentModel;

View File

@ -1,5 +1,4 @@
using Microsoft.Data.SqlClient;
using Npgsql;
using Npgsql;
using NpgsqlTypes;
using Renci.SshNet;
using System;

View File

@ -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();
}
}
}
}

View File

@ -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<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddTransient<ICabinetStorage, CabinetStorage>();
services.AddTransient<IDeviceStorage, DeviceStorage>();
services.AddTransient<IKindStorage, KindStorage>();
services.AddTransient<IKitStorage, KitStorage>();
services.AddTransient<IServiceStorage, ServiceStorage>();
services.AddTransient<IStaffStorage, StaffStorage>();
services.AddTransient<ICabinetLogic, CabinetLogic>();
services.AddTransient<IDeviceLogic, DeviceLogic>();
services.AddTransient<IKindLogic, KindLogic>();
services.AddTransient<IKitLogic, KitLogic>();
services.AddTransient<IServiceLogic, ServiceLogic>();
services.AddTransient<IStaffLogic, StaffLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormCabinets>();
services.AddTransient<FormDevices>();
services.AddTransient<FormKinds>();
services.AddTransient<FormKits>();
services.AddTransient<FormServices>();
services.AddTransient<FormStaff>();
services.AddTransient<FormOwnership>();
}
Application.Run(new FormMain());
}
}
}

View File

@ -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<CabinetLogic> 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<CabinetViewModel>? 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,
});
}
}
}

View File

@ -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<DeviceLogic> 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<DeviceViewModel>? 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,
});
}
}
}

View File

@ -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<KindLogic> 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<KindViewModel>? 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,
});
}
}
}

View File

@ -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<KitLogic> 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<KitViewModel>? 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,
});
}
}
}

View File

@ -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<ServiceLogic> 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<ServiceViewModel>? 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,
});
}
}
}

View File

@ -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<StaffLogic> 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<StaffViewModel>? 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,
});
}
}
}

View File

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

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<int, IKitModel> Ownership { get; set; }
= new();
}
}

View File

@ -1,14 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.BusinessLogicsContracts
{
public interface ICabinetLogic
{
List<CabinetViewModel>? ReadList(CabinetSearchModel? model);
CabinetViewModel? ReadElement(CabinetSearchModel model);
bool Create(CabinetBindingModel model);
bool Update(CabinetBindingModel model);
bool Delete(CabinetBindingModel model);
}
}

View File

@ -1,14 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.BusinessLogicsContracts
{
public interface IDeviceLogic
{
List<DeviceViewModel>? ReadList(DeviceSearchModel? model);
DeviceViewModel? ReadElement(DeviceSearchModel model);
bool Create(DeviceBindingModel model);
bool Update(DeviceBindingModel model);
bool Delete(DeviceBindingModel model);
}
}

View File

@ -1,14 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.BusinessLogicsContracts
{
public interface IKindLogic
{
List<KindViewModel>? ReadList(KindSearchModel? model);
KindViewModel? ReadElement(KindSearchModel model);
bool Create(KindBindingModel model);
bool Update(KindBindingModel model);
bool Delete(KindBindingModel model);
}
}

View File

@ -1,14 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.BusinessLogicsContracts
{
public interface IKitLogic
{
List<KitViewModel>? ReadList(KitSearchModel? model);
KitViewModel? ReadElement(KitSearchModel model);
bool Create(KitBindingModel model);
bool Update(KitBindingModel model);
bool Delete(KitBindingModel model);
}
}

View File

@ -1,14 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.BusinessLogicsContracts
{
public interface IServiceLogic
{
List<ServiceViewModel>? ReadList(ServiceSearchModel? model);
ServiceViewModel? ReadElement(ServiceSearchModel model);
bool Create(ServiceBindingModel model);
bool Update(ServiceBindingModel model);
bool Delete(ServiceBindingModel model);
}
}

View File

@ -1,14 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.BusinessLogicsContracts
{
public interface IStaffLogic
{
List<StaffViewModel>? ReadList(StaffSearchModel? model);
StaffViewModel? ReadElement(StaffSearchModel model);
bool Create(StaffBindingModel model);
bool Update(StaffBindingModel model);
bool Delete(StaffBindingModel model);
}
}

View File

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

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -1,15 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.StoragesContracts
{
public interface ICabinetStorage
{
List<CabinetViewModel> GetFullList();
List<CabinetViewModel> GetFilteredList(CabinetSearchModel model);
CabinetViewModel? GetElement(CabinetSearchModel model);
CabinetViewModel? Insert(CabinetBindingModel model);
CabinetViewModel? Update(CabinetBindingModel model);
CabinetViewModel? Delete(CabinetBindingModel model);
}
}

View File

@ -1,15 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.StoragesContracts
{
public interface IDeviceStorage
{
List<DeviceViewModel> GetFullList();
List<DeviceViewModel> GetFilteredList(DeviceSearchModel model);
DeviceViewModel? GetElement(DeviceSearchModel model);
DeviceViewModel? Insert(DeviceBindingModel model);
DeviceViewModel? Update(DeviceBindingModel model);
DeviceViewModel? Delete(DeviceBindingModel model);
}
}

View File

@ -1,15 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.StoragesContracts
{
public interface IKindStorage
{
List<KindViewModel> GetFullList();
List<KindViewModel> GetFilteredList(KindSearchModel model);
KindViewModel? GetElement(KindSearchModel model);
KindViewModel? Insert(KindBindingModel model);
KindViewModel? Update(KindBindingModel model);
KindViewModel? Delete(KindBindingModel model);
}
}

View File

@ -1,15 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.StoragesContracts
{
public interface IKitStorage
{
List<KitViewModel> GetFullList();
List<KitViewModel> GetFilteredList(KitSearchModel model);
KitViewModel? GetElement(KitSearchModel model);
KitViewModel? Insert(KitBindingModel model);
KitViewModel? Update(KitBindingModel model);
KitViewModel? Delete(KitBindingModel model);
}
}

View File

@ -1,15 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.StoragesContracts
{
public interface IServiceStorage
{
List<ServiceViewModel> GetFullList();
List<ServiceViewModel> GetFilteredList(ServiceSearchModel model);
ServiceViewModel? GetElement(ServiceSearchModel model);
ServiceViewModel? Insert(ServiceBindingModel model);
ServiceViewModel? Update(ServiceBindingModel model);
ServiceViewModel? Delete(ServiceBindingModel model);
}
}

View File

@ -1,15 +0,0 @@
using DeviceContracts.BindingModels;
using DeviceContracts.SearchModels;
using DeviceContracts.ViewModels;
namespace DeviceContracts.StoragesContracts
{
public interface IStaffStorage
{
List<StaffViewModel> GetFullList();
List<StaffViewModel> GetFilteredList(StaffSearchModel model);
StaffViewModel? GetElement(StaffSearchModel model);
StaffViewModel? Insert(StaffBindingModel model);
StaffViewModel? Update(StaffBindingModel model);
StaffViewModel? Delete(StaffBindingModel model);
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<int, IKitModel> Ownership { get; set; }
= new();
}
}

View File

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

View File

@ -1,9 +0,0 @@
namespace DeviceDataModels.Enums
{
public enum AccessLevel
{
Сотрудник = 0,
Техник = 1,
Админ = 2
}
}

View File

@ -1,7 +0,0 @@
namespace DeviceDataModels
{
public interface IId
{
int Id { get; }
}
}

View File

@ -1,8 +0,0 @@
namespace DeviceDataModels.Models
{
public interface ICabinetModel : IId
{
string Room { get; }
int Building { get; }
}
}

View File

@ -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; }
}
}

View File

@ -1,8 +0,0 @@
namespace DeviceDataModels.Models
{
public interface IKindModel : IId
{
string Title { get; }
int Frequency { get; }
}
}

View File

@ -1,8 +0,0 @@
namespace DeviceDataModels.Models
{
public interface IKitModel : IId
{
string Title { get; }
int? CabinetId { get; }
}
}

View File

@ -1,10 +0,0 @@
namespace DeviceDataModels.Models
{
public interface IServiceModel : IId
{
string Description { get; }
DateOnly StartDate { get; }
DateOnly? EndDate { get; }
int DeviceId { get; }
}
}

View File

@ -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; }
}
}

View File

@ -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<Ownership>()
.HasKey(sc => new { sc.StaffId, sc.KitId });
}
public virtual DbSet<Cabinet> Cabinets { set; get; }
public virtual DbSet<Device> Devices { set; get; }
public virtual DbSet<Kind> Kinds { set; get; }
public virtual DbSet<Kit> Kits { set; get; }
public virtual DbSet<Service> Services { set; get; }
public virtual DbSet<Staff> Staff { set; get; }
public virtual DbSet<Ownership> Ownership { set; get; }
}
}

View File

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

View File

@ -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<CabinetViewModel> GetFullList()
{
using var context = new DeviceDatabase();
return context.Cabinets.Select(x => x.GetViewModel).ToList();
}
public List<CabinetViewModel> 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;
}
}
}

View File

@ -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<DeviceViewModel> GetFullList()
{
using var context = new DeviceDatabase();
return context.Devices.Select(x => x.GetViewModel).ToList();
}
public List<DeviceViewModel> 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;
}
}
}

View File

@ -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<KindViewModel> GetFullList()
{
using var context = new DeviceDatabase();
return context.Kinds.Select(x => x.GetViewModel).ToList();
}
public List<KindViewModel> 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;
}
}
}

View File

@ -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<KitViewModel> GetFullList()
{
using var context = new DeviceDatabase();
return context.Kits.Select(x => x.GetViewModel).ToList();
}
public List<KitViewModel> 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;
}
}
}

View File

@ -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<ServiceViewModel> GetFullList()
{
using var context = new DeviceDatabase();
return context.Services.Select(x => x.GetViewModel).ToList();
}
public List<ServiceViewModel> 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;
}
}
}

View File

@ -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<StaffViewModel> GetFullList()
{
using var context = new DeviceDatabase();
return context.Staff.Select(x => x.GetViewModel).ToList();
}
public List<StaffViewModel> 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;
}
}
}

View File

@ -1,300 +0,0 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Building")
.HasColumnType("int");
b.Property<int?>("CabinetId")
.HasColumnType("int");
b.Property<string>("Room")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("CabinetId");
b.ToTable("Cabinets");
});
modelBuilder.Entity("DeviceDatabaseImplement.Models.Device", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("Condition")
.HasColumnType("bit");
b.Property<int>("KindId")
.HasColumnType("int");
b.Property<int?>("KitId")
.HasColumnType("int");
b.Property<string>("Model")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateOnly?>("ProductionDate")
.HasColumnType("date");
b.Property<string>("SerialNumber")
.HasColumnType("nvarchar(max)");
b.Property<int?>("WarrantyPeriod")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("KindId");
b.HasIndex("KitId");
b.ToTable("Devices");
});
modelBuilder.Entity("DeviceDatabaseImplement.Models.Kind", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Frequency")
.HasColumnType("int");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Kinds");
});
modelBuilder.Entity("DeviceDatabaseImplement.Models.Kit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("CabinetId")
.HasColumnType("int");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("CabinetId");
b.ToTable("Kits");
});
modelBuilder.Entity("DeviceDatabaseImplement.Models.Ownership", b =>
{
b.Property<int>("StaffId")
.HasColumnType("int");
b.Property<int>("KitId")
.HasColumnType("int");
b.HasKey("StaffId", "KitId");
b.HasIndex("KitId");
b.ToTable("Ownership");
});
modelBuilder.Entity("DeviceDatabaseImplement.Models.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("DeviceId")
.HasColumnType("int");
b.Property<DateOnly?>("EndDate")
.HasColumnType("date");
b.Property<int?>("ServiceId")
.HasColumnType("int");
b.Property<DateOnly>("StartDate")
.HasColumnType("date");
b.HasKey("Id");
b.HasIndex("ServiceId");
b.ToTable("Services");
});
modelBuilder.Entity("DeviceDatabaseImplement.Models.Staff", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AccessLevel")
.HasColumnType("int");
b.Property<string>("Department")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FullName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("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
}
}
}

View File

@ -1,218 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DeviceDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Cabinets",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Room = table.Column<string>(type: "nvarchar(max)", nullable: false),
Building = table.Column<int>(type: "int", nullable: false),
},
constraints: table =>
{
table.PrimaryKey("Cabinets_PKey", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Kits",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cabinet_Id = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
Frequency = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("Kinds_PKey", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Devices",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Model = table.Column<string>(type: "nvarchar(max)", nullable: false),
Serial_Number = table.Column<string>(type: "nvarchar(max)", nullable: true),
Production_Date = table.Column<DateOnly>(type: "date", nullable: true),
Warranty_Period = table.Column<int>(type: "int", nullable: true),
Condition = table.Column<bool>(type: "bit", nullable: false),
Kind_Id = table.Column<int>(type: "int", nullable: false),
Kit_Id = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
Start_Date = table.Column<DateOnly>(type: "date", nullable: false),
End_Date = table.Column<DateOnly>(type: "date", nullable: true),
Device_Id = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Full_Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Department = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
Access_Level = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("Staff_PKey", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Ownership",
columns: table => new
{
Kit_Id = table.Column<int>(type: "int", nullable: false),
Staff_Id = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -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,
};
}
}

View File

@ -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,
};
}
}

View File

@ -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,
};
}
}

View File

@ -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,
};
}
}

View File

@ -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!;
}
}

View File

@ -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,
};
}
}

View File

@ -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,
};
}
}