Compare commits
4 Commits
92d6b4ed4d
...
7fde2e5622
Author | SHA1 | Date | |
---|---|---|---|
7fde2e5622 | |||
1e40ed2d43 | |||
19132c6645 | |||
049582dbc4 |
@ -13,8 +13,7 @@ namespace ComputerShopContracts.BindingModels
|
|||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
//!!!ДОБАВИТЬ ССЫЛКУ НА СБОРКУ
|
public int AssemblyId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public DateTime DateMake { get; set; } = DateTime.Now;
|
public DateTime DateMake { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@ namespace ComputerShopContracts.SearchModels
|
|||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public int? UserId { get; set; }
|
public int? UserId { get; set; }
|
||||||
|
|
||||||
//!!!ДОБАВИТЬ ПОИСК ПО СБОРКЕ (СУЩНОСТИ ОЛЕГА)
|
//поиск по сборкам
|
||||||
|
public int? AssemblyId { get; set; }
|
||||||
|
|
||||||
//!!!мб надо добавить поиск по заказам
|
//!!!мб надо добавить поиск по заказам
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@ namespace ComputerShopContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public int UserId { get; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
[DisplayName("Название комплектующей")]
|
[DisplayName("Название комплектующей")]
|
||||||
public string ComponentName { get; } = string.Empty;
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
|
||||||
[DisplayName("Стоимость")]
|
[DisplayName("Стоимость")]
|
||||||
public double Cost { get; }
|
public double Cost { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace ComputerShopContracts.ViewModels
|
|||||||
|
|
||||||
//!!!МБ ДОБАВИТЬ НИК ПОЛЬЗОВАТЕЛЯ, СОЗДАВШЕГО ЗАЯВКУ
|
//!!!МБ ДОБАВИТЬ НИК ПОЛЬЗОВАТЕЛЯ, СОЗДАВШЕГО ЗАЯВКУ
|
||||||
|
|
||||||
//!!!МБ ДОБАВИТЬ ID СБОРКИ
|
public int AssemblyId { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, IOrderModel> RequestOrders { get; set; } = new();
|
public Dictionary<int, IOrderModel> RequestOrders { get; set; } = new();
|
||||||
|
|
||||||
|
@ -14,12 +14,10 @@ namespace ComputerShopDataModels.Models
|
|||||||
//ID пользователя, создавшего заявку
|
//ID пользователя, создавшего заявку
|
||||||
int UserId { get; }
|
int UserId { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ID сборки
|
||||||
|
/// </summary>
|
||||||
|
int AssemblyId { get; }
|
||||||
//!!!ДОБАВИТЬ ССЫЛКУ НА СБОРКУ ИЗ ЧАСТИ ОЛЕГА
|
|
||||||
|
|
||||||
|
|
||||||
Dictionary<int, IOrderModel> RequestOrders { get; }
|
Dictionary<int, IOrderModel> RequestOrders { get; }
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using ComputerShopDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace ComputerShopDatabaseImplement
|
namespace ComputerShopDatabaseImplement
|
||||||
{
|
{
|
||||||
@ -16,5 +17,17 @@ namespace ComputerShopDatabaseImplement
|
|||||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<Component> Components { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<Assembly> Assemblies { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<AssemblyComponent> AssemblyComponents { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<Product> Products { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<ProductComponent> ProductComponents { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,12 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="Implements\**" />
|
||||||
|
<EmbeddedResource Remove="Implements\**" />
|
||||||
|
<None Remove="Implements\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.18" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.18" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.18">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.18">
|
||||||
@ -20,8 +26,4 @@
|
|||||||
<ProjectReference Include="..\ComputerShopDataModels\ComputerShopDataModels.csproj" />
|
<ProjectReference Include="..\ComputerShopDataModels\ComputerShopDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Implements\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
65
ComputerShopDatabaseImplement/Models/Assembly.cs
Normal file
65
ComputerShopDatabaseImplement/Models/Assembly.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace ComputerShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Assembly : IAssemblyModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int UserId { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string AssemblyName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Cost { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Category { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[ForeignKey("ComponentId")]
|
||||||
|
public virtual List<AssemblyComponent> Components { get; set; } = new();
|
||||||
|
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _assemblyComponents;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IComponentModel, int)> AssemblyComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_assemblyComponents == null)
|
||||||
|
{
|
||||||
|
_assemblyComponents = Components.ToDictionary(
|
||||||
|
AsmComp => AsmComp.ComponentId,
|
||||||
|
AsmComp => (AsmComp.Component as IComponentModel, AsmComp.Count)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _assemblyComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Assembly Create(ComputerShopDatabase Context, AssemblyBindingModel Model)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = Model.Id,
|
||||||
|
UserId = Model.UserId,
|
||||||
|
AssemblyName = Model.AssemblyName,
|
||||||
|
Cost = Model.Cost,
|
||||||
|
Category = Model.Category,
|
||||||
|
Components = Model.AssemblyComponents.Select(x => new AssemblyComponent
|
||||||
|
{
|
||||||
|
Component = Context.Components.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Update(), ViewModel, UpdateComponents()
|
||||||
|
}
|
||||||
|
}
|
22
ComputerShopDatabaseImplement/Models/AssemblyComponent.cs
Normal file
22
ComputerShopDatabaseImplement/Models/AssemblyComponent.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace ComputerShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class AssemblyComponent
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int AssemblyId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ComponentId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
public virtual Assembly Assembly { get; set; } = new();
|
||||||
|
|
||||||
|
public virtual Component Component { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
50
ComputerShopDatabaseImplement/Models/Component.cs
Normal file
50
ComputerShopDatabaseImplement/Models/Component.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace ComputerShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Component : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int UserId { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string ComponentName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Cost { get; private set; }
|
||||||
|
|
||||||
|
[ForeignKey("ComponentId")]
|
||||||
|
public virtual List<AssemblyComponent> AssemblyComponents { get; set; } = new();
|
||||||
|
|
||||||
|
public static Component Create(ComponentBindingModel Model)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = Model.Id,
|
||||||
|
UserId = Model.UserId,
|
||||||
|
ComponentName = Model.ComponentName,
|
||||||
|
Cost = Model.Cost,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ComponentBindingModel Model)
|
||||||
|
{
|
||||||
|
ComponentName = Model.ComponentName;
|
||||||
|
Cost = Model.Cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComponentViewModel ViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
UserId = UserId,
|
||||||
|
ComponentName = ComponentName,
|
||||||
|
Cost = Cost,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
66
ComputerShopDatabaseImplement/Models/Product.cs
Normal file
66
ComputerShopDatabaseImplement/Models/Product.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace ComputerShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Product : IProductModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int UserId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string ProductName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Cost { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Warranty { get; set; }
|
||||||
|
|
||||||
|
public int? ShipmentId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("ComponentId")]
|
||||||
|
public virtual List<ProductComponent> Components { get; set; } = new();
|
||||||
|
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _productComponents;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_productComponents == null)
|
||||||
|
{
|
||||||
|
_productComponents = Components.ToDictionary(
|
||||||
|
ProdComp => ProdComp.ComponentId,
|
||||||
|
ProdComp => (ProdComp.Component as IComponentModel, ProdComp.Count)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _productComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Product Create(ComputerShopDatabase Context, ProductBindingModel Model)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = Model.Id,
|
||||||
|
UserId = Model.UserId,
|
||||||
|
ProductName = Model.ProductName,
|
||||||
|
Cost = Model.Cost,
|
||||||
|
Warranty = Model.Warranty,
|
||||||
|
Components = Model.ProductComponents.Select(x => new ProductComponent
|
||||||
|
{
|
||||||
|
Component = Context.Components.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList(),
|
||||||
|
ShipmentId = Model.ShipmentId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
ComputerShopDatabaseImplement/Models/ProductComponent.cs
Normal file
22
ComputerShopDatabaseImplement/Models/ProductComponent.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace ComputerShopDatabaseImplement.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 Product Product { get; set; } = new();
|
||||||
|
|
||||||
|
public virtual Component Component { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user