Compare commits
5 Commits
41fa66267d
...
d49014d810
Author | SHA1 | Date | |
---|---|---|---|
|
d49014d810 | ||
|
55eade5399 | ||
|
1ba401c454 | ||
|
493886c45a | ||
|
210d90bb69 |
@ -9,7 +9,7 @@ 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
|
||||
@ -35,10 +35,6 @@ 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
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -34,5 +34,6 @@ namespace ComputerHardwareStoreDatabaseImplement
|
||||
|
||||
public virtual DbSet<StoreKeeper> StoreKeepers { set; get; }
|
||||
public virtual DbSet<Build> Builds { 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)
|
||||
@ -34,7 +51,14 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
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)
|
||||
@ -57,3 +81,4 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
|
||||
public Dictionary<int, (IProductModel, int)> OrderProduct => throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -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