Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 67bffd6798 | |||
| 1d24f91773 | |||
| 3d750ef0b2 | |||
| fe3e9171e8 | |||
| abf3aeca23 | |||
| 81b4335193 | |||
| b81bb26b41 | |||
| ad9847c51c | |||
| 5d703cb615 | |||
| b4c8722cd4 | |||
| 2fa2dfe6bc | |||
| 1a650d93b1 | |||
| 054222a8d4 | |||
| 4ac87a10ed | |||
| 332c58bda5 | |||
| e1fdeb7ba3 | |||
| 56faadb0ad | |||
| 27449f920f | |||
| 0d0ccaea66 | |||
| 82ce660a86 | |||
| e3a1f15b7c |
@@ -13,6 +13,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopBusinessLogic",
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopListImplement", "AutoWorkshopImplement\AutoWorkshopListImplement.csproj", "{B564F5E8-2F14-4816-8481-1F9649F1F414}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopFileImplement", "AutoWorkshopFileImplement\AutoWorkshopFileImplement.csproj", "{862B0F3D-1B88-45B8-9526-AD21A6D6FA81}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopDatabaseImplement", "AutoWorkshopDatabaseImplement\AutoWorkshopDatabaseImplement.csproj", "{751668F7-01A3-43F0-BDD8-ABB3A8F5A955}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -39,6 +43,14 @@ Global
|
||||
{B564F5E8-2F14-4816-8481-1F9649F1F414}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B564F5E8-2F14-4816-8481-1F9649F1F414}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B564F5E8-2F14-4816-8481-1F9649F1F414}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{862B0F3D-1B88-45B8-9526-AD21A6D6FA81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{862B0F3D-1B88-45B8-9526-AD21A6D6FA81}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{862B0F3D-1B88-45B8-9526-AD21A6D6FA81}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{862B0F3D-1B88-45B8-9526-AD21A6D6FA81}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{751668F7-01A3-43F0-BDD8-ABB3A8F5A955}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{751668F7-01A3-43F0-BDD8-ABB3A8F5A955}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{751668F7-01A3-43F0-BDD8-ABB3A8F5A955}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{751668F7-01A3-43F0-BDD8-ABB3A8F5A955}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -13,11 +13,14 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
public OrderLogic(ILogger<RepairLogic> Logger, IOrderStorage OrderStorage)
|
||||
public OrderLogic(ILogger<RepairLogic> Logger, IOrderStorage OrderStorage, IShopStorage ShopStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
|
||||
_orderStorage = OrderStorage;
|
||||
_shopStorage = ShopStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? Model)
|
||||
@@ -107,6 +110,23 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel Model)
|
||||
{
|
||||
var Order = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = Model.Id
|
||||
});
|
||||
|
||||
if (Order is null)
|
||||
throw new ArgumentNullException(nameof(Order));
|
||||
|
||||
if (!_shopStorage.RestockingShops(new SupplyBindingModel
|
||||
{
|
||||
RepairId = Order.RepairId,
|
||||
Count = Order.Count
|
||||
}))
|
||||
{
|
||||
throw new ArgumentException("Недостаточно места");
|
||||
}
|
||||
|
||||
return ChangeOrderStatus(Model, OrderStatus.Delivered);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
if (Model.Count <= 0)
|
||||
throw new ArgumentException("Количество ремонтов должно быть больше 0");
|
||||
|
||||
var Shop = _shopStorage.GetElement(new ShopSearchModel
|
||||
ShopViewModel? Shop = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
Id = Model.ShopId
|
||||
});
|
||||
@@ -110,11 +110,18 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
if (Shop == null)
|
||||
throw new ArgumentException("Магазина не существует");
|
||||
|
||||
int CurrentRepairsNum = Shop.ShopRepairs.Select(x => x.Value.Item2).Sum();
|
||||
if (Model.Count > Shop.RepairsMaxCount - CurrentRepairsNum)
|
||||
{
|
||||
_logger.LogWarning("Попытка добавить в магазин число элементов, большее RepairsMaxCount");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Shop.ShopRepairs.ContainsKey(Model.RepairId))
|
||||
{
|
||||
var OldValue = Shop.ShopRepairs[Model.RepairId];
|
||||
OldValue.Item2 += Model.Count;
|
||||
Shop.ShopRepairs[Model.RepairId] = OldValue;
|
||||
var RepairsNum = Shop.ShopRepairs[Model.RepairId];
|
||||
RepairsNum.Item2 += Model.Count;
|
||||
Shop.ShopRepairs[Model.RepairId] = RepairsNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -124,11 +131,20 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
});
|
||||
|
||||
if (Repair == null)
|
||||
throw new ArgumentException($"Поставка: Товар с id:{Model.RepairId} не найденн");
|
||||
throw new ArgumentException($"Поставка: Товар с id {Model.RepairId} не найден");
|
||||
|
||||
Shop.ShopRepairs.Add(Model.RepairId, (Repair, Model.Count));
|
||||
}
|
||||
|
||||
|
||||
_shopStorage.Update(new ShopBindingModel()
|
||||
{
|
||||
Id = Shop.Id,
|
||||
ShopName = Shop.ShopName,
|
||||
Address = Shop.Address,
|
||||
OpeningDate = Shop.OpeningDate,
|
||||
ShopRepairs = Shop.ShopRepairs,
|
||||
RepairsMaxCount = Shop.RepairsMaxCount,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -158,5 +174,21 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
public bool MakeSell(SupplySearchModel Model)
|
||||
{
|
||||
if (!Model.RepairId.HasValue || !Model.Count.HasValue)
|
||||
return false;
|
||||
|
||||
_logger.LogInformation("Поиск ремонтов во всех магазинах");
|
||||
if (_shopStorage.Sell(Model))
|
||||
{
|
||||
_logger.LogInformation("Продажа выполнена успешно");
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Продажа не выполнена");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,7 @@ namespace AutoWorkshopContracts.BindingModels
|
||||
public DateTime OpeningDate { get; set; } = DateTime.Now;
|
||||
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs { get; set; } = new();
|
||||
|
||||
public int RepairsMaxCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,7 @@ namespace AutoWorkshopContracts.BusinessLogicsContracts
|
||||
bool Delete(ShopBindingModel Model);
|
||||
|
||||
bool MakeSupply(SupplyBindingModel Model);
|
||||
|
||||
bool MakeSell(SupplySearchModel Model);
|
||||
}
|
||||
}
|
||||
|
||||
9
AutoWorkshopContracts/SearchModels/SupplySearchModel.cs
Normal file
9
AutoWorkshopContracts/SearchModels/SupplySearchModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace AutoWorkshopContracts.SearchModels
|
||||
{
|
||||
public class SupplySearchModel
|
||||
{
|
||||
public int? RepairId { get; set; }
|
||||
|
||||
public int? Count { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,9 @@ namespace AutoWorkshopContracts.StoragesContracts
|
||||
ShopViewModel? Update(ShopBindingModel Model);
|
||||
|
||||
ShopViewModel? Delete(ShopBindingModel Model);
|
||||
|
||||
bool Sell(SupplySearchModel Model);
|
||||
|
||||
bool RestockingShops(SupplyBindingModel Model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,8 @@ namespace AutoWorkshopContracts.ViewModels
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs { get; set; } = new();
|
||||
|
||||
[DisplayName("Вместимость")]
|
||||
public int RepairsMaxCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,7 @@
|
||||
DateTime OpeningDate { get; }
|
||||
|
||||
Dictionary<int, (IRepairModel, int)> ShopRepairs { get; }
|
||||
|
||||
int RepairsMaxCount { get; }
|
||||
}
|
||||
}
|
||||
|
||||
33
AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs
Normal file
33
AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement
|
||||
{
|
||||
public class AutoWorkshopDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder OptionsBuilder)
|
||||
{
|
||||
if (OptionsBuilder.IsConfigured == false)
|
||||
{
|
||||
OptionsBuilder.UseNpgsql(@"Host=localhost;Port=5000;Database=AutoWorkshop_Hard;Username=postgres;Password=admin");
|
||||
}
|
||||
|
||||
base.OnConfiguring(OptionsBuilder);
|
||||
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||
}
|
||||
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
|
||||
public virtual DbSet<Repair> Repairs { set; get; }
|
||||
|
||||
public virtual DbSet<RepairComponent> RepairComponents { set; get; }
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
|
||||
public virtual DbSet<Shop> Shops { get; set; }
|
||||
|
||||
public virtual DbSet<ShopRepair> ShopRepairs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="netcore-psql-util" Version="1.2.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
82
AutoWorkshopDatabaseImplement/Implements/ComponentStorage.cs
Normal file
82
AutoWorkshopDatabaseImplement/Implements/ComponentStorage.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
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 AutoWorkshopDatabase();
|
||||
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 AutoWorkshopDatabase();
|
||||
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 AutoWorkshopDatabase();
|
||||
Context.Components.Add(NewComponent);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
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 AutoWorkshopDatabase();
|
||||
var Component = Context.Components.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Component == null)
|
||||
return null;
|
||||
|
||||
Context.Components.Remove(Component);
|
||||
Context.SaveChanges();
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
94
AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs
Normal file
94
AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return new();
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Where(x => x.Id == Model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.FirstOrDefault(x => Model.Id.HasValue && x.Id == Model.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
var NewOrder = Order.Create(Model);
|
||||
if (NewOrder == null)
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
Context.Orders.Add(NewOrder);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Repair).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
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.Repair).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
var Order = Context.Orders.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
Context.Orders.Remove(Order);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Order.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
109
AutoWorkshopDatabaseImplement/Implements/RepairStorage.cs
Normal file
109
AutoWorkshopDatabaseImplement/Implements/RepairStorage.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class RepairStorage : IRepairStorage
|
||||
{
|
||||
public List<RepairViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
return Context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<RepairViewModel> GetFilteredList(RepairSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.RepairName))
|
||||
return new();
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.RepairName.Contains(Model.RepairName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public RepairViewModel? GetElement(RepairSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.RepairName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.RepairName) && x.RepairName == Model.RepairName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Insert(RepairBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var NewRepair = Repair.Create(Context, Model);
|
||||
if (NewRepair == null)
|
||||
return null;
|
||||
|
||||
Context.Repairs.Add(NewRepair);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewRepair.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Update(RepairBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
using var Transaction = Context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var Repair = Context.Repairs.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Repair == null)
|
||||
return null;
|
||||
|
||||
Repair.Update(Model);
|
||||
Context.SaveChanges();
|
||||
Repair.UpdateComponents(Context, Model);
|
||||
|
||||
Transaction.Commit();
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public RepairViewModel? Delete(RepairBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Repair = Context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Repair == null)
|
||||
return null;
|
||||
|
||||
Context.Repairs.Remove(Repair);
|
||||
Context.SaveChanges();
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
221
AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs
Normal file
221
AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs
Normal file
@@ -0,0 +1,221 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
return Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName))
|
||||
return new();
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.Where(x => x.ShopName.Contains(Model.ShopName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName) && !Model.Id.HasValue)
|
||||
return new();
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.ShopName) && x.ShopName == Model.ShopName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var NewShop = Shop.Create(Context, Model);
|
||||
if (NewShop == null)
|
||||
return null;
|
||||
|
||||
Context.Shops.Add(NewShop);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
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.UpdateRepairs(Context, Model);
|
||||
|
||||
Transaction.Commit();
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Shop = Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Shop == null)
|
||||
return null;
|
||||
|
||||
Context.Shops.Remove(Shop);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool Sell(SupplySearchModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
var Transaction = Context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var ShopsWithDesiredRepair = Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.ToList()
|
||||
.Where(x => x.ShopRepairs.ContainsKey(Model.RepairId.Value))
|
||||
.OrderByDescending(x => x.ShopRepairs[Model.RepairId.Value].Item2)
|
||||
.ToList();
|
||||
|
||||
foreach (var Shop in ShopsWithDesiredRepair)
|
||||
{
|
||||
int Slack = Model.Count.Value - Shop.ShopRepairs[Model.RepairId.Value].Item2;
|
||||
|
||||
if (Slack > 0)
|
||||
{
|
||||
Shop.ShopRepairs.Remove(Model.RepairId.Value);
|
||||
Shop.RepairsDictionatyUpdate(Context);
|
||||
Context.SaveChanges();
|
||||
|
||||
Model.Count = Slack;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Slack == 0)
|
||||
{
|
||||
Shop.ShopRepairs.Remove(Model.RepairId.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var RepairAndCount = Shop.ShopRepairs[Model.RepairId.Value];
|
||||
RepairAndCount.Item2 = -Slack;
|
||||
Shop.ShopRepairs[Model.RepairId.Value] = RepairAndCount;
|
||||
}
|
||||
|
||||
Shop.RepairsDictionatyUpdate(Context);
|
||||
Transaction.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public bool RestockingShops(SupplyBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
var Transaction = Context.Database.BeginTransaction();
|
||||
|
||||
var Shops = Context.Shops
|
||||
.Include(x => x.Repairs)
|
||||
.ThenInclude(x => x.Repair)
|
||||
.ToList()
|
||||
.Where(x => x.RepairsMaxCount > x.ShopRepairs
|
||||
.Select(x => x.Value.Item2).Sum())
|
||||
.ToList();
|
||||
|
||||
try
|
||||
{
|
||||
foreach (Shop Shop in Shops)
|
||||
{
|
||||
int FreeSpaceNum = Shop.RepairsMaxCount - Shop.ShopRepairs.Select(x => x.Value.Item2).Sum();
|
||||
|
||||
int Refill = Math.Min(FreeSpaceNum, Model.Count);
|
||||
Model.Count -= Refill;
|
||||
|
||||
if (Shop.ShopRepairs.ContainsKey(Model.RepairId))
|
||||
{
|
||||
var RepairAndCount = Shop.ShopRepairs[Model.RepairId];
|
||||
RepairAndCount.Item2 += Refill;
|
||||
Shop.ShopRepairs[Model.RepairId] = RepairAndCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
var Repair = Context.Repairs.First(x => x.Id == Model.RepairId);
|
||||
Shop.ShopRepairs.Add(Model.RepairId, (Repair, Refill));
|
||||
}
|
||||
|
||||
Shop.RepairsDictionatyUpdate(Context);
|
||||
|
||||
if (Model.Count == 0)
|
||||
{
|
||||
Transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
248
AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.Designer.cs
generated
Normal file
248
AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.Designer.cs
generated
Normal file
@@ -0,0 +1,248 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AutoWorkshopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(AutoWorkshopDatabase))]
|
||||
[Migration("20240417061857_Shops")]
|
||||
partial class Shops
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("RepairName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Repairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairsMaxCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopRepairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("RepairComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany()
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Repairs")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Repairs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
185
AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.cs
Normal file
185
AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Shops : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ComponentName = table.Column<string>(type: "text", nullable: false),
|
||||
Cost = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Repairs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairName = table.Column<string>(type: "text", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Repairs", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ShopName = table.Column<string>(type: "text", nullable: false),
|
||||
Address = table.Column<string>(type: "text", nullable: false),
|
||||
OpeningDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
RepairsMaxCount = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Repairs_RepairId",
|
||||
column: x => x.RepairId,
|
||||
principalTable: "Repairs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "RepairComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairId = table.Column<int>(type: "integer", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_RepairComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_RepairComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_RepairComponents_Repairs_RepairId",
|
||||
column: x => x.RepairId,
|
||||
principalTable: "Repairs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopRepairs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairId = table.Column<int>(type: "integer", nullable: false),
|
||||
ShopId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopRepairs", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopRepairs_Repairs_RepairId",
|
||||
column: x => x.RepairId,
|
||||
principalTable: "Repairs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopRepairs_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_RepairId",
|
||||
table: "Orders",
|
||||
column: "RepairId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_RepairComponents_ComponentId",
|
||||
table: "RepairComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_RepairComponents_RepairId",
|
||||
table: "RepairComponents",
|
||||
column: "RepairId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopRepairs_RepairId",
|
||||
table: "ShopRepairs",
|
||||
column: "RepairId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopRepairs_ShopId",
|
||||
table: "ShopRepairs",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "RepairComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopRepairs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Repairs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
||||
250
AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.Designer.cs
generated
Normal file
250
AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.Designer.cs
generated
Normal file
@@ -0,0 +1,250 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AutoWorkshopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(AutoWorkshopDatabase))]
|
||||
[Migration("20240505173724_Fix Shop-Repair relationship")]
|
||||
partial class FixShopRepairrelationship
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("RepairName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Repairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairsMaxCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopRepairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("RepairComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Shops")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Repairs")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Repairs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FixShopRepairrelationship : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AutoWorkshopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(AutoWorkshopDatabase))]
|
||||
partial class AutoWorkshopDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("RepairName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Repairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairsMaxCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopRepairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("RepairComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
|
||||
{
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Shops")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AutoWorkshopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Repairs")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Repairs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
61
AutoWorkshopDatabaseImplement/Models/Component.cs
Normal file
61
AutoWorkshopDatabaseImplement/Models/Component.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.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<RepairComponent> RepairComponents { 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
|
||||
};
|
||||
}
|
||||
}
|
||||
70
AutoWorkshopDatabaseImplement/Models/Order.cs
Normal file
70
AutoWorkshopDatabaseImplement/Models/Order.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int RepairId { get; private set; }
|
||||
|
||||
public virtual Repair Repair { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Undefined;
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Order()
|
||||
{
|
||||
Id = Model.Id,
|
||||
RepairId = Model.RepairId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
DateCreate = Model.DateCreate,
|
||||
DateImplement = Model.DateImplement,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
Status = Model.Status;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
RepairId = RepairId,
|
||||
RepairName = Repair.RepairName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
}
|
||||
}
|
||||
109
AutoWorkshopDatabaseImplement/Models/Repair.cs
Normal file
109
AutoWorkshopDatabaseImplement/Models/Repair.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Repair : IRepairModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string RepairName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _repairComponents = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> RepairComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_repairComponents == null)
|
||||
{
|
||||
_repairComponents = Components.ToDictionary(RepComp => RepComp.ComponentId, RepComp =>
|
||||
(RepComp.Component as IComponentModel, RepComp.Count));
|
||||
}
|
||||
|
||||
return _repairComponents;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("RepairId")]
|
||||
public virtual List<RepairComponent> Components { get; set; } = new();
|
||||
|
||||
[ForeignKey("RepairId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
[ForeignKey("RepairId")]
|
||||
public virtual List<ShopRepair> Shops { get; set; } = new();
|
||||
|
||||
public static Repair Create(AutoWorkshopDatabase Context, RepairBindingModel Model)
|
||||
{
|
||||
return new Repair()
|
||||
{
|
||||
Id = Model.Id,
|
||||
RepairName = Model.RepairName,
|
||||
Price = Model.Price,
|
||||
Components = Model.RepairComponents.Select(x => new RepairComponent
|
||||
{
|
||||
Component = Context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(RepairBindingModel Model)
|
||||
{
|
||||
RepairName = Model.RepairName;
|
||||
Price = Model.Price;
|
||||
}
|
||||
|
||||
public RepairViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
RepairName = RepairName,
|
||||
Price = Price,
|
||||
RepairComponents = RepairComponents
|
||||
};
|
||||
|
||||
public void UpdateComponents(AutoWorkshopDatabase Context, RepairBindingModel Model)
|
||||
{
|
||||
var RepairComponents = Context.RepairComponents.Where(rec => rec.RepairId == Model.Id).ToList();
|
||||
|
||||
if (RepairComponents != null && RepairComponents.Count > 0)
|
||||
{
|
||||
Context.RepairComponents.RemoveRange(RepairComponents.Where(rec => !Model.RepairComponents.ContainsKey(rec.ComponentId)));
|
||||
Context.SaveChanges();
|
||||
|
||||
foreach (var ComponentToUpdate in RepairComponents)
|
||||
{
|
||||
ComponentToUpdate.Count = Model.RepairComponents[ComponentToUpdate.ComponentId].Item2;
|
||||
Model.RepairComponents.Remove(ComponentToUpdate.ComponentId);
|
||||
}
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
var Repair = Context.Repairs.First(x => x.Id == Id);
|
||||
|
||||
foreach (var RepairComponent in Model.RepairComponents)
|
||||
{
|
||||
Context.RepairComponents.Add(new RepairComponent
|
||||
{
|
||||
Repair = Repair,
|
||||
Component = Context.Components.First(x => x.Id == RepairComponent.Key),
|
||||
Count = RepairComponent.Value.Item2
|
||||
});
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
_repairComponents = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
AutoWorkshopDatabaseImplement/Models/RepairComponent.cs
Normal file
22
AutoWorkshopDatabaseImplement/Models/RepairComponent.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class RepairComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int RepairId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Component Component { get; set; } = new();
|
||||
|
||||
public virtual Repair Repair { get; set; } = new();
|
||||
}
|
||||
}
|
||||
131
AutoWorkshopDatabaseImplement/Models/Shop.cs
Normal file
131
AutoWorkshopDatabaseImplement/Models/Shop.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
[Required]
|
||||
public int RepairsMaxCount { get; set; }
|
||||
|
||||
[ForeignKey("ShopId")]
|
||||
public List<ShopRepair> Repairs { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (IRepairModel, int)>? _shopRepairs = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopRepairs == null)
|
||||
{
|
||||
if (_shopRepairs == null)
|
||||
{
|
||||
_shopRepairs = Repairs.ToDictionary(ShopRep => ShopRep.RepairId, ShopRep => (ShopRep.Repair as IRepairModel, ShopRep.Count));
|
||||
}
|
||||
return _shopRepairs;
|
||||
}
|
||||
|
||||
return _shopRepairs;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop Create(AutoWorkshopDatabase Context, ShopBindingModel Model)
|
||||
{
|
||||
return new Shop()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ShopName = Model.ShopName,
|
||||
Address = Model.Address,
|
||||
OpeningDate = Model.OpeningDate,
|
||||
Repairs = Model.ShopRepairs.Select(x => new ShopRepair
|
||||
{
|
||||
Repair = Context.Repairs.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
RepairsMaxCount = Model.RepairsMaxCount
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel Model)
|
||||
{
|
||||
ShopName = Model.ShopName;
|
||||
Address = Model.Address;
|
||||
OpeningDate = Model.OpeningDate;
|
||||
RepairsMaxCount = Model.RepairsMaxCount;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopRepairs = ShopRepairs,
|
||||
RepairsMaxCount = RepairsMaxCount
|
||||
};
|
||||
|
||||
public void UpdateRepairs(AutoWorkshopDatabase Context, ShopBindingModel Model)
|
||||
{
|
||||
var ShopRepairs = Context.ShopRepairs
|
||||
.Where(rec => rec.ShopId == Model.Id)
|
||||
.ToList();
|
||||
|
||||
if (ShopRepairs != null && ShopRepairs.Count > 0)
|
||||
{
|
||||
Context.ShopRepairs.RemoveRange(ShopRepairs.Where(rec => !Model.ShopRepairs.ContainsKey(rec.RepairId)));
|
||||
Context.SaveChanges();
|
||||
|
||||
ShopRepairs = Context.ShopRepairs.Where(rec => rec.ShopId == Model.Id).ToList();
|
||||
|
||||
foreach (var RepairToUpdate in ShopRepairs)
|
||||
{
|
||||
RepairToUpdate.Count = Model.ShopRepairs[RepairToUpdate.RepairId].Item2;
|
||||
Model.ShopRepairs.Remove(RepairToUpdate.RepairId);
|
||||
}
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
var Shop = Context.Shops.First(x => x.Id == Id);
|
||||
|
||||
foreach (var ShopRepair in Model.ShopRepairs)
|
||||
{
|
||||
Context.ShopRepairs.Add(new ShopRepair
|
||||
{
|
||||
Shop = Shop,
|
||||
Repair = Context.Repairs.First(x => x.Id == ShopRepair.Key),
|
||||
Count = ShopRepair.Value.Item2
|
||||
});
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
_shopRepairs = null;
|
||||
}
|
||||
|
||||
public void RepairsDictionatyUpdate(AutoWorkshopDatabase Context)
|
||||
{
|
||||
UpdateRepairs(Context, new ShopBindingModel
|
||||
{
|
||||
Id = Id,
|
||||
ShopRepairs = ShopRepairs
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
22
AutoWorkshopDatabaseImplement/Models/ShopRepair.cs
Normal file
22
AutoWorkshopDatabaseImplement/Models/ShopRepair.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class ShopRepair
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int RepairId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Shop Shop { get; set; } = new();
|
||||
|
||||
public virtual Repair Repair { get; set; } = new();
|
||||
}
|
||||
}
|
||||
14
AutoWorkshopFileImplement/AutoWorkshopFileImplement.csproj
Normal file
14
AutoWorkshopFileImplement/AutoWorkshopFileImplement.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
|
||||
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
61
AutoWorkshopFileImplement/DataFileSingleton.cs
Normal file
61
AutoWorkshopFileImplement/DataFileSingleton.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutoWorkshopFileImplement
|
||||
{
|
||||
public class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? _instance;
|
||||
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string RepairFileName = "Repair.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Repair> Repairs { get; private set; }
|
||||
public List<Shop> Shops { get; private set; }
|
||||
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Repairs = LoadData(RepairFileName, "Repair", x => Repair.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
}
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataFileSingleton();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SaveRepairs() => SaveData(Repairs, RepairFileName, "Repairs", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
|
||||
private static List<T>? LoadData<T>(string FileName, string XmlNodeName, Func<XElement, T> SelectFunction)
|
||||
{
|
||||
if (File.Exists(FileName))
|
||||
{
|
||||
return XDocument.Load(FileName)?.Root?.Elements(XmlNodeName)?.Select(SelectFunction)?.ToList();
|
||||
}
|
||||
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
private static void SaveData<T>(List<T> Data, string FileName, string XmlNodeName, Func<T, XElement> SelectFunction)
|
||||
{
|
||||
if (Data != null)
|
||||
{
|
||||
new XDocument(new XElement(XmlNodeName, Data.Select(SelectFunction).ToArray())).Save(FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
AutoWorkshopFileImplement/Implements/ComponentStorage.cs
Normal file
82
AutoWorkshopFileImplement/Implements/ComponentStorage.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public ComponentStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
return _source.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ComponentName))
|
||||
return new();
|
||||
|
||||
return _source.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;
|
||||
|
||||
return _source.Components.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(Model.ComponentName) && x.ComponentName == Model.ComponentName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel Model)
|
||||
{
|
||||
Model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var NewComponent = Component.Create(Model);
|
||||
|
||||
if (NewComponent == null)
|
||||
return null;
|
||||
|
||||
_source.Components.Add(NewComponent);
|
||||
_source.SaveComponents();
|
||||
|
||||
return NewComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel Model)
|
||||
{
|
||||
var Component = _source.Components.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Component == null)
|
||||
return null;
|
||||
|
||||
Component.Update(Model);
|
||||
_source.SaveComponents();
|
||||
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel Model)
|
||||
{
|
||||
var Component = _source.Components.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Component == null)
|
||||
return null;
|
||||
|
||||
_source.Components.Remove(Component);
|
||||
_source.SaveComponents();
|
||||
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
AutoWorkshopFileImplement/Implements/OrderStorage.cs
Normal file
96
AutoWorkshopFileImplement/Implements/OrderStorage.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
using System.Reflection;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return _source.Orders.Select(x => AddRepairName(x.GetViewModel)).ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return new();
|
||||
|
||||
return _source.Orders.Where(x => x.Id == Model.Id).Select(x => AddRepairName(x.GetViewModel)).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
var Element = _source.Orders.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Element != null)
|
||||
{
|
||||
_source.Orders.Remove(Element);
|
||||
_source.SaveOrders();
|
||||
|
||||
return AddRepairName(Element.GetViewModel);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
var Order = _source.Orders.FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id));
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
return AddRepairName(Order.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
||||
{
|
||||
Model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var NewOrder = Order.Create(Model);
|
||||
|
||||
if (NewOrder == null)
|
||||
return null;
|
||||
|
||||
_source.Orders.Add(NewOrder);
|
||||
_source.SaveOrders();
|
||||
|
||||
return AddRepairName(NewOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
{
|
||||
var Order = _source.Orders.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
Order.Update(Model);
|
||||
_source.SaveOrders();
|
||||
|
||||
return AddRepairName(Order.GetViewModel);
|
||||
}
|
||||
|
||||
private OrderViewModel AddRepairName(OrderViewModel Model)
|
||||
{
|
||||
var SelectedRepair = _source.Repairs.FirstOrDefault(x => x.Id == Model.RepairId);
|
||||
|
||||
Model.RepairName = SelectedRepair?.RepairName ?? string.Empty;
|
||||
return Model;
|
||||
}
|
||||
}
|
||||
}
|
||||
80
AutoWorkshopFileImplement/Implements/RepairStorage.cs
Normal file
80
AutoWorkshopFileImplement/Implements/RepairStorage.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Implements
|
||||
{
|
||||
public class RepairStorage : IRepairStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public RepairStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<RepairViewModel> GetFullList()
|
||||
{
|
||||
return _source.Repairs.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<RepairViewModel> GetFilteredList(RepairSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.RepairName))
|
||||
return new();
|
||||
|
||||
return _source.Repairs.Where(x => x.RepairName.Contains(Model.RepairName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public RepairViewModel? GetElement(RepairSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.RepairName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
return _source.Repairs.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.RepairName) && x.RepairName == Model.RepairName) || (Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Insert(RepairBindingModel Model)
|
||||
{
|
||||
Model.Id = _source.Repairs.Count > 0 ? _source.Repairs.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var NewRepair = Repair.Create(Model);
|
||||
|
||||
if (NewRepair == null)
|
||||
return null;
|
||||
|
||||
_source.Repairs.Add(NewRepair);
|
||||
_source.SaveRepairs();
|
||||
|
||||
return NewRepair.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Update(RepairBindingModel Model)
|
||||
{
|
||||
var Repair = _source.Repairs.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Repair == null)
|
||||
return null;
|
||||
|
||||
Repair.Update(Model);
|
||||
_source.SaveRepairs();
|
||||
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
|
||||
public RepairViewModel? Delete(RepairBindingModel Model)
|
||||
{
|
||||
var Repair = _source.Repairs.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Repair == null)
|
||||
return null;
|
||||
|
||||
_source.Repairs.Remove(Repair);
|
||||
_source.SaveRepairs();
|
||||
|
||||
return Repair.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
168
AutoWorkshopFileImplement/Implements/ShopStorage.cs
Normal file
168
AutoWorkshopFileImplement/Implements/ShopStorage.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopFileImplement.Models;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public ShopStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return _source.Shops.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName))
|
||||
return new();
|
||||
|
||||
return _source.Shops
|
||||
.Where(x => x.ShopName
|
||||
.Contains(Model.ShopName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ShopName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
return _source.Shops.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(Model.ShopName) && x.ShopName == Model.ShopName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel Model)
|
||||
{
|
||||
Model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var NewShop = Shop.Create(Model);
|
||||
if (NewShop == null)
|
||||
return null;
|
||||
|
||||
_source.Shops.Add(NewShop);
|
||||
_source.SaveShops();
|
||||
|
||||
return NewShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel Model)
|
||||
{
|
||||
var Shop = _source.Shops.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Shop == null)
|
||||
return null;
|
||||
|
||||
Shop.Update(Model);
|
||||
_source.SaveShops();
|
||||
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel Model)
|
||||
{
|
||||
var Shop = _source.Shops.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Shop == null)
|
||||
return null;
|
||||
|
||||
_source.Shops.Remove(Shop);
|
||||
_source.SaveShops();
|
||||
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool Sell(SupplySearchModel Model)
|
||||
{
|
||||
if (Model == null || !Model.RepairId.HasValue || !Model.Count.HasValue)
|
||||
return false;
|
||||
|
||||
int TotalRepairsNum = _source.Shops
|
||||
.Select(x => x.Repairs.ContainsKey(Model.RepairId.Value) ? x.Repairs[Model.RepairId.Value] : 0)
|
||||
.Sum();
|
||||
if (TotalRepairsNum < Model.Count)
|
||||
return false;
|
||||
|
||||
var ShopsWithDesiredRepair = _source.Shops
|
||||
.Where(x => x.Repairs.ContainsKey(Model.RepairId.Value))
|
||||
.OrderByDescending(x => x.Repairs[Model.RepairId.Value])
|
||||
.ToList();
|
||||
|
||||
foreach (var Shop in ShopsWithDesiredRepair)
|
||||
{
|
||||
int Slack = Model.Count.Value - Shop.Repairs[Model.RepairId.Value];
|
||||
|
||||
if (Slack > 0)
|
||||
{
|
||||
Shop.Repairs.Remove(Model.RepairId.Value);
|
||||
Shop.RepairsUpdate();
|
||||
|
||||
Model.Count = Slack;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Slack == 0)
|
||||
Shop.Repairs.Remove(Model.RepairId.Value);
|
||||
else
|
||||
Shop.Repairs[Model.RepairId.Value] = -Slack;
|
||||
|
||||
Shop.RepairsUpdate();
|
||||
_source.SaveShops();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
_source.SaveShops();
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool RestockingShops(SupplyBindingModel Model)
|
||||
{
|
||||
int TotalFreeSpaceNum = _source.Shops
|
||||
.Select(x => x.RepairsMaxCount - x.ShopRepairs
|
||||
.Select(y => y.Value.Item2)
|
||||
.Sum())
|
||||
.Sum();
|
||||
|
||||
if (TotalFreeSpaceNum < Model.Count)
|
||||
return false;
|
||||
|
||||
foreach (Shop Shop in _source.Shops)
|
||||
{
|
||||
int FreeSpaceNum = Shop.RepairsMaxCount - Shop.ShopRepairs.Select(x => x.Value.Item2).Sum();
|
||||
|
||||
if (FreeSpaceNum <= 0)
|
||||
continue;
|
||||
|
||||
FreeSpaceNum = Math.Min(FreeSpaceNum, Model.Count);
|
||||
Model.Count -= FreeSpaceNum;
|
||||
|
||||
if (Shop.Repairs.ContainsKey(Model.RepairId))
|
||||
Shop.Repairs[Model.RepairId] += FreeSpaceNum;
|
||||
else
|
||||
Shop.Repairs.Add(Model.RepairId, FreeSpaceNum);
|
||||
|
||||
Shop.RepairsUpdate();
|
||||
|
||||
if (Model.Count == 0)
|
||||
{
|
||||
_source.SaveShops();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
65
AutoWorkshopFileImplement/Models/Component.cs
Normal file
65
AutoWorkshopFileImplement/Models/Component.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
public double Cost { get; set; }
|
||||
|
||||
public static Component? Create(ComponentBindingModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ComponentName = Model.ComponentName,
|
||||
Cost = Model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Component? Create(XElement Element)
|
||||
{
|
||||
if (Element is null)
|
||||
return null;
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||
ComponentName = Element.Element("ComponentName")!.Value,
|
||||
Cost = Convert.ToDouble(Element.Element("Cost")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
ComponentName = Model.ComponentName;
|
||||
Cost = Model.Cost;
|
||||
}
|
||||
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Component",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ComponentName", ComponentName),
|
||||
new XElement("Cost", Cost.ToString())
|
||||
);
|
||||
}
|
||||
}
|
||||
90
AutoWorkshopFileImplement/Models/Order.cs
Normal file
90
AutoWorkshopFileImplement/Models/Order.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Enums;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int RepairId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; }
|
||||
|
||||
public DateTime DateCreate { get; private set; }
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Order()
|
||||
{
|
||||
Id = Model.Id,
|
||||
RepairId = Model.RepairId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
DateCreate = Model.DateCreate,
|
||||
DateImplement = Model.DateImplement
|
||||
};
|
||||
}
|
||||
|
||||
public static Order? Create(XElement Element)
|
||||
{
|
||||
if (Element is null)
|
||||
return null;
|
||||
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||
RepairId = Convert.ToInt32(Element.Element("RepairId")!.Value),
|
||||
Count = Convert.ToInt32(Element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(Element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), Element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(Element.Element("DateCreate")!.Value),
|
||||
DateImplement = string.IsNullOrEmpty(Element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(Element.Element("DateImplement")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
Status = Model.Status;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
RepairId = RepairId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("RepairId", RepairId),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
new XElement("DateCreate", DateCreate.ToString()),
|
||||
new XElement("DateImplement", DateImplement.ToString())
|
||||
);
|
||||
}
|
||||
}
|
||||
90
AutoWorkshopFileImplement/Models/Repair.cs
Normal file
90
AutoWorkshopFileImplement/Models/Repair.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Models
|
||||
{
|
||||
public class Repair : IRepairModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string RepairName { get; private set; } = string.Empty;
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Components { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _RepairComponents = null;
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> RepairComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_RepairComponents == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_RepairComponents = Components.ToDictionary(x =>
|
||||
x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
||||
}
|
||||
return _RepairComponents;
|
||||
}
|
||||
}
|
||||
|
||||
public static Repair? Create(RepairBindingModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Repair()
|
||||
{
|
||||
Id = Model.Id,
|
||||
RepairName = Model.RepairName,
|
||||
Price = Model.Price,
|
||||
Components = Model.RepairComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Repair? Create(XElement Element)
|
||||
{
|
||||
if (Element is null)
|
||||
return null;
|
||||
|
||||
return new Repair()
|
||||
{
|
||||
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||
RepairName = Element.Element("RepairName")!.Value,
|
||||
Price = Convert.ToDouble(Element.Element("Price")!.Value),
|
||||
Components = Element.Element("RepairComponents")!.Elements("RepairComponent").ToDictionary(x =>
|
||||
Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(RepairBindingModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
RepairName = Model.RepairName;
|
||||
Price = Model.Price;
|
||||
Components = Model.RepairComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_RepairComponents = null;
|
||||
}
|
||||
|
||||
public RepairViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
RepairName = RepairName,
|
||||
Price = Price,
|
||||
RepairComponents = RepairComponents
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Repair",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("RepairName", RepairName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("RepairComponents", Components.Select(x =>
|
||||
new XElement("RepairComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())
|
||||
);
|
||||
}
|
||||
}
|
||||
110
AutoWorkshopFileImplement/Models/Shop.cs
Normal file
110
AutoWorkshopFileImplement/Models/Shop.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutoWorkshopFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Repairs { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IRepairModel, int)>? _shopRepairs = null;
|
||||
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopRepairs == null)
|
||||
{
|
||||
var Source = DataFileSingleton.GetInstance();
|
||||
_shopRepairs = Repairs.ToDictionary(x => x.Key, y => ((Source.Repairs.FirstOrDefault(z => z.Id == y.Key) as IRepairModel)!, y.Value));
|
||||
}
|
||||
|
||||
return _shopRepairs;
|
||||
}
|
||||
}
|
||||
|
||||
public int RepairsMaxCount { get; private set; }
|
||||
|
||||
public static Shop? Create(ShopBindingModel? Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
return new Shop()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ShopName = Model.ShopName,
|
||||
Address = Model.Address,
|
||||
OpeningDate = Model.OpeningDate,
|
||||
Repairs = Model.ShopRepairs.ToDictionary(x => x.Key, x => x.Value.Item2),
|
||||
RepairsMaxCount = Model.RepairsMaxCount
|
||||
};
|
||||
}
|
||||
|
||||
public static Shop? Create(XElement Element)
|
||||
{
|
||||
if (Element == null)
|
||||
return null;
|
||||
|
||||
return new Shop()
|
||||
{
|
||||
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||
ShopName = Element.Element("ShopName")!.Value,
|
||||
Address = Element.Element("Address")!.Value,
|
||||
OpeningDate = Convert.ToDateTime(Element.Element("OpeningDate")!.Value),
|
||||
Repairs = Element.Element("ShopRepairs")!.Elements("ShopRepair")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value)),
|
||||
RepairsMaxCount = Convert.ToInt32(Element.Element("RepairsMaxCount")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel? Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return;
|
||||
|
||||
ShopName = Model.ShopName;
|
||||
Address = Model.Address;
|
||||
OpeningDate = Model.OpeningDate;
|
||||
RepairsMaxCount = Model.RepairsMaxCount;
|
||||
Repairs = Model.ShopRepairs.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopRepairs = null;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopRepairs = ShopRepairs,
|
||||
RepairsMaxCount = RepairsMaxCount
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("Address", Address),
|
||||
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||
new XElement("ShopRepairs", Repairs.Select(
|
||||
x => new XElement("ShopRepair", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()),
|
||||
new XElement("RepairsMaxCount", RepairsMaxCount.ToString())
|
||||
);
|
||||
|
||||
public void RepairsUpdate()
|
||||
{
|
||||
_shopRepairs = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,5 +108,15 @@ namespace AutoWorkshopListImplement.Implements
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Sell(SupplySearchModel Model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool RestockingShops(SupplyBindingModel Model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace AutoWorkshopListImplement.Models
|
||||
|
||||
public Dictionary<int, (IRepairModel, int)> ShopRepairs { get; private set; } = new();
|
||||
|
||||
public int RepairsMaxCount { get; private set; }
|
||||
|
||||
public static Shop? Create(ShopBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
@@ -26,7 +28,8 @@ namespace AutoWorkshopListImplement.Models
|
||||
Id = Model.Id,
|
||||
ShopName = Model.ShopName,
|
||||
Address = Model.Address,
|
||||
OpeningDate = Model.OpeningDate
|
||||
OpeningDate = Model.OpeningDate,
|
||||
RepairsMaxCount = Model.RepairsMaxCount,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,6 +41,7 @@ namespace AutoWorkshopListImplement.Models
|
||||
ShopName = Model.ShopName;
|
||||
Address = Model.Address;
|
||||
OpeningDate = Model.OpeningDate;
|
||||
RepairsMaxCount = Model.RepairsMaxCount;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
@@ -46,7 +50,8 @@ namespace AutoWorkshopListImplement.Models
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopRepairs = ShopRepairs
|
||||
ShopRepairs = ShopRepairs,
|
||||
RepairsMaxCount = RepairsMaxCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoWorkshopBusinessLogic\AutoWorkshopBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\AutoWorkshopImplement\AutoWorkshopListImplement.csproj" />
|
||||
<ProjectReference Include="..\AutoWorkshopDatabaseImplement\AutoWorkshopDatabaseImplement.csproj" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.2.8" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
|
||||
125
AutoWorkshopView/Forms/Shop/FormSellRepair.Designer.cs
generated
Normal file
125
AutoWorkshopView/Forms/Shop/FormSellRepair.Designer.cs
generated
Normal file
@@ -0,0 +1,125 @@
|
||||
namespace AutoWorkshopView.Forms.Shop
|
||||
{
|
||||
partial class FormSellRepair
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
RepairLabel = new Label();
|
||||
RepairComboBox = new ComboBox();
|
||||
CountLabel = new Label();
|
||||
CountTextBox = new TextBox();
|
||||
SellButton = new Button();
|
||||
CancelButton = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// RepairLabel
|
||||
//
|
||||
RepairLabel.AutoSize = true;
|
||||
RepairLabel.Location = new Point(10, 11);
|
||||
RepairLabel.Name = "RepairLabel";
|
||||
RepairLabel.Size = new Size(54, 15);
|
||||
RepairLabel.TabIndex = 0;
|
||||
RepairLabel.Text = "Ремонт: ";
|
||||
//
|
||||
// RepairComboBox
|
||||
//
|
||||
RepairComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
RepairComboBox.FormattingEnabled = true;
|
||||
RepairComboBox.Location = new Point(94, 8);
|
||||
RepairComboBox.Margin = new Padding(3, 2, 3, 2);
|
||||
RepairComboBox.Name = "RepairComboBox";
|
||||
RepairComboBox.Size = new Size(217, 23);
|
||||
RepairComboBox.TabIndex = 1;
|
||||
//
|
||||
// CountLabel
|
||||
//
|
||||
CountLabel.AutoSize = true;
|
||||
CountLabel.Location = new Point(10, 41);
|
||||
CountLabel.Name = "CountLabel";
|
||||
CountLabel.Size = new Size(78, 15);
|
||||
CountLabel.TabIndex = 2;
|
||||
CountLabel.Text = "Количество: ";
|
||||
//
|
||||
// CountTextBox
|
||||
//
|
||||
CountTextBox.Location = new Point(94, 39);
|
||||
CountTextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
CountTextBox.Name = "CountTextBox";
|
||||
CountTextBox.Size = new Size(217, 23);
|
||||
CountTextBox.TabIndex = 3;
|
||||
//
|
||||
// SellButton
|
||||
//
|
||||
SellButton.Location = new Point(117, 77);
|
||||
SellButton.Margin = new Padding(3, 2, 3, 2);
|
||||
SellButton.Name = "SellButton";
|
||||
SellButton.Size = new Size(92, 30);
|
||||
SellButton.TabIndex = 4;
|
||||
SellButton.Text = "Продать";
|
||||
SellButton.UseVisualStyleBackColor = true;
|
||||
SellButton.Click += SellButton_Click;
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(215, 77);
|
||||
CancelButton.Margin = new Padding(3, 2, 3, 2);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(96, 30);
|
||||
CancelButton.TabIndex = 5;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
CancelButton.Click += ButtonCancel_Click;
|
||||
//
|
||||
// FormSellRepair
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(325, 122);
|
||||
Controls.Add(CancelButton);
|
||||
Controls.Add(SellButton);
|
||||
Controls.Add(CountTextBox);
|
||||
Controls.Add(CountLabel);
|
||||
Controls.Add(RepairComboBox);
|
||||
Controls.Add(RepairLabel);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormSellRepair";
|
||||
Text = "Продажа ремонтов";
|
||||
Load += FormSellRepair_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label RepairLabel;
|
||||
private ComboBox RepairComboBox;
|
||||
private Label CountLabel;
|
||||
private TextBox CountTextBox;
|
||||
private Button SellButton;
|
||||
private Button CancelButton;
|
||||
}
|
||||
}
|
||||
87
AutoWorkshopView/Forms/Shop/FormSellRepair.cs
Normal file
87
AutoWorkshopView/Forms/Shop/FormSellRepair.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopView.Forms.Shop
|
||||
{
|
||||
public partial class FormSellRepair : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IRepairLogic _repairLogic;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
|
||||
private List<RepairViewModel> _repairList = new List<RepairViewModel>();
|
||||
|
||||
public FormSellRepair(ILogger<FormSellRepair> Logger, IRepairLogic RepairLogic, IShopLogic ShopLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_repairLogic = RepairLogic;
|
||||
_shopLogic = ShopLogic;
|
||||
}
|
||||
|
||||
private void FormSellRepair_Load(object sender, EventArgs e)
|
||||
{
|
||||
_repairList = _repairLogic.ReadList(null);
|
||||
|
||||
if (_repairList != null)
|
||||
{
|
||||
RepairComboBox.DisplayMember = "RepairName";
|
||||
RepairComboBox.ValueMember = "Id";
|
||||
RepairComboBox.DataSource = _repairList;
|
||||
RepairComboBox.SelectedItem = null;
|
||||
|
||||
_logger.LogInformation("Загрузка ремонтов для продажи");
|
||||
}
|
||||
}
|
||||
|
||||
private void SellButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (RepairComboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите ремонт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Создание покупки");
|
||||
|
||||
try
|
||||
{
|
||||
bool Result = _shopLogic.MakeSell(new SupplySearchModel
|
||||
{
|
||||
RepairId = Convert.ToInt32(RepairComboBox.SelectedValue),
|
||||
Count = Convert.ToInt32(CountTextBox.Text)
|
||||
});
|
||||
|
||||
if (Result)
|
||||
{
|
||||
_logger.LogInformation("Проверка пройдена, продажа проведена");
|
||||
MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Проверка не пройдена");
|
||||
MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
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
AutoWorkshopView/Forms/Shop/FormSellRepair.resx
Normal file
120
AutoWorkshopView/Forms/Shop/FormSellRepair.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>
|
||||
62
AutoWorkshopView/Forms/Shop/FormShop.Designer.cs
generated
62
AutoWorkshopView/Forms/Shop/FormShop.Designer.cs
generated
@@ -40,13 +40,16 @@
|
||||
CountColumn = new DataGridViewTextBoxColumn();
|
||||
OpeningDateLabel = new Label();
|
||||
OpenDateTimePicker = new DateTimePicker();
|
||||
RepairsMaxCountLabel = new Label();
|
||||
RepairsMaxCountNumericUp = new NumericUpDown();
|
||||
((System.ComponentModel.ISupportInitialize)ViewDataGrid).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)RepairsMaxCountNumericUp).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// NameLabel
|
||||
//
|
||||
NameLabel.AutoSize = true;
|
||||
NameLabel.Location = new Point(10, 12);
|
||||
NameLabel.Location = new Point(9, 9);
|
||||
NameLabel.Name = "NameLabel";
|
||||
NameLabel.Size = new Size(65, 15);
|
||||
NameLabel.TabIndex = 0;
|
||||
@@ -54,24 +57,24 @@
|
||||
//
|
||||
// NameTextBox
|
||||
//
|
||||
NameTextBox.Location = new Point(112, 9);
|
||||
NameTextBox.Location = new Point(105, 6);
|
||||
NameTextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
NameTextBox.Name = "NameTextBox";
|
||||
NameTextBox.Size = new Size(240, 23);
|
||||
NameTextBox.Size = new Size(210, 23);
|
||||
NameTextBox.TabIndex = 1;
|
||||
//
|
||||
// AddressTextBox
|
||||
//
|
||||
AddressTextBox.Location = new Point(112, 36);
|
||||
AddressTextBox.Location = new Point(105, 33);
|
||||
AddressTextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
AddressTextBox.Name = "AddressTextBox";
|
||||
AddressTextBox.Size = new Size(240, 23);
|
||||
AddressTextBox.Size = new Size(210, 23);
|
||||
AddressTextBox.TabIndex = 3;
|
||||
//
|
||||
// AddressLabel
|
||||
//
|
||||
AddressLabel.AutoSize = true;
|
||||
AddressLabel.Location = new Point(12, 39);
|
||||
AddressLabel.Location = new Point(10, 36);
|
||||
AddressLabel.Name = "AddressLabel";
|
||||
AddressLabel.Size = new Size(46, 15);
|
||||
AddressLabel.TabIndex = 2;
|
||||
@@ -79,10 +82,10 @@
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(395, 343);
|
||||
CancelButton.Location = new Point(345, 302);
|
||||
CancelButton.Margin = new Padding(3, 2, 3, 2);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(114, 33);
|
||||
CancelButton.Size = new Size(100, 25);
|
||||
CancelButton.TabIndex = 5;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
@@ -90,10 +93,10 @@
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(276, 343);
|
||||
SaveButton.Location = new Point(239, 302);
|
||||
SaveButton.Margin = new Padding(3, 2, 3, 2);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(114, 33);
|
||||
SaveButton.Size = new Size(100, 25);
|
||||
SaveButton.TabIndex = 6;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
@@ -106,14 +109,14 @@
|
||||
ViewDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
ViewDataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
ViewDataGrid.Columns.AddRange(new DataGridViewColumn[] { IdColumn, RepairNameColumn, CountColumn });
|
||||
ViewDataGrid.Location = new Point(10, 108);
|
||||
ViewDataGrid.Location = new Point(9, 126);
|
||||
ViewDataGrid.Margin = new Padding(3, 2, 3, 2);
|
||||
ViewDataGrid.Name = "ViewDataGrid";
|
||||
ViewDataGrid.ReadOnly = true;
|
||||
ViewDataGrid.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
|
||||
ViewDataGrid.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
|
||||
ViewDataGrid.RowTemplate.Height = 29;
|
||||
ViewDataGrid.Size = new Size(498, 230);
|
||||
ViewDataGrid.Size = new Size(436, 172);
|
||||
ViewDataGrid.TabIndex = 7;
|
||||
//
|
||||
// IdColumn
|
||||
@@ -141,25 +144,45 @@
|
||||
// OpeningDateLabel
|
||||
//
|
||||
OpeningDateLabel.AutoSize = true;
|
||||
OpeningDateLabel.Location = new Point(10, 69);
|
||||
OpeningDateLabel.Location = new Point(9, 63);
|
||||
OpeningDateLabel.Name = "OpeningDateLabel";
|
||||
OpeningDateLabel.Size = new Size(87, 15);
|
||||
OpeningDateLabel.Size = new Size(90, 15);
|
||||
OpeningDateLabel.TabIndex = 8;
|
||||
OpeningDateLabel.Text = "Дата открытия";
|
||||
OpeningDateLabel.Text = "Дата открытия:";
|
||||
//
|
||||
// OpenDateTimePicker
|
||||
//
|
||||
OpenDateTimePicker.Location = new Point(112, 63);
|
||||
OpenDateTimePicker.Location = new Point(105, 60);
|
||||
OpenDateTimePicker.Margin = new Padding(3, 2, 3, 2);
|
||||
OpenDateTimePicker.Name = "OpenDateTimePicker";
|
||||
OpenDateTimePicker.Size = new Size(240, 23);
|
||||
OpenDateTimePicker.Size = new Size(210, 23);
|
||||
OpenDateTimePicker.TabIndex = 9;
|
||||
//
|
||||
// RepairsMaxCountLabel
|
||||
//
|
||||
RepairsMaxCountLabel.AutoSize = true;
|
||||
RepairsMaxCountLabel.Location = new Point(9, 90);
|
||||
RepairsMaxCountLabel.Name = "RepairsMaxCountLabel";
|
||||
RepairsMaxCountLabel.Size = new Size(83, 15);
|
||||
RepairsMaxCountLabel.TabIndex = 10;
|
||||
RepairsMaxCountLabel.Text = "Вместимость:";
|
||||
//
|
||||
// RepairsMaxCountNumericUp
|
||||
//
|
||||
RepairsMaxCountNumericUp.Location = new Point(105, 87);
|
||||
RepairsMaxCountNumericUp.Margin = new Padding(3, 2, 3, 2);
|
||||
RepairsMaxCountNumericUp.Maximum = new decimal(new int[] { 10000, 0, 0, 0 });
|
||||
RepairsMaxCountNumericUp.Name = "RepairsMaxCountNumericUp";
|
||||
RepairsMaxCountNumericUp.Size = new Size(210, 23);
|
||||
RepairsMaxCountNumericUp.TabIndex = 11;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(519, 385);
|
||||
ClientSize = new Size(460, 340);
|
||||
Controls.Add(RepairsMaxCountNumericUp);
|
||||
Controls.Add(RepairsMaxCountLabel);
|
||||
Controls.Add(OpenDateTimePicker);
|
||||
Controls.Add(OpeningDateLabel);
|
||||
Controls.Add(ViewDataGrid);
|
||||
@@ -174,6 +197,7 @@
|
||||
Text = "Магазин";
|
||||
Load += FormShop_Load;
|
||||
((System.ComponentModel.ISupportInitialize)ViewDataGrid).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)RepairsMaxCountNumericUp).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@@ -192,5 +216,7 @@
|
||||
private DataGridViewTextBoxColumn CountColumn;
|
||||
private Label OpeningDateLabel;
|
||||
private DateTimePicker OpenDateTimePicker;
|
||||
private Label RepairsMaxCountLabel;
|
||||
private NumericUpDown RepairsMaxCountNumericUp;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AutoWorkshopView.Forms.Shop
|
||||
{
|
||||
@@ -45,6 +46,7 @@ namespace AutoWorkshopView.Forms.Shop
|
||||
NameTextBox.Text = View.ShopName;
|
||||
AddressTextBox.Text = View.Address;
|
||||
OpenDateTimePicker.Value = View.OpeningDate;
|
||||
RepairsMaxCountNumericUp.Value = View.RepairsMaxCount;
|
||||
_shopRepairs = View.ShopRepairs ?? new Dictionary<int, (IRepairModel, int)>();
|
||||
|
||||
LoadData();
|
||||
@@ -103,7 +105,8 @@ namespace AutoWorkshopView.Forms.Shop
|
||||
Id = _id ?? 0,
|
||||
ShopName = NameTextBox.Text,
|
||||
Address = AddressTextBox.Text,
|
||||
OpeningDate = OpenDateTimePicker.Value
|
||||
OpeningDate = OpenDateTimePicker.Value,
|
||||
RepairsMaxCount = (int)RepairsMaxCountNumericUp.Value,
|
||||
};
|
||||
|
||||
var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model);
|
||||
|
||||
11
AutoWorkshopView/MainForm.Designer.cs
generated
11
AutoWorkshopView/MainForm.Designer.cs
generated
@@ -35,6 +35,7 @@
|
||||
ShopsToolStripMenuItem = new ToolStripMenuItem();
|
||||
OperationToolStripMenuItem = new ToolStripMenuItem();
|
||||
TransactionToolStripMenuItem = new ToolStripMenuItem();
|
||||
SaleToolStripMenuItem = new ToolStripMenuItem();
|
||||
DataGridView = new DataGridView();
|
||||
CreateOrderButton = new Button();
|
||||
TakeInWorkButton = new Button();
|
||||
@@ -86,7 +87,7 @@
|
||||
//
|
||||
// OperationToolStripMenuItem
|
||||
//
|
||||
OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransactionToolStripMenuItem });
|
||||
OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransactionToolStripMenuItem, SaleToolStripMenuItem });
|
||||
OperationToolStripMenuItem.Name = "OperationToolStripMenuItem";
|
||||
OperationToolStripMenuItem.Size = new Size(75, 20);
|
||||
OperationToolStripMenuItem.Text = "Операции";
|
||||
@@ -165,6 +166,13 @@
|
||||
RefreshButton.UseVisualStyleBackColor = true;
|
||||
RefreshButton.Click += RefreshButton_Click;
|
||||
//
|
||||
// SaleToolStripMenuItem
|
||||
//
|
||||
SaleToolStripMenuItem.Name = "SaleToolStripMenuItem";
|
||||
SaleToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
SaleToolStripMenuItem.Text = "Продажа";
|
||||
SaleToolStripMenuItem.Click += new System.EventHandler(SellToolStripMenuItem_Click);
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@@ -204,5 +212,6 @@
|
||||
private ToolStripMenuItem ShopsToolStripMenuItem;
|
||||
private ToolStripMenuItem OperationToolStripMenuItem;
|
||||
private ToolStripMenuItem TransactionToolStripMenuItem;
|
||||
private ToolStripMenuItem SaleToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ namespace AutoWorkshopView
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
|
||||
public MainForm(ILogger<MainForm> Logger, IOrderLogic OrderLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -185,5 +186,15 @@ namespace AutoWorkshopView
|
||||
Form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void SellToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormSellRepair));
|
||||
|
||||
if (Service is FormSellRepair Form)
|
||||
{
|
||||
Form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using AutoWorkshopBusinessLogic.BusinessLogics;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopListImplement.Implements;
|
||||
using AutoWorkshopDatabaseImplement.Implements;
|
||||
using AutoWorkshopView.Forms;
|
||||
using AutoWorkshopView.Forms.Shop;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -56,6 +56,7 @@ namespace AutoWorkshopView
|
||||
Services.AddTransient<FormShop>();
|
||||
Services.AddTransient<FormShops>();
|
||||
Services.AddTransient<FormCreateSupply>();
|
||||
Services.AddTransient<FormSellRepair>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user