PIbd-21 Potapov N.S. LabWork03 Hard #12
1
.gitignore
vendored
1
.gitignore
vendored
@ -398,3 +398,4 @@ FodyWeavers.xsd
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
ImplementationExtensions/
|
||||
|
@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemBusinessLogic
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemListImplement", "SecuritySystemListImplement\SecuritySystemListImplement.csproj", "{6A104362-3398-4D4E-A3D0-2F4B32858569}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemFileImplement", "SecuritySystemFileImplement\SecuritySystemFileImplement.csproj", "{0ACD169C-97A8-452E-A17A-19E2464F5286}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemFileImplement", "SecuritySystemFileImplement\SecuritySystemFileImplement.csproj", "{0ACD169C-97A8-452E-A17A-19E2464F5286}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemDatabaseImplement", "SecuritySystemDatabaseImplement\SecuritySystemDatabaseImplement.csproj", "{4AE7461C-39CC-463B-B5A1-A47ED3B9E925}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -45,6 +47,10 @@ Global
|
||||
{0ACD169C-97A8-452E-A17A-19E2464F5286}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0ACD169C-97A8-452E-A17A-19E2464F5286}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0ACD169C-97A8-452E-A17A-19E2464F5286}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4AE7461C-39CC-463B-B5A1-A47ED3B9E925}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4AE7461C-39CC-463B-B5A1-A47ED3B9E925}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4AE7461C-39CC-463B-B5A1-A47ED3B9E925}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4AE7461C-39CC-463B-B5A1-A47ED3B9E925}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -13,12 +13,14 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly ISecureStorage _secureStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic)
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, ISecureStorage secureStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_secureStorage = secureStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
@ -56,14 +58,18 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("Read operation failed");
|
||||
return false;
|
||||
}
|
||||
model.SecureId = element.SecureId;
|
||||
model.Count = element.Count;
|
||||
model.Sum = element.Sum;
|
||||
if (element.Status != targetStatus - 1)
|
||||
{
|
||||
_logger.LogWarning("Status change operation failed");
|
||||
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
|
||||
}
|
||||
var secure = _secureStorage.GetElement(new SecureSearchModel { Id = model.SecureId });
|
||||
if (targetStatus == OrderStatus.Выдан)
|
||||
{
|
||||
_shopLogic.SupplySecures();
|
||||
_shopLogic.SupplySecures(secure, model.Count);
|
||||
}
|
||||
model.Status = targetStatus;
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
|
@ -153,6 +153,11 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
|
||||
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
|
||||
|
||||
if (GetFreeSpace(shopElement.Id) < count)
|
||||
{
|
||||
throw new InvalidOperationException("В магазине не хватает места");
|
||||
}
|
||||
|
||||
if (shopElement.ShopSecures.TryGetValue(secure.Id, out var sameSecure))
|
||||
{
|
||||
shopElement.ShopSecures[secure.Id] = (secure, sameSecure.Item2 + count);
|
||||
@ -176,34 +181,44 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool SupplySecures(ISecureModel secure, int count) => throw new NotImplementedException();
|
||||
public bool SellSecures(ISecureModel model, int count) => throw new NotImplementedException();
|
||||
public bool CheckSecuresCount(ISecureModel model, int count)
|
||||
public bool SupplySecures(ISecureModel secure, int count)
|
||||
{
|
||||
int securesInShops = _shopStorage.GetFullList()
|
||||
.Select(x => x.ShopSecures.Select(y => y.Value.Item1.Id == model.Id ? y.Value.Item2 : 0).Sum()).Sum();
|
||||
return securesInShops >= count;
|
||||
}
|
||||
public bool CheckSupplySecures(ShopSearchModel shopSearchModel, int count)
|
||||
{
|
||||
if (shopSearchModel == null)
|
||||
throw new ArgumentNullException(nameof(shopSearchModel));
|
||||
|
||||
var shop = _shopStorage.GetElement(shopSearchModel);
|
||||
|
||||
if (shop == null)
|
||||
if (!CheckSupplySecures(count))
|
||||
{
|
||||
_logger.LogWarning("Required shop element not found in storage");
|
||||
return false;
|
||||
throw new InvalidOperationException("Невозможно пополнить: в магазинах не хватает места");
|
||||
}
|
||||
|
||||
int securesInShop = _shopStorage.GetFullList().Select(x => x.ShopSecures.Select(y => y.Value.Item2).Sum()).Sum();
|
||||
var shops = _shopStorage.GetFullList();
|
||||
foreach (var shop in shops)
|
||||
{
|
||||
int shopFreeSpace = GetFreeSpace(shop.Id);
|
||||
if (shopFreeSpace > 0 && count > 0)
|
||||
{
|
||||
int min = Math.Min(count, shopFreeSpace);
|
||||
count -= min;
|
||||
SupplySecures(new ShopSearchModel { Id = shop.Id }, secure, min);
|
||||
}
|
||||
}
|
||||
|
||||
return securesInShop + count <= shop.MaxSecuresCount;
|
||||
return true;
|
||||
}
|
||||
public bool SellSecures(ISecureModel model, int count)
|
||||
{
|
||||
return _shopStorage.SellSecures(model, count);
|
||||
}
|
||||
public bool CheckSupplySecures(int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return GetFreeSpace() >= count;
|
||||
}
|
||||
private int GetFreeSpace()
|
||||
{
|
||||
var shops = _shopStorage.GetFullList();
|
||||
return shops.Select(shop => shop.MaxSecuresCount - shop.ShopSecures.Select(shopSecure => shopSecure.Value.Item2).Sum()).Sum();
|
||||
}
|
||||
private int GetFreeSpace(int shopId)
|
||||
{
|
||||
var shop = _shopStorage.GetElement(new ShopSearchModel { Id = shopId });
|
||||
return shop.MaxSecuresCount - shop.ShopSecures.Select(shopSecure => shopSecure.Value.Item2).Sum();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,14 +17,6 @@ namespace SecuritySystemContracts.BusinessLogicsContracts
|
||||
/// </summary>
|
||||
bool SellSecures(ISecureModel model, int count);
|
||||
/// <summary>
|
||||
/// Проверяет наличие определенного количества продукта суммарно по всем магазинам
|
||||
/// </summary>
|
||||
bool CheckSecuresCount(ISecureModel model, int count);
|
||||
/// <summary>
|
||||
/// Проверяет можно ли пополнить конкретный магазин продукцией в указанном количестве
|
||||
/// </summary>
|
||||
bool CheckSupplySecures(ShopSearchModel shopSearchModel, int count);
|
||||
/// <summary>
|
||||
/// Проверяет можно ли распределить во все магазины продукты в указанном количестве
|
||||
/// </summary>
|
||||
bool CheckSupplySecures(int count);
|
||||
|
@ -13,5 +13,6 @@ namespace SecuritySystemContracts.StoragesContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SellSecures(ISecureModel secureModel, int securesCount);
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,10 @@ namespace SecuritySystemContracts.ViewModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Адрес")]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
[DisplayName("Макс. кол-во товара")]
|
||||
[DisplayName("Вместимость")]
|
||||
public int MaxSecuresCount { get; set; }
|
||||
[DisplayName("Заполненность")]
|
||||
public int UsedSpace { get; set; }
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
public Dictionary<int, (ISecureModel, int)> ShopSecures { get; set; } = new();
|
||||
|
@ -0,0 +1,85 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDatabaseImplement.Models;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
return context.Components
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
|
||||
model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new SecuritySystemDatabase();
|
||||
return context.Components
|
||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SecuritySystemDatabase();
|
||||
return context.Components
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
||||
model.ComponentName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SecuritySystemDatabase();
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var component = context.Components.FirstOrDefault(x => x.Id ==
|
||||
model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var element = context.Components.FirstOrDefault(rec => rec.Id ==
|
||||
model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDatabaseImplement.Models;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SecuritySystemDatabase();
|
||||
return context.Orders.Include(x => x.Secure).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new SecuritySystemDatabase();
|
||||
return context.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Include(x => x.Secure)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
return context.Orders.Include(x => x.Secure).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SecuritySystemDatabase();
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDatabaseImplement.Models;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Implements
|
||||
{
|
||||
public class SecureStorage : ISecureStorage
|
||||
{
|
||||
public List<SecureViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
return context.Secures
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<SecureViewModel> GetFilteredList(SecureSearchModel model)
|
||||
{
|
||||
var secures = GetFullList();
|
||||
if (model.Id != null)
|
||||
{
|
||||
secures = secures.Where(x => x.Id == model.Id).ToList();
|
||||
}
|
||||
if (!model.SecureName.IsNullOrEmpty())
|
||||
{
|
||||
secures = secures.Where(x => x.SecureName == model.SecureName).ToList();
|
||||
}
|
||||
return secures;
|
||||
}
|
||||
public SecureViewModel? GetElement(SecureSearchModel model)
|
||||
{
|
||||
return GetFilteredList(model).FirstOrDefault();
|
||||
}
|
||||
public SecureViewModel? Insert(SecureBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var newSecure = Secure.Create(context, model);
|
||||
if (newSecure == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Secures.Add(newSecure);
|
||||
context.SaveChanges();
|
||||
return newSecure.GetViewModel;
|
||||
}
|
||||
public SecureViewModel? Update(SecureBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var secure = context.Secures.FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
if (secure == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
secure.Update(model);
|
||||
context.SaveChanges();
|
||||
secure.UpdateComponents(context, model);
|
||||
transaction.Commit();
|
||||
return secure.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public SecureViewModel? Delete(SecureBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var element = context.Secures
|
||||
.Include(x => x.Components)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Secures.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDatabaseImplement.Models;
|
||||
using SecuritySystemDataModels.Models;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var shop = context.Shops.Include(x => x.Secures).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop != null)
|
||||
{
|
||||
context.Shops.Remove(shop);
|
||||
context.SaveChanges();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
return GetFilteredList(model).FirstOrDefault();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
var elements = GetFullList();
|
||||
if (model.Id != null)
|
||||
{
|
||||
elements = elements.Where(x => x.Id == model.Id).ToList();
|
||||
}
|
||||
if (!model.Name.IsNullOrEmpty())
|
||||
{
|
||||
elements = elements.Where(x => x.Name == model.Name).ToList();
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Secures)
|
||||
.ThenInclude(x => x.Secure)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
var newShop = Shop.Create(context, model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Shops.Add(newShop);
|
||||
context.SaveChanges();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool SellSecures(ISecureModel secureModel, int securesCount)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
foreach (var shopSecure in context.ShopSecures.Where(x => x.SecureId == secureModel.Id))
|
||||
{
|
||||
var min = Math.Min(securesCount, shopSecure.Count);
|
||||
shopSecure.Count -= min;
|
||||
securesCount -= min;
|
||||
if (securesCount <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (securesCount == 0)
|
||||
{
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
if (securesCount > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
using var context = new SecuritySystemDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
shop.UpdateSecures(context, model);
|
||||
|
||||
transaction.Commit();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
171
SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240311050857_InitialCreate.Designer.cs
generated
Normal file
171
SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240311050857_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SecuritySystemDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(SecuritySystemDatabase))]
|
||||
[Migration("20240311050857_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("SecureName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Secures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.ToTable("SecureComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Secure");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("SecureComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Secure");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("SecureComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Secures",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
SecureName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Secures", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
SecureId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Secures_SecureId",
|
||||
column: x => x.SecureId,
|
||||
principalTable: "Secures",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SecureComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
SecureId = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SecureComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_SecureComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_SecureComponents_Secures_SecureId",
|
||||
column: x => x.SecureId,
|
||||
principalTable: "Secures",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_SecureId",
|
||||
table: "Orders",
|
||||
column: "SecureId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SecureComponents_ComponentId",
|
||||
table: "SecureComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SecureComponents_SecureId",
|
||||
table: "SecureComponents",
|
||||
column: "SecureId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "SecureComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Secures");
|
||||
}
|
||||
}
|
||||
}
|
248
SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240519222424_AddShops.Designer.cs
generated
Normal file
248
SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240519222424_AddShops.Designer.cs
generated
Normal file
@ -0,0 +1,248 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SecuritySystemDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(SecuritySystemDatabase))]
|
||||
[Migration("20240519222424_AddShops")]
|
||||
partial class AddShops
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("SecureName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Secures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.ToTable("SecureComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("MaxSecuresCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.ShopSecure", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopSecures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Secure");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("SecureComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Secure");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.ShopSecure", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany()
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Secures")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Secure");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("SecureComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Secures");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddShops : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
MaxSecuresCount = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopSecures",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
SecureId = table.Column<int>(type: "int", nullable: false),
|
||||
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopSecures", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopSecures_Secures_SecureId",
|
||||
column: x => x.SecureId,
|
||||
principalTable: "Secures",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopSecures_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopSecures_SecureId",
|
||||
table: "ShopSecures",
|
||||
column: "SecureId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopSecures_ShopId",
|
||||
table: "ShopSecures",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopSecures");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,245 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SecuritySystemDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(SecuritySystemDatabase))]
|
||||
partial class SecuritySystemDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("SecureName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Secures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.ToTable("SecureComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("MaxSecuresCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.ShopSecure", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SecureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SecureId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopSecures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Secure");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("SecureComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Secure");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.ShopSecure", b =>
|
||||
{
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
|
||||
.WithMany()
|
||||
|
||||
.HasForeignKey("SecureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SecuritySystemDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Secures")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Secure");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("SecureComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Secures");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<SecureComponent> SecureComponents { get; set; } =
|
||||
new();
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public static Component Create(ComponentViewModel model)
|
||||
{
|
||||
return new Component
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public void Update(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Enums;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int SecureId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public virtual Secure Secure { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order
|
||||
{
|
||||
SecureId = model.SecureId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
SecureId = SecureId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
SecureName = Secure.SecureName
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Models
|
||||
{
|
||||
public class Secure : ISecureModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string SecureName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _productComponents =
|
||||
null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> SecureComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_productComponents == null)
|
||||
{
|
||||
_productComponents = Components
|
||||
.ToDictionary(recPC => recPC.ComponentId, recPC =>
|
||||
(recPC.Component as IComponentModel, recPC.Count));
|
||||
}
|
||||
return _productComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("SecureId")]
|
||||
public virtual List<SecureComponent> Components { get; set; } = new();
|
||||
[ForeignKey("SecureId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Secure Create(SecuritySystemDatabase context, SecureBindingModel model)
|
||||
{
|
||||
return new Secure()
|
||||
{
|
||||
Id = model.Id,
|
||||
SecureName = model.SecureName,
|
||||
Price = model.Price,
|
||||
Components = model.SecureComponents.Select(x => new
|
||||
SecureComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(SecureBindingModel model)
|
||||
{
|
||||
SecureName = model.SecureName;
|
||||
Price = model.Price;
|
||||
}
|
||||
public SecureViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SecureName = SecureName,
|
||||
Price = Price,
|
||||
SecureComponents = SecureComponents
|
||||
};
|
||||
public void UpdateComponents(SecuritySystemDatabase context,
|
||||
SecureBindingModel model)
|
||||
{
|
||||
var productComponents = context.SecureComponents.Where(rec =>
|
||||
rec.SecureId == model.Id).ToList();
|
||||
if (productComponents != null && productComponents.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.SecureComponents.RemoveRange(productComponents.Where(rec
|
||||
=> !model.SecureComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateComponent in productComponents)
|
||||
{
|
||||
updateComponent.Count =
|
||||
model.SecureComponents[updateComponent.ComponentId].Item2;
|
||||
model.SecureComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var product = context.Secures.First(x => x.Id == Id);
|
||||
foreach (var pc in model.SecureComponents)
|
||||
{
|
||||
context.SecureComponents.Add(new SecureComponent
|
||||
{
|
||||
Secure = product,
|
||||
Component = context.Components.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_productComponents = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Models
|
||||
{
|
||||
public class SecureComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int SecureId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Secure Secure { get; set; } = new();
|
||||
}
|
||||
|
||||
}
|
108
SecuritySystem/SecuritySystemDatabaseImplement/Models/Shop.cs
Normal file
108
SecuritySystem/SecuritySystemDatabaseImplement/Models/Shop.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
[Required]
|
||||
public int MaxSecuresCount { get; set; }
|
||||
[ForeignKey("ShopId")]
|
||||
public virtual List<ShopSecure> Secures { get; set; } = new();
|
||||
private Dictionary<int, (ISecureModel, int)>? _shopSecures = null;
|
||||
[NotMapped]
|
||||
private int UsedSpace { get; set; }
|
||||
[NotMapped]
|
||||
public Dictionary<int, (ISecureModel, int)> ShopSecures
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopSecures == null)
|
||||
{
|
||||
_shopSecures = Secures
|
||||
.ToDictionary(
|
||||
shopSecure => shopSecure.SecureId,
|
||||
shopSecure => (shopSecure.Secure as ISecureModel, shopSecure.Count)
|
||||
);
|
||||
|
||||
UsedSpace = _shopSecures.Select(x => x.Value.Item2).Sum();
|
||||
}
|
||||
return _shopSecures;
|
||||
}
|
||||
}
|
||||
public static Shop Create(SecuritySystemDatabase context, ShopBindingModel model)
|
||||
{
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Address = model.Address,
|
||||
OpeningDate = model.OpeningDate,
|
||||
MaxSecuresCount = model.MaxSecuresCount,
|
||||
Secures = model.ShopSecures.Select(x => new ShopSecure
|
||||
{
|
||||
Secure = context.Secures.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Address = model.Address;
|
||||
OpeningDate = model.OpeningDate;
|
||||
MaxSecuresCount = model.MaxSecuresCount;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
MaxSecuresCount = MaxSecuresCount,
|
||||
ShopSecures = ShopSecures,
|
||||
UsedSpace = UsedSpace
|
||||
|
||||
};
|
||||
public void UpdateSecures(SecuritySystemDatabase context, ShopBindingModel model)
|
||||
{
|
||||
var shopSecures = context.ShopSecures.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
if (shopSecures != null && shopSecures.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.ShopSecures.RemoveRange(shopSecures.Where(rec => !model.ShopSecures.ContainsKey(rec.SecureId)));
|
||||
context.SaveChanges();
|
||||
shopSecures = context.ShopSecures.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateSecure in shopSecures)
|
||||
{
|
||||
updateSecure.Count = model.ShopSecures[updateSecure.SecureId].Item2;
|
||||
model.ShopSecures.Remove(updateSecure.SecureId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var shop = context.Shops.First(x => x.Id == Id);
|
||||
foreach (var elem in model.ShopSecures)
|
||||
{
|
||||
context.ShopSecures.Add(new ShopSecure
|
||||
{
|
||||
Shop = shop,
|
||||
Secure = context.Secures.First(x => x.Id == elem.Key),
|
||||
Count = elem.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_shopSecures = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement.Models
|
||||
{
|
||||
public class ShopSecure
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int SecureId { get; set; }
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Shop Shop { get; set; } = new();
|
||||
public virtual Secure Secure { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SecuritySystemDatabaseImplement.Models;
|
||||
using System.ComponentModel;
|
||||
using Component = SecuritySystemDatabaseImplement.Models.Component;
|
||||
|
||||
namespace SecuritySystemDatabaseImplement
|
||||
{
|
||||
public class SecuritySystemDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder
|
||||
optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=SecuritySystemDatabaseHard;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Secure> Secures { set; get; }
|
||||
public virtual DbSet<SecureComponent> SecureComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<ShopSecure> ShopSecures { get; set; }
|
||||
public virtual DbSet<Shop> Shops { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -4,6 +4,7 @@ using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using SecuritySystemFileImplement.Models;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SecuritySystemFileImplement.Implements
|
||||
{
|
||||
@ -75,5 +76,56 @@ namespace SecuritySystemFileImplement.Implements
|
||||
source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
public bool SellSecures(ISecureModel secureModel, int securesCount)
|
||||
{
|
||||
var secure = source.Secures.FirstOrDefault(x => x.Id == secureModel.Id);
|
||||
|
||||
if (secure == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var shopSecures = source.Shops.SelectMany(shop => shop.ShopSecures.Where(c => c.Value.Item1.Id == secure.Id));
|
||||
|
||||
int countStore = 0;
|
||||
|
||||
foreach (var it in shopSecures)
|
||||
countStore += it.Value.Item2;
|
||||
|
||||
if (securesCount > countStore)
|
||||
return false;
|
||||
|
||||
foreach (var shop in source.Shops)
|
||||
{
|
||||
var secures = shop.ShopSecures;
|
||||
|
||||
foreach (var c in secures.Where(x => x.Value.Item1.Id == secure.Id))
|
||||
{
|
||||
int min = Math.Min(c.Value.Item2, securesCount);
|
||||
secures[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
|
||||
securesCount -= min;
|
||||
|
||||
if (securesCount <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
shop.Update(new ShopBindingModel
|
||||
{
|
||||
Id = shop.Id,
|
||||
Name = shop.Name,
|
||||
Address = shop.Address,
|
||||
MaxSecuresCount = shop.MaxSecuresCount,
|
||||
OpeningDate = shop.OpeningDate,
|
||||
ShopSecures = secures
|
||||
});
|
||||
|
||||
source.SaveShops();
|
||||
|
||||
if (securesCount <= 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using SecuritySystemListImplement.Models;
|
||||
|
||||
namespace SecuritySystemListImplement.Implements
|
||||
@ -117,5 +118,10 @@ namespace SecuritySystemListImplement.Implements
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellSecures(ISecureModel secureModel, int securesCount)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,13 +33,14 @@
|
||||
ComponentsToolStripMenuItem = new ToolStripMenuItem();
|
||||
SecuresToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
|
||||
продатьПродукциюToolStripMenuItem = new ToolStripMenuItem();
|
||||
dataGridView = new DataGridView();
|
||||
buttonCreateOrder = new Button();
|
||||
buttonTakeOrderInWork = new Button();
|
||||
buttonOrderReady = new Button();
|
||||
button4 = new Button();
|
||||
buttonRefresh = new Button();
|
||||
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
@ -47,7 +48,7 @@
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem });
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продатьПродукциюToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(1043, 28);
|
||||
@ -82,6 +83,20 @@
|
||||
магазиныToolStripMenuItem.Text = "Магазины";
|
||||
магазиныToolStripMenuItem.Click += ShopsToolStripMenuItem_Click;
|
||||
//
|
||||
// пополнениеМагазинаToolStripMenuItem
|
||||
//
|
||||
пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
|
||||
пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24);
|
||||
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
||||
пополнениеМагазинаToolStripMenuItem.Click += SupplyShopToolStripMenuItem_Click;
|
||||
//
|
||||
// продатьПродукциюToolStripMenuItem
|
||||
//
|
||||
продатьПродукциюToolStripMenuItem.Name = "продатьПродукциюToolStripMenuItem";
|
||||
продатьПродукциюToolStripMenuItem.Size = new Size(165, 24);
|
||||
продатьПродукциюToolStripMenuItem.Text = "Продать продукцию";
|
||||
продатьПродукциюToolStripMenuItem.Click += продатьПродукциюToolStripMenuItem_Click;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
@ -151,13 +166,6 @@
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// пополнениеМагазинаToolStripMenuItem
|
||||
//
|
||||
пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
|
||||
пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24);
|
||||
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
||||
пополнениеМагазинаToolStripMenuItem.Click += SupplyShopToolStripMenuItem_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
@ -195,5 +203,6 @@
|
||||
private Button buttonRefresh;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
|
||||
private ToolStripMenuItem продатьПродукциюToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.BusinessLogicsContracts;
|
||||
using SecuritySystemView.Shop;
|
||||
|
||||
namespace SecuritySystemView
|
||||
{
|
||||
@ -154,5 +155,14 @@ namespace SecuritySystemView
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void продатьПродукциюToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||
if (service is FormShopSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
|
@ -4,7 +4,8 @@ using NLog.Extensions.Logging;
|
||||
using SecuritySystemBusinessLogic.BusinessLogics;
|
||||
using SecuritySystemContracts.BusinessLogicsContracts;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemFileImplement.Implements;
|
||||
using SecuritySystemDatabaseImplement.Implements;
|
||||
using SecuritySystemView.Shop;
|
||||
|
||||
namespace SecuritySystemView
|
||||
{
|
||||
@ -51,6 +52,7 @@ namespace SecuritySystemView
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShopSupply>();
|
||||
services.AddTransient<FormShopSell>();
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||
@ -28,6 +32,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemContracts\SecuritySystemContracts.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemDatabaseImplement\SecuritySystemDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemFileImplement\SecuritySystemFileImplement.csproj" />
|
||||
<ProjectReference Include="..\SecuritySystemListImplement\SecuritySystemListImplement.csproj" />
|
||||
|
@ -38,10 +38,12 @@
|
||||
ColumnId = new DataGridViewTextBoxColumn();
|
||||
ColumnName = new DataGridViewTextBoxColumn();
|
||||
ColumnCount = new DataGridViewTextBoxColumn();
|
||||
colorDialog1 = new ColorDialog();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
numericUpDownCapacity = new NumericUpDown();
|
||||
labelCapacity = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
@ -153,11 +155,30 @@
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// numericUpDownCapacity
|
||||
//
|
||||
numericUpDownCapacity.Location = new Point(510, 71);
|
||||
numericUpDownCapacity.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownCapacity.Name = "numericUpDownCapacity";
|
||||
numericUpDownCapacity.Size = new Size(150, 27);
|
||||
numericUpDownCapacity.TabIndex = 7;
|
||||
//
|
||||
// labelCapacity
|
||||
//
|
||||
labelCapacity.AutoSize = true;
|
||||
labelCapacity.Location = new Point(398, 76);
|
||||
labelCapacity.Name = "labelCapacity";
|
||||
labelCapacity.Size = new Size(103, 20);
|
||||
labelCapacity.TabIndex = 8;
|
||||
labelCapacity.Text = "Вместимость:";
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(672, 450);
|
||||
Controls.Add(labelCapacity);
|
||||
Controls.Add(numericUpDownCapacity);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(dataGridView);
|
||||
@ -171,6 +192,7 @@
|
||||
Text = "Магазин";
|
||||
Load += FormShop_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@ -187,8 +209,9 @@
|
||||
private DataGridViewTextBoxColumn ColumnId;
|
||||
private DataGridViewTextBoxColumn ColumnName;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
private ColorDialog colorDialog1;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private NumericUpDown numericUpDownCapacity;
|
||||
private Label labelCapacity;
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ namespace SecuritySystemView
|
||||
textBoxName.Text = view.Name;
|
||||
textBoxAddress.Text = view.Address;
|
||||
dateTimePickerOpeningDate.Value = view.OpeningDate;
|
||||
numericUpDownCapacity.Value = view.MaxSecuresCount;
|
||||
_shopSecures = view.ShopSecures ?? new Dictionary<int, (ISecureModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
@ -85,6 +86,12 @@ namespace SecuritySystemView
|
||||
return;
|
||||
}
|
||||
|
||||
if (numericUpDownCapacity.Value <= 0)
|
||||
{
|
||||
MessageBox.Show("Вместимость должна быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
|
||||
try
|
||||
@ -95,7 +102,8 @@ namespace SecuritySystemView
|
||||
Name = textBoxName.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
OpeningDate = dateTimePickerOpeningDate.Value.Date,
|
||||
ShopSecures = _shopSecures
|
||||
ShopSecures = _shopSecures,
|
||||
MaxSecuresCount = (int)numericUpDownCapacity.Value
|
||||
};
|
||||
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
|
@ -18,7 +18,7 @@
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
@ -126,7 +126,13 @@
|
||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="colorDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
<metadata name="ColumnId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
125
SecuritySystem/SecuritySystemView/Shop/FormShopSell.Designer.cs
generated
Normal file
125
SecuritySystem/SecuritySystemView/Shop/FormShopSell.Designer.cs
generated
Normal file
@ -0,0 +1,125 @@
|
||||
namespace SecuritySystemView.Shop
|
||||
{
|
||||
partial class FormShopSell
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonSell = new Button();
|
||||
buttonCancel = new Button();
|
||||
comboBoxSecure = new ComboBox();
|
||||
numericUpDownCount = new NumericUpDown();
|
||||
labelSecure = new Label();
|
||||
labelCount = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
buttonSell.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonSell.Location = new Point(573, 89);
|
||||
buttonSell.Name = "buttonSell";
|
||||
buttonSell.Size = new Size(94, 29);
|
||||
buttonSell.TabIndex = 0;
|
||||
buttonSell.Text = "Продать";
|
||||
buttonSell.UseVisualStyleBackColor = true;
|
||||
buttonSell.Click += buttonSell_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(673, 89);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 1;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// comboBoxSecure
|
||||
//
|
||||
comboBoxSecure.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxSecure.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSecure.FormattingEnabled = true;
|
||||
comboBoxSecure.Location = new Point(84, 9);
|
||||
comboBoxSecure.Name = "comboBoxSecure";
|
||||
comboBoxSecure.Size = new Size(683, 28);
|
||||
comboBoxSecure.TabIndex = 2;
|
||||
//
|
||||
// numericUpDownCount
|
||||
//
|
||||
numericUpDownCount.Location = new Point(108, 43);
|
||||
numericUpDownCount.Name = "numericUpDownCount";
|
||||
numericUpDownCount.Size = new Size(150, 27);
|
||||
numericUpDownCount.TabIndex = 3;
|
||||
//
|
||||
// labelSecure
|
||||
//
|
||||
labelSecure.AutoSize = true;
|
||||
labelSecure.Location = new Point(12, 12);
|
||||
labelSecure.Name = "labelSecure";
|
||||
labelSecure.Size = new Size(66, 20);
|
||||
labelSecure.TabIndex = 4;
|
||||
labelSecure.Text = "Продукт";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(12, 45);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(90, 20);
|
||||
labelCount.TabIndex = 5;
|
||||
labelCount.Text = "Количество";
|
||||
//
|
||||
// FormShopSell
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(779, 130);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(labelSecure);
|
||||
Controls.Add(numericUpDownCount);
|
||||
Controls.Add(comboBoxSecure);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSell);
|
||||
Name = "FormShopSell";
|
||||
Text = "Продажа товара";
|
||||
Load += FormShopSell_Load;
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonSell;
|
||||
private Button buttonCancel;
|
||||
private ComboBox comboBoxSecure;
|
||||
private NumericUpDown numericUpDownCount;
|
||||
private Label labelSecure;
|
||||
private Label labelCount;
|
||||
}
|
||||
}
|
85
SecuritySystem/SecuritySystemView/Shop/FormShopSell.cs
Normal file
85
SecuritySystem/SecuritySystemView/Shop/FormShopSell.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace SecuritySystemView.Shop
|
||||
{
|
||||
public partial class FormShopSell : Form
|
||||
{
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly ISecureLogic _secureLogic;
|
||||
private readonly ILogger _logger;
|
||||
public FormShopSell(ILogger<FormShopSell> logger, IShopLogic shopLogic, ISecureLogic secureLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_shopLogic = shopLogic;
|
||||
_secureLogic = secureLogic;
|
||||
}
|
||||
|
||||
private void FormShopSell_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка продукции для продажи");
|
||||
try
|
||||
{
|
||||
var list = _secureLogic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxSecure.DisplayMember = "SecureName";
|
||||
comboBoxSecure.ValueMember = "Id";
|
||||
comboBoxSecure.DataSource = list;
|
||||
comboBoxSecure.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка продукции");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSell_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (numericUpDownCount.Value < 1)
|
||||
{
|
||||
MessageBox.Show("Количество продукта должно быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxSecure.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите продукт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Создание продажи");
|
||||
try
|
||||
{
|
||||
var operationResult = _shopLogic.SellSecures(
|
||||
new SecureBindingModel
|
||||
{
|
||||
Id = Convert.ToInt32(comboBoxSecure.SelectedValue)
|
||||
},
|
||||
Convert.ToInt32(numericUpDownCount.Value)
|
||||
);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при создании продажи. Дополнительная информация в логах.");
|
||||
}
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания продажи");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
SecuritySystem/SecuritySystemView/Shop/FormShopSell.resx
Normal file
120
SecuritySystem/SecuritySystemView/Shop/FormShopSell.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Loading…
x
Reference in New Issue
Block a user
Связь настроена не до конца