Compare commits
22 Commits
BACKDEV-40
...
19d3158342
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19d3158342 | ||
|
|
fb7db4b90b | ||
|
|
26a687363e | ||
|
|
4fe042017b | ||
|
|
af397abdac | ||
| 2a30f03682 | |||
|
|
a30de13f4e | ||
|
|
c72e7a4a7a | ||
|
|
cc389d7922 | ||
| c01e3c916d | |||
|
|
733c40a85a | ||
| 4391a40a78 | |||
| 2643f53e0b | |||
|
|
54afeb2906 | ||
|
|
d49014d810 | ||
|
|
55eade5399 | ||
| 41fa66267d | |||
|
|
1ba401c454 | ||
|
|
493886c45a | ||
|
|
210d90bb69 | ||
|
|
ce72b6d6b0 | ||
|
|
4b1d26dfb5 |
@@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDataMo
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreContracts", "ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj", "{5F394E21-2597-432B-AE73-BBAFD8D9F50E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerHardwareStoreBusinessLogic", "ComputerHardwareStoreBusinessLogic\ComputerHardwareStoreBusinessLogic.csproj", "{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreBusinessLogic", "ComputerHardwareStoreBusinessLogic\ComputerHardwareStoreBusinessLogic.csproj", "{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDatabaseImplement", "ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj", "{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -33,6 +35,10 @@ Global
|
||||
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -3,6 +3,7 @@ using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
@@ -78,7 +79,6 @@ namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
model.OrderProduct = element.OrderProduct;
|
||||
model.DateCreate = element.DateCreate;
|
||||
model.Status = element.Status;
|
||||
model.Cost = element.Cost;
|
||||
|
||||
if (model.Status != orderStatus - 1)
|
||||
{
|
||||
@@ -106,9 +106,9 @@ namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Cost));
|
||||
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.DateCreate))
|
||||
if (model.DateCreate == null) // TODO чего блин, всмысле нет
|
||||
{
|
||||
throw new ArgumentNullException("Нет даты создания покупки", nameof(model.Date));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="BusinessLogic\**" />
|
||||
<EmbeddedResource Remove="BusinessLogic\**" />
|
||||
<None Remove="BusinessLogic\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace ComputerHardwareStoreContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public int VendorId { get; set; }
|
||||
public IVendorModel Vendor { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||
public List<ICommentModel> Comments { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ namespace ComputerHardwareStoreContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
public int StoreKeeperId { get; set; }
|
||||
public IStoreKeeperModel StoreKeeper { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,10 @@ namespace ComputerHardwareStoreContracts.BindingModels
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int CannedId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Cost { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProduct { get; set; } = new();
|
||||
public DateTime? DateImplement { get; set; } = null;
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace ComputerHardwareStoreContracts.BindingModels
|
||||
public int VendorId { get; set; }
|
||||
public double Cost { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuild { get; set; } = new();
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProduct { get; set; } = new();
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||
{
|
||||
public interface IBuidStorage
|
||||
public interface IBuildStorage
|
||||
{
|
||||
List<BuildViewModel> GetFullList();
|
||||
List<BuildViewModel> GetFilteredList(BuildSearchModel model);
|
||||
@@ -7,10 +7,11 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название сборки")]
|
||||
public string Name { get; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Стоимость")]
|
||||
public double Price { get; }
|
||||
public int VendorId { get; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; } = new();
|
||||
public double Price { get; set; }
|
||||
public IVendorModel Vendor { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||
public List<ICommentModel> Comments { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,5 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public int BuildId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
public int StoreKeeperId { get; set; }
|
||||
public IStoreKeeperModel StoreKeeper { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Стоимость")]
|
||||
public double Cost { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; }
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProduct { get; set; } = new();
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> CannedComponents { get; set; } = new();
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents => throw new NotImplementedException();
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
public int VendorId { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuild { get; set; } = new();
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
|
||||
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProduct { get; set; } = new();
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
{
|
||||
string Name { get; }
|
||||
double Price { get; }
|
||||
int VendorId { get; }
|
||||
IVendorModel Vendor { get; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; }
|
||||
public List<ICommentModel> Comments { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,5 @@
|
||||
{
|
||||
DateTime Date { get; }
|
||||
string Text { get; }
|
||||
int BuildId { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
{
|
||||
string Name { get; }
|
||||
double Cost { get; }
|
||||
int StoreKeeperId { get; }
|
||||
IStoreKeeperModel StoreKeeper { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
|
||||
namespace ComputerHardwareStoreDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
double Cost { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProduct { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
int VendorId { get; }
|
||||
double Cost { get; }
|
||||
DateTime DateCreate { get; }
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuild { get; }
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProduct { get; }
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; }
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement
|
||||
{
|
||||
public class ComputerHardwareStoreDBContext : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
/*
|
||||
* в program добавить:
|
||||
* // получаем строку подключения из файла конфигурации
|
||||
* string connection = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
*
|
||||
* // добавляем контекст ApplicationContext в качестве сервиса в приложение
|
||||
* builder.Services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(connection));
|
||||
*
|
||||
* в appsettings:
|
||||
* "ConnectionStrings": {
|
||||
* "DefaultConnection": "Host=localhost;Database=ProductBar_db;Username=compstore;Password=compstore"
|
||||
* },
|
||||
*/
|
||||
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Product> Products { set; get; }
|
||||
public virtual DbSet<ProductComponent> ProductComponents { set; get; }
|
||||
public virtual DbSet<StoreKeeper> StoreKeepers { set; get; }
|
||||
public virtual DbSet<Build> Builds { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
|
||||
public virtual DbSet<BuildComponent> BuildComponents { set; get; }
|
||||
public virtual DbSet<Comment> Comments { set; get; }
|
||||
public virtual DbSet<Vendor> Vendors { set; get; }
|
||||
public virtual DbSet<Purchase> Purchases { set; get; }
|
||||
public virtual DbSet<PurchaseBuild> PurchaseBuilds { set; get; }
|
||||
public virtual DbSet<PurchaseProduct> PurchaseProducts { set; get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj" />
|
||||
<ProjectReference Include="..\ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,85 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDatabaseImplement.Models;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Components
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new ();
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Components
|
||||
.Where(x => x.Name.Contains(model.Name))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
return context.Components
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Name)
|
||||
&& x.Name == model.Name)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
var newComponent = Component.Create(context, model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new ComputerHardwareStoreDBContext();
|
||||
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 ComputerHardwareStoreDBContext();
|
||||
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Build : IBuildModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_buildComponents == null)
|
||||
{
|
||||
_buildComponents = Components
|
||||
.ToDictionary(bc => bc.ComponentId, bc =>
|
||||
(bc.Component as IComponentModel, bc.Count));
|
||||
}
|
||||
return _buildComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("BuildId")]
|
||||
public virtual List<BuildComponent> Components { get; set; } = new();
|
||||
[ForeignKey("BuildId")]
|
||||
|
||||
public virtual List<Comment> Comments { get; set; } = new();
|
||||
[NotMapped]
|
||||
List<ICommentModel> IBuildModel.Comments => Comments.Select(c => c as ICommentModel).ToList();
|
||||
|
||||
public virtual Vendor Vendor { get; private set; } = new();
|
||||
IVendorModel IBuildModel.Vendor => Vendor as IVendorModel;
|
||||
|
||||
public static Build? Create(ComputerHardwareStoreDBContext context, BuildBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price,
|
||||
Vendor = context.Vendors.First(v => v.Id == model.Vendor.Id),
|
||||
Components = context.Components
|
||||
.Where(c => model.BuildComponents.ContainsKey(c.Id))
|
||||
.Select(c => new BuildComponent()
|
||||
{
|
||||
BuildId = model.Id,
|
||||
ComponentId = c.Id,
|
||||
Component = c,
|
||||
Count = model.BuildComponents[c.Id].Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(BuildBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public BuildViewModel GetViewModel() => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Price = Price,
|
||||
Vendor = Vendor,
|
||||
Comments = Comments.Select(c => c as ICommentModel).ToList(),
|
||||
BuildComponents = BuildComponents
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class BuildComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int BuildId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Build Build { get; set; } = new();
|
||||
public virtual Component Component { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Comment : ICommentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public DateTime Date { get; set; }
|
||||
[Required]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int BuildId { get; set; }
|
||||
public static Comment? Create(CommentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
Date = model.Date,
|
||||
Text = model.Text,
|
||||
BuildId = model.BuildId,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CommentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Text = model.Text;
|
||||
}
|
||||
|
||||
public CommentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Date = Date,
|
||||
Text = Text,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[Required]
|
||||
public virtual StoreKeeper? StoreKeeper { get; set; }
|
||||
[NotMapped]
|
||||
IStoreKeeperModel IComponentModel.StoreKeeper => throw new NotImplementedException();
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
|
||||
public static Component? Create(ComputerHardwareStoreDBContext context, ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Cost = model.Cost,
|
||||
StoreKeeper = context.StoreKeepers.First(x => x.Id == model.StoreKeeper.Id)
|
||||
};
|
||||
}
|
||||
public void Update (ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
[Required]
|
||||
public double Sum { get; set; }
|
||||
[Required]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
private Dictionary<int, (IProductModel, int)>? _orderProducts = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_orderProducts == null)
|
||||
{
|
||||
_orderProducts = Products
|
||||
.ToDictionary(
|
||||
op => op.ProductId,
|
||||
op => (op.Product as IProductModel, op.Count));
|
||||
}
|
||||
return _orderProducts;
|
||||
}
|
||||
}
|
||||
[ForeignKey("OrderId")]
|
||||
public virtual List<OrderProduct> Products { get; set; } = new();
|
||||
public static Order? Create(ComputerHardwareStoreDBContext context, OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Products = context.Products
|
||||
.Where(p => model.OrderProducts.ContainsKey(p.Id))
|
||||
.Select(p => new OrderProduct()
|
||||
{
|
||||
OrderId = model.Id,
|
||||
ProductId = p.Id,
|
||||
Product = p,
|
||||
Count = model.OrderProducts[p.Id].Item2
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class OrderProduct
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int OrderId { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Product Product { get; set; } = new();
|
||||
public virtual Order Order { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Product : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _productComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_productComponents == null)
|
||||
{
|
||||
_productComponents = Components
|
||||
.ToDictionary(c => c.ComponentId, c => (c.Component as IComponentModel, c.Count));
|
||||
}
|
||||
return _productComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("ProductId")]
|
||||
public virtual List<ProductComponent> Components { get; set; } = new();
|
||||
[ForeignKey("ProductId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Product Create(ComputerHardwareStoreDBContext context, ProductBindingModel model)
|
||||
{
|
||||
return new Product()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price,
|
||||
Components = context.Components
|
||||
.Where(c => model.ProductComponents.ContainsKey(c.Id))
|
||||
.Select(c => new ProductComponent()
|
||||
{
|
||||
ProductId = model.Id,
|
||||
ComponentId = c.Id,
|
||||
Component = c,
|
||||
Count = model.ProductComponents[c.Id].Item2
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
public void Update(ProductBindingModel model)
|
||||
{
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Price = model.Price;
|
||||
|
||||
}
|
||||
public ProductViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Price = Price,
|
||||
ProductComponents = ProductComponents
|
||||
};
|
||||
|
||||
public static void UpdateComponents(ComputerHardwareStoreDBContext context, ProductBindingModel model)
|
||||
{
|
||||
var productComponents = context.ProductComponents
|
||||
.Where(pc => pc.ProductId == model.Id)
|
||||
.ToList();
|
||||
if (productComponents.Count != 0 && productComponents.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.ProductComponents
|
||||
.Where(pc => !model.ProductComponents.ContainsKey(pc.ComponentId))
|
||||
.ExecuteDelete();
|
||||
// обновили количество у существующих записей
|
||||
productComponents
|
||||
.ForEach(updateComponent =>
|
||||
{
|
||||
updateComponent.Count = model.ProductComponents[updateComponent.ComponentId].Item2;
|
||||
model.ProductComponents.Remove(updateComponent.ComponentId);
|
||||
});
|
||||
}
|
||||
// добавили новые
|
||||
context.ProductComponents
|
||||
.AddRange(model.ProductComponents.Values
|
||||
.Select(val => new ProductComponent()
|
||||
{
|
||||
ProductId = model.Id,
|
||||
ComponentId = val.Item1.Id,
|
||||
Count = val.Item2
|
||||
}));
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class ProductComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Product Product { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Purchase : IPurchaseModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int VendorId { get; set; }
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
private Dictionary<int, (IBuildModel, int)>? _purchaseBuilds = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_purchaseBuilds == null)
|
||||
{
|
||||
_purchaseBuilds = Builds
|
||||
.ToDictionary(op => op.BuildId, op => (op.Build as IBuildModel, op.Count));
|
||||
}
|
||||
return _purchaseBuilds;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseBuild> Builds { get; set; } = new();
|
||||
private Dictionary<int, (IProductModel, int)>? _purchaseProducts = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IProductModel, int)> PurchaseProducts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_purchaseProducts == null)
|
||||
{
|
||||
_purchaseProducts = Products
|
||||
.ToDictionary(op => op.ProductId, op => (op.Product as IProductModel, op.Count));
|
||||
}
|
||||
return _purchaseProducts;
|
||||
}
|
||||
}
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseProduct> Products { get; set; } = new();
|
||||
|
||||
public static Purchase Create(ComputerHardwareStoreDBContext context, PurchaseBindingModel model)
|
||||
{
|
||||
return new Purchase()
|
||||
{
|
||||
Id = model.Id,
|
||||
Cost = model.Cost,
|
||||
DateCreate = model.DateCreate,
|
||||
Builds = context.Builds
|
||||
.Where(b => model.PurchaseBuilds.ContainsKey(b.Id))
|
||||
.Select(b => new PurchaseBuild()
|
||||
{
|
||||
PurchaseId = model.Id,
|
||||
BuildId = b.Id,
|
||||
Build = b,
|
||||
Count = model.PurchaseProducts[b.Id].Item2
|
||||
}).ToList(),
|
||||
Products = context.Products
|
||||
.Where(p => model.PurchaseProducts.ContainsKey(p.Id))
|
||||
.Select (p => new PurchaseProduct()
|
||||
{
|
||||
PurchaseId = model.Id,
|
||||
ProductId = p.Id,
|
||||
Product = p,
|
||||
Count = model.PurchaseProducts[p.Id].Item2
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
}
|
||||
public void Update(PurchaseBindingModel model)
|
||||
{
|
||||
Cost = model.Cost;
|
||||
|
||||
}
|
||||
public PurchaseViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Cost = Cost,
|
||||
DateCreate = DateCreate,
|
||||
PurchaseBuilds = PurchaseBuilds,
|
||||
PurchaseProducts = PurchaseProducts
|
||||
};
|
||||
|
||||
public static void UpdateBuilds(ComputerHardwareStoreDBContext context, PurchaseBindingModel model)
|
||||
{
|
||||
var productBuilds = context.PurchaseBuilds
|
||||
.Where(pc => pc.PurchaseId == model.Id)
|
||||
.ToList();
|
||||
if (productBuilds.Count != 0 && productBuilds.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.PurchaseBuilds
|
||||
.Where(pc => !model.PurchaseBuilds.ContainsKey(pc.BuildId))
|
||||
.ExecuteDelete();
|
||||
// обновили количество у существующих записей
|
||||
productBuilds
|
||||
.ForEach(updateBuild =>
|
||||
{
|
||||
updateBuild.Count = model.PurchaseBuilds[updateBuild.BuildId].Item2;
|
||||
model.PurchaseBuilds.Remove(updateBuild.BuildId);
|
||||
});
|
||||
}
|
||||
// добавили новые
|
||||
context.PurchaseBuilds
|
||||
.AddRange(model.PurchaseBuilds.Values
|
||||
.Select(val => new PurchaseBuild()
|
||||
{
|
||||
PurchaseId = model.Id,
|
||||
BuildId = val.Item1.Id,
|
||||
Count = val.Item2
|
||||
}));
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public static void UpdateProducts(ComputerHardwareStoreDBContext context, PurchaseBindingModel model)
|
||||
{
|
||||
var productProducts = context.PurchaseProducts
|
||||
.Where(pc => pc.PurchaseId == model.Id)
|
||||
.ToList();
|
||||
if (productProducts.Count != 0 && productProducts.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.PurchaseProducts
|
||||
.Where(pc => !model.PurchaseProducts.ContainsKey(pc.ProductId))
|
||||
.ExecuteDelete();
|
||||
// обновили количество у существующих записей
|
||||
productProducts
|
||||
.ForEach(updateProduct =>
|
||||
{
|
||||
updateProduct.Count = model.PurchaseProducts[updateProduct.ProductId].Item2;
|
||||
model.PurchaseProducts.Remove(updateProduct.ProductId);
|
||||
});
|
||||
}
|
||||
// добавили новые
|
||||
context.PurchaseProducts
|
||||
.AddRange(model.PurchaseProducts.Values
|
||||
.Select(val => new PurchaseProduct()
|
||||
{
|
||||
PurchaseId = model.Id,
|
||||
ProductId = val.Item1.Id,
|
||||
Count = val.Item2
|
||||
}));
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class PurchaseBuild
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int PurchaseId { get; set; }
|
||||
[Required]
|
||||
public int BuildId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Purchase Purchase { get; set; } = new();
|
||||
public virtual Build Build { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class PurchaseProduct
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int PurchaseId { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Purchase Purchase { get; set; } = new();
|
||||
public virtual Product Product { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class StoreKeeper : IStoreKeeperModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
|
||||
public string Login { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[ForeignKey("StoreKeeperId")]
|
||||
public virtual List<Product> Products { get; set; } = new();
|
||||
[ForeignKey("StoreKeeperId")]
|
||||
public virtual List<Component> Components { get; set; } = new();
|
||||
|
||||
public static StoreKeeper? Create(ComputerHardwareStoreDBContext context, StoreKeeperBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new StoreKeeper()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
public void Update(StoreKeeperBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Password = string.IsNullOrEmpty(model.Password) ? Password : model.Password;
|
||||
}
|
||||
|
||||
public StoreKeeperViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Login = Login,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Vendor : IVendorModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
|
||||
public string Login { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[ForeignKey("VendorId")]
|
||||
public virtual List<Purchase> Purchases { get; set; } = new();
|
||||
[ForeignKey("VendorId")]
|
||||
public virtual List<Build> Builds { get; set; } = new();
|
||||
|
||||
public static Vendor? Create(ComputerHardwareStoreDBContext context, VendorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Vendor()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
public void Update(VendorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
||||
Password = string.IsNullOrEmpty(model.Password) ? Password : model.Password;
|
||||
}
|
||||
|
||||
public VendorViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Login = Login,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user