+
This commit is contained in:
parent
1ba401c454
commit
55eade5399
@ -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", "{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}"
|
||||
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
|
||||
{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -10,6 +10,6 @@ namespace ComputerHardwareStoreContracts.BindingModels
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; } = null;
|
||||
public Dictionary<int, (IProductModel, int)> OrderProduct { get; set; } = new();
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
public DateTime DateCreate { get; set; }
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProduct { get; set; } = new();
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,6 @@ namespace ComputerHardwareStoreDataModels.Models
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProduct { get; }
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts { get; }
|
||||
}
|
||||
}
|
||||
|
@ -31,5 +31,6 @@ namespace ComputerHardwareStoreDatabaseImplement
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Product> Products { set; get; }
|
||||
public virtual DbSet<ProductComponent> ProductComponents { set; get; }
|
||||
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Enums;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
@ -18,9 +19,25 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; private set; }
|
||||
public virtual Product? Product { 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)
|
||||
@ -30,13 +47,18 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
ProductId = model.CannedId,
|
||||
Product = context.Products.First(x => x.Id == model.ProductId)
|
||||
Products = model.OrderProducts
|
||||
.Select(op => new OrderProduct()
|
||||
{
|
||||
OrderId = model.Id,
|
||||
ProductId = op.Key,
|
||||
Count = op.Value.Item2
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel model)
|
||||
@ -51,12 +73,10 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ProductId = ProductId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ProductName = Product.ProductName
|
||||
};
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user