Compare commits
No commits in common. "139d12d7e773fb04dcd1129335a2657245d7d7d1" and "a846d8071556cf435325eaebebf60222e76f6e94" have entirely different histories.
139d12d7e7
...
a846d80715
@ -84,23 +84,23 @@ namespace PrecastConcretePlantFileImplement.Implements
|
||||
}
|
||||
public bool SellReinforceds(IReinforcedModel model, int count)
|
||||
{
|
||||
int availableQuantity = source.Shops.Select(x => x.ShopReinforceds.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum();
|
||||
int availableQuantity = source.Shops.Select(x => x.Reinforceds.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum();
|
||||
if (availableQuantity < count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var shops = source.Shops.Where(x => x.ShopReinforceds.ContainsKey(model.Id));
|
||||
var shops = source.Shops.Where(x => x.Reinforceds.ContainsKey(model.Id));
|
||||
foreach (var shop in shops)
|
||||
{
|
||||
int countInCurrentShop = shop.ShopReinforceds[model.Id].Item2;
|
||||
int countInCurrentShop = shop.Reinforceds[model.Id].Item2;
|
||||
if (countInCurrentShop <= count)
|
||||
{
|
||||
shop.ShopReinforceds[model.Id] = (shop.ShopReinforceds[model.Id].Item1, 0);
|
||||
shop.Reinforceds[model.Id] = (shop.Reinforceds[model.Id].Item1, 0);
|
||||
count -= countInCurrentShop;
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.ShopReinforceds[model.Id] = (shop.ShopReinforceds[model.Id].Item1, countInCurrentShop - count);
|
||||
shop.Reinforceds[model.Id] = (shop.Reinforceds[model.Id].Item1, countInCurrentShop - count);
|
||||
count = 0;
|
||||
}
|
||||
Update(new ShopBindingModel
|
||||
@ -109,7 +109,7 @@ namespace PrecastConcretePlantFileImplement.Implements
|
||||
ShopName = shop.ShopName,
|
||||
Address = shop.Address,
|
||||
DateOpening = shop.DateOpening,
|
||||
ShopReinforceds = shop.ShopReinforceds,
|
||||
Reinforceds = shop.Reinforceds,
|
||||
Capacity = shop.Capacity
|
||||
});
|
||||
if (count == 0)
|
||||
|
@ -20,7 +20,7 @@ namespace PrecastConcretePlantFileImplement.Models
|
||||
public int Capacity { get; private set; }
|
||||
public Dictionary<int, int> ReinforcedsCount = new();
|
||||
public Dictionary<int, (IReinforcedModel, int)>? _reinforceds = null;
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforceds
|
||||
public Dictionary<int, (IReinforcedModel, int)> Reinforceds
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -49,7 +49,7 @@ namespace PrecastConcretePlantFileImplement.Models
|
||||
Address = model.Address,
|
||||
DateOpening = model.DateOpening,
|
||||
Capacity = model.Capacity,
|
||||
ReinforcedsCount = model.ShopReinforceds.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
ReinforcedsCount = model.Reinforceds.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Shop? Create(XElement element)
|
||||
@ -81,7 +81,7 @@ namespace PrecastConcretePlantFileImplement.Models
|
||||
Address = model.Address;
|
||||
DateOpening = model.DateOpening;
|
||||
Capacity = model.Capacity;
|
||||
ReinforcedsCount = model.ShopReinforceds.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
ReinforcedsCount = model.Reinforceds.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_reinforceds = null;
|
||||
|
||||
}
|
||||
@ -92,7 +92,7 @@ namespace PrecastConcretePlantFileImplement.Models
|
||||
Address = Address,
|
||||
DateOpening = DateOpening,
|
||||
Capacity = Capacity,
|
||||
ShopReinforceds = ShopReinforceds
|
||||
Reinforceds = Reinforceds
|
||||
};
|
||||
public XElement GetXElement => new("Shop",
|
||||
new XAttribute("Id", Id),
|
||||
|
@ -48,7 +48,7 @@ namespace PrecastConcretePlantView
|
||||
textBoxAddress.Text = view.Address;
|
||||
dateTimePicker.Text = view.DateOpening.ToString();
|
||||
numericUpDownCapacity.Value = view.Capacity;
|
||||
_shopReinforceds = view.ShopReinforceds ?? new Dictionary<int, (IReinforcedModel, int)>();
|
||||
_shopReinforceds = view.Reinforceds ?? new Dictionary<int, (IReinforcedModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
@ -103,7 +103,7 @@ namespace PrecastConcretePlantView
|
||||
Address = textBoxAddress.Text,
|
||||
DateOpening = dateTimePicker.Value.Date,
|
||||
Capacity = (int)numericUpDownCapacity.Value,
|
||||
ShopReinforceds = _shopReinforceds
|
||||
Reinforceds = _shopReinforceds
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
if (!operationResult)
|
||||
|
@ -37,7 +37,7 @@ namespace PrecastConcretePlantView
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ShopReinforceds"].Visible = false;
|
||||
dataGridView.Columns["Reinforceds"].Visible = false;
|
||||
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Загрузка магазинов");
|
||||
|
@ -13,9 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantContrac
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantListImplement", "..\PrecastConcretePlantListImplement\PrecastConcretePlantListImplement.csproj", "{9EFFE92D-1414-4FD9-B424-56A32797499A}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantFileImplement", "..\PrecastConcreteFileImplement\PrecastConcretePlantFileImplement.csproj", "{921B695C-0124-4295-8E39-1CC60E0D1D56}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantDatabaseImplement", "..\PrecastConcretePlantDataBaseImplemet\PrecastConcretePlantDatabaseImplement.csproj", "{8E649C11-1085-49FC-BC7A-CACB558CB39A}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantFileImplement", "..\PrecastConcreteFileImplement\PrecastConcretePlantFileImplement.csproj", "{921B695C-0124-4295-8E39-1CC60E0D1D56}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -47,10 +45,6 @@ Global
|
||||
{921B695C-0124-4295-8E39-1CC60E0D1D56}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{921B695C-0124-4295-8E39-1CC60E0D1D56}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{921B695C-0124-4295-8E39-1CC60E0D1D56}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8E649C11-1085-49FC-BC7A-CACB558CB39A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8E649C11-1085-49FC-BC7A-CACB558CB39A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8E649C11-1085-49FC-BC7A-CACB558CB39A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8E649C11-1085-49FC-BC7A-CACB558CB39A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -9,10 +9,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -20,7 +16,6 @@
|
||||
<ProjectReference Include="..\PrecastConcreteFileImplement\PrecastConcretePlantFileImplement.csproj" />
|
||||
<ProjectReference Include="..\PrecastConcretePlantBusinessLogic\PrecastConcretePlantBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\PrecastConcretePlantContracts\PrecastConcretePlantContracts.csproj" />
|
||||
<ProjectReference Include="..\PrecastConcretePlantDataBaseImplemet\PrecastConcretePlantDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\PrecastConcretePlantDataModels\PrecastConcretePlantDataModels.csproj" />
|
||||
<ProjectReference Include="..\PrecastConcretePlantListImplement\PrecastConcretePlantListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -5,7 +5,7 @@ using NLog.Extensions.Logging;
|
||||
using PrecastConcretePlantBusinessLogic.BusinessLogic;
|
||||
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
||||
using PrecastConcretePlantContracts.StoragesContracts;
|
||||
using PrecastConcretePlantDatabaseImplement.Implements;
|
||||
using PrecastConcretePlantFileImplement.Implements;
|
||||
|
||||
namespace PrecastConcretePlant
|
||||
{
|
||||
|
@ -124,21 +124,21 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
_logger.LogWarning("AddReinforcedInShop element not found");
|
||||
return false;
|
||||
}
|
||||
if (shop.Capacity - shop.ShopReinforceds.Select(x => x.Value.Item2).Sum() < count)
|
||||
if (shop.Capacity - shop.Reinforceds.Select(x => x.Value.Item2).Sum() < count)
|
||||
{
|
||||
throw new ArgumentNullException("В магазине не хватает места", nameof(count));
|
||||
}
|
||||
else _logger.LogInformation("AddReinforcedInShop find. Id:{Id}", shop.Id);
|
||||
|
||||
if (shop.ShopReinforceds.ContainsKey(reinforced.Id))
|
||||
if (shop.Reinforceds.ContainsKey(reinforced.Id))
|
||||
{
|
||||
shop.ShopReinforceds[reinforced.Id] = (reinforced, count + shop.ShopReinforceds[reinforced.Id].Item2);
|
||||
shop.Reinforceds[reinforced.Id] = (reinforced, count + shop.Reinforceds[reinforced.Id].Item2);
|
||||
_logger.LogInformation("AddReinforcedInShop. Added {count} {reinforced} to '{ShopName}' shop",
|
||||
count, reinforced.ReinforcedName, shop.ShopName);
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.ShopReinforceds[reinforced.Id] = (reinforced, count);
|
||||
shop.Reinforceds[reinforced.Id] = (reinforced, count);
|
||||
_logger.LogInformation("AddReinforcedInShop. Added {count} new reinforced {reinforced} to '{ShopName}' shop",
|
||||
count, reinforced.ReinforcedName, shop.ShopName);
|
||||
}
|
||||
@ -148,7 +148,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
Address = shop.Address,
|
||||
ShopName = shop.ShopName,
|
||||
DateOpening = shop.DateOpening,
|
||||
ShopReinforceds = shop.ShopReinforceds,
|
||||
Reinforceds = shop.Reinforceds,
|
||||
Capacity = shop.Capacity
|
||||
});
|
||||
return true;
|
||||
@ -164,7 +164,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
throw new ArgumentException("Количество ЖБИ должно быть больше 0", nameof(count));
|
||||
}
|
||||
_logger.LogInformation("AddReinforceds. ShopName:{ShopName}. Id:{Id}", model.ReinforcedName, model.Id);
|
||||
var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.ShopReinforceds.Select(x => x.Value.Item2).Sum()).Sum();
|
||||
var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.Reinforceds.Select(x => x.Value.Item2).Sum()).Sum();
|
||||
if (allFreeQuantity < count)
|
||||
{
|
||||
_logger.LogWarning("AddReinforceds operation failed.");
|
||||
@ -172,7 +172,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
}
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
int freeQuantity = shop.Capacity - shop.ShopReinforceds.Select(x => x.Value.Item2).Sum();
|
||||
int freeQuantity = shop.Capacity - shop.Reinforceds.Select(x => x.Value.Item2).Sum();
|
||||
if (freeQuantity < count)
|
||||
{
|
||||
if (!AddReinforcedInShop(new() { Id = shop.Id }, model, freeQuantity))
|
||||
|
@ -18,7 +18,7 @@ namespace PrecastConcretePlantContracts.BindingModels
|
||||
|
||||
public int Capacity { get; set; }
|
||||
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforceds
|
||||
public Dictionary<int, (IReinforcedModel, int)> Reinforceds
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -22,7 +22,7 @@ namespace PrecastConcretePlantContracts.ViewModels
|
||||
|
||||
[DisplayName("Вместимость магазина")]
|
||||
public int Capacity { get; set; }
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforceds
|
||||
public Dictionary<int, (IReinforcedModel, int)> Reinforceds
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -1,89 +0,0 @@
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
using PrecastConcretePlantContracts.StoragesContracts;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
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 PrecastConcretePlantDatabase();
|
||||
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 PrecastConcretePlantDatabase();
|
||||
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 PrecastConcretePlantDatabase();
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
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 PrecastConcretePlantDatabase();
|
||||
var element = context.Components.FirstOrDefault(rec => rec.Id ==
|
||||
model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
using PrecastConcretePlantContracts.StoragesContracts;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
var element = context.Orders
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
var deletedElement = context.Orders
|
||||
.Include(x => x.Reinforced)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Orders.Include(x => x.Reinforced)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Reinforced)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Reinforced)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return context.Orders
|
||||
.Include(x => x.Reinforced)
|
||||
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
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.Reinforced)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
using PrecastConcretePlantContracts.StoragesContracts;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Implements
|
||||
{
|
||||
public class ReinforcedStorage : IReinforcedStorage
|
||||
{
|
||||
public List<ReinforcedViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Reinforceds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ReinforcedViewModel> GetFilteredList(ReinforcedSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ReinforcedName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Reinforceds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.ReinforcedName.Contains(model.ReinforcedName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ReinforcedViewModel? GetElement(ReinforcedSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ReinforcedName) &&
|
||||
!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Reinforceds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ReinforcedName) &&
|
||||
x.ReinforcedName == model.ReinforcedName) ||
|
||||
(model.Id.HasValue && x.Id ==
|
||||
model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public ReinforcedViewModel? Insert(ReinforcedBindingModel model)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
var newReinforced = Reinforced.Create(context, model);
|
||||
if (newReinforced == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Reinforceds.Add(newReinforced);
|
||||
context.SaveChanges();
|
||||
return newReinforced.GetViewModel;
|
||||
}
|
||||
public ReinforcedViewModel? Update(ReinforcedBindingModel model)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var Reinforced = context.Reinforceds.FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
if (Reinforced == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Reinforced.Update(model);
|
||||
context.SaveChanges();
|
||||
Reinforced.UpdateComponents(context, model);
|
||||
transaction.Commit();
|
||||
return Reinforced.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public ReinforcedViewModel? Delete(ReinforcedBindingModel model)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
var element = context.Reinforceds
|
||||
.Include(x => x.Components)
|
||||
.Include(x=>x.Orders)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Reinforceds.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
using PrecastConcretePlantContracts.StoragesContracts;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Reinforceds)
|
||||
.ThenInclude(x => x.Reinforced)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Reinforceds)
|
||||
.ThenInclude(x => x.Reinforced)
|
||||
.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 null;
|
||||
}
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Reinforceds)
|
||||
.ThenInclude(x => x.Reinforced)
|
||||
.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 PrecastConcretePlantDatabase();
|
||||
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 PrecastConcretePlantDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var shop = context.Shops.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
context.SaveChanges();
|
||||
shop.UpdateTravels(context, model);
|
||||
transaction.Commit();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
var element = context.Shops
|
||||
.Include(x => x.Reinforceds)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Shops.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellReinforceds(IReinforcedModel model, int count)
|
||||
{
|
||||
using var context = new PrecastConcretePlantDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var shops = context.ShopReinforceds
|
||||
.Include(x => x.Shop)
|
||||
.ToList()
|
||||
.Where(rec => rec.ReinforcedId == model.Id);
|
||||
if (shops == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (var shop in shops)
|
||||
{
|
||||
if (shop.Count < count)
|
||||
{
|
||||
shop.Count = 0;
|
||||
count -= shop.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.Count = shop.Count - count;
|
||||
count -= count;
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using PrecastConcretePlantDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(PrecastConcretePlantDatabase))]
|
||||
[Migration("20230318153144_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("ReinforcedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ReinforcedId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("ReinforcedName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Reinforceds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ReinforcedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("ReinforcedId");
|
||||
|
||||
b.ToTable("ReinforcedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ReinforcedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Reinforced");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
|
||||
{
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("ReinforcedComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("ReinforcedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Reinforced");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("ReinforcedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Reinforceds",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ReinforcedName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Reinforceds", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ReinforcedId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Reinforceds_ReinforcedId",
|
||||
column: x => x.ReinforcedId,
|
||||
principalTable: "Reinforceds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ReinforcedComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ReinforcedId = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ReinforcedComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ReinforcedComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ReinforcedComponents_Reinforceds_ReinforcedId",
|
||||
column: x => x.ReinforcedId,
|
||||
principalTable: "Reinforceds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ReinforcedId",
|
||||
table: "Orders",
|
||||
column: "ReinforcedId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ReinforcedComponents_ComponentId",
|
||||
table: "ReinforcedComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ReinforcedComponents_ReinforcedId",
|
||||
table: "ReinforcedComponents",
|
||||
column: "ReinforcedId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ReinforcedComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Reinforceds");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,248 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using PrecastConcretePlantDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(PrecastConcretePlantDatabase))]
|
||||
[Migration("20230521120118_addshop")]
|
||||
partial class addshop
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("ReinforcedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ReinforcedId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("ReinforcedName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Reinforceds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ReinforcedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("ReinforcedId");
|
||||
|
||||
b.ToTable("ReinforcedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ReinforcedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ReinforcedId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopReinforceds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Capacity")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateOpening")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ReinforcedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Reinforced");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
|
||||
{
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("ReinforcedComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("ReinforcedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Reinforced");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b =>
|
||||
{
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||
.WithMany()
|
||||
.HasForeignKey("ReinforcedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Shop", "Shop")
|
||||
.WithMany("Reinforceds")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Reinforced");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("ReinforcedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Shop", b =>
|
||||
{
|
||||
b.Navigation("Reinforceds");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class addshop : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateOpening = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Capacity = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopReinforceds",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||
ReinforcedId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopReinforceds", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopReinforceds_Reinforceds_ReinforcedId",
|
||||
column: x => x.ReinforcedId,
|
||||
principalTable: "Reinforceds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopReinforceds_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopReinforceds_ReinforcedId",
|
||||
table: "ShopReinforceds",
|
||||
column: "ReinforcedId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopReinforceds_ShopId",
|
||||
table: "ShopReinforceds",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopReinforceds");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,245 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using PrecastConcretePlantDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(PrecastConcretePlantDatabase))]
|
||||
partial class PrecastConcretePlantDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("ReinforcedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ReinforcedId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("ReinforcedName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Reinforceds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ReinforcedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("ReinforcedId");
|
||||
|
||||
b.ToTable("ReinforcedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ReinforcedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ReinforcedId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopReinforceds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Capacity")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateOpening")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ReinforcedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Reinforced");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
|
||||
{
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("ReinforcedComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("ReinforcedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Reinforced");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b =>
|
||||
{
|
||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||
.WithMany()
|
||||
.HasForeignKey("ReinforcedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Shop", "Shop")
|
||||
.WithMany("Reinforceds")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Reinforced");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("ReinforcedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Shop", b =>
|
||||
{
|
||||
b.Navigation("Reinforceds");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.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<ReinforcedComponent> ReinforcedComponents { 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
|
||||
};
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDataModels.Enums;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int ReinforcedId { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public virtual Reinforced Reinforced { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
ReinforcedId = model.ReinforcedId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ReinforcedId = ReinforcedId,
|
||||
ReinforcedName = Reinforced.ReinforcedName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
|
||||
};
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Models
|
||||
{
|
||||
public class Reinforced : IReinforcedModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string ReinforcedName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _reinforcedComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> ReinforcedComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_reinforcedComponents == null)
|
||||
{
|
||||
_reinforcedComponents = Components
|
||||
.ToDictionary(recPC => recPC.ComponentId, recPC =>
|
||||
(recPC.Component as IComponentModel, recPC.Count));
|
||||
}
|
||||
return _reinforcedComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("ReinforcedId")]
|
||||
public virtual List<ReinforcedComponent> Components { get; set; } = new();
|
||||
[ForeignKey("ReinforcedId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Reinforced Create(PrecastConcretePlantDatabase context,
|
||||
ReinforcedBindingModel model)
|
||||
{
|
||||
return new Reinforced()
|
||||
{
|
||||
Id = model.Id,
|
||||
ReinforcedName = model.ReinforcedName,
|
||||
Price = model.Price,
|
||||
Components = model.ReinforcedComponents.Select(x => new
|
||||
ReinforcedComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(ReinforcedBindingModel model)
|
||||
{
|
||||
ReinforcedName = model.ReinforcedName;
|
||||
Price = model.Price;
|
||||
}
|
||||
public ReinforcedViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ReinforcedName = ReinforcedName,
|
||||
Price = Price,
|
||||
ReinforcedComponents = ReinforcedComponents
|
||||
};
|
||||
public void UpdateComponents(PrecastConcretePlantDatabase context, ReinforcedBindingModel model)
|
||||
{
|
||||
var ReinforcedComponents = context.ReinforcedComponents.Where(rec =>
|
||||
rec.ReinforcedId == model.Id).ToList();
|
||||
if (ReinforcedComponents != null && ReinforcedComponents.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.ReinforcedComponents.RemoveRange(ReinforcedComponents.Where(rec
|
||||
=> !model.ReinforcedComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateComponent in ReinforcedComponents)
|
||||
{
|
||||
updateComponent.Count = model.ReinforcedComponents[updateComponent.ComponentId].Item2;
|
||||
model.ReinforcedComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var Reinforced = context.Reinforceds.First(x => x.Id == Id);
|
||||
foreach (var rc in model.ReinforcedComponents)
|
||||
{
|
||||
context.ReinforcedComponents.Add(new ReinforcedComponent
|
||||
{
|
||||
Reinforced = Reinforced,
|
||||
Component = context.Components.First(x => x.Id == rc.Key),
|
||||
Count = rc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_reinforcedComponents = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Models
|
||||
{
|
||||
public class ReinforcedComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int ReinforcedId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Reinforced Reinforced { get; set; } = new();
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDatabaseImplement;
|
||||
using PrecastConcretePlantDatabaseImplement.Models;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
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 DateOpening { get; set; }
|
||||
[Required]
|
||||
public int Capacity { get; set; }
|
||||
|
||||
private Dictionary<int, (IReinforcedModel, int)>? _shopReinforceds = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforceds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopReinforceds == null)
|
||||
{
|
||||
_shopReinforceds = Reinforceds.ToDictionary(rec => rec.ReinforcedId, rec => (rec.Reinforced as IReinforcedModel, rec.Count));
|
||||
}
|
||||
return _shopReinforceds;
|
||||
}
|
||||
}
|
||||
[ForeignKey("ShopId")]
|
||||
public virtual List<ShopReinforced> Reinforceds { get; set; } = new();
|
||||
public static Shop Create(PrecastConcretePlantDatabase context, ShopBindingModel model)
|
||||
{
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
DateOpening = model.DateOpening,
|
||||
Capacity = model.Capacity,
|
||||
Reinforceds = model.ShopReinforceds.Select(x => new ShopReinforced
|
||||
{
|
||||
Reinforced = context.Reinforceds.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel model)
|
||||
{
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateOpening = model.DateOpening;
|
||||
Capacity = model.Capacity;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
DateOpening = DateOpening,
|
||||
Capacity = Capacity,
|
||||
ShopReinforceds = ShopReinforceds
|
||||
};
|
||||
|
||||
public void UpdateTravels(PrecastConcretePlantDatabase context, ShopBindingModel model)
|
||||
{
|
||||
var shopReinforceds = context.ShopReinforceds.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
if (shopReinforceds != null && shopReinforceds.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.ShopReinforceds.RemoveRange(shopReinforceds.Where(rec => !model.ShopReinforceds.ContainsKey(rec.ReinforcedId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateTravel in shopReinforceds)
|
||||
{
|
||||
updateTravel.Count = model.ShopReinforceds[updateTravel.ReinforcedId].Item2;
|
||||
model.ShopReinforceds.Remove(updateTravel.ReinforcedId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var shop = context.Shops.First(x => x.Id == Id);
|
||||
foreach (var st in model.ShopReinforceds)
|
||||
{
|
||||
context.ShopReinforceds.Add(new ShopReinforced
|
||||
{
|
||||
Shop = shop,
|
||||
Reinforced = context.Reinforceds.First(x => x.Id == st.Key),
|
||||
Count = st.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_shopReinforceds = null;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement.Models
|
||||
{
|
||||
public class ShopReinforced
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ReinforcedId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Reinforced Reinforced { get; set; } = new();
|
||||
|
||||
public virtual Shop Shop { get; set; } = new();
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<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.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PrecastConcretePlantContracts\PrecastConcretePlantContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,29 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PrecastConcretePlantDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantDatabaseImplement
|
||||
{
|
||||
public class PrecastConcretePlantDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder
|
||||
optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-0IOO2C0;Initial Catalog= PrecastConcretePlantDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Reinforced> Reinforceds { set; get; }
|
||||
public virtual DbSet<ReinforcedComponent> ReinforcedComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Shop> Shops { set; get; }
|
||||
public virtual DbSet<ShopReinforced> ShopReinforceds { set; get; }
|
||||
}
|
||||
}
|
@ -12,6 +12,6 @@ namespace PrecastConcretePlantDataModels.Models
|
||||
string Address { get; }
|
||||
DateTime DateOpening { get; }
|
||||
public int Capacity { get; }
|
||||
Dictionary<int, (IReinforcedModel, int)> ShopReinforceds { get; }
|
||||
Dictionary<int, (IReinforcedModel, int)> Reinforceds { get; }
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace PrecastConcretePlantListImplement.Models
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
public DateTime DateOpening { get; private set; }
|
||||
public int Capacity { get; private set; }
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforceds
|
||||
public Dictionary<int, (IReinforcedModel, int)> Reinforceds
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
@ -33,7 +33,7 @@ namespace PrecastConcretePlantListImplement.Models
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
DateOpening = model.DateOpening,
|
||||
ShopReinforceds = new()
|
||||
Reinforceds = new()
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel? model)
|
||||
@ -45,14 +45,14 @@ namespace PrecastConcretePlantListImplement.Models
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateOpening = model.DateOpening;
|
||||
ShopReinforceds = model.ShopReinforceds;
|
||||
Reinforceds = model.Reinforceds;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
ShopReinforceds = ShopReinforceds,
|
||||
Reinforceds = Reinforceds,
|
||||
DateOpening = DateOpening,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user