+
This commit is contained in:
parent
070473b0d6
commit
95b2759a12
@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDataMo
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreContracts", "ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj", "{5F394E21-2597-432B-AE73-BBAFD8D9F50E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreContracts", "ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj", "{5F394E21-2597-432B-AE73-BBAFD8D9F50E}"
|
||||||
EndProject
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -10,6 +10,6 @@ namespace ComputerHardwareStoreContracts.BindingModels
|
|||||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
public DateTime? DateImplement { get; set; } = null;
|
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; }
|
public DateTime DateCreate { get; set; }
|
||||||
[DisplayName("Дата выполнения")]
|
[DisplayName("Дата выполнения")]
|
||||||
public DateTime? DateImplement { get; set; }
|
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; }
|
OrderStatus Status { get; }
|
||||||
DateTime DateCreate { get; }
|
DateTime DateCreate { get; }
|
||||||
DateTime? DateImplement { 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<Component> Components { set; get; }
|
||||||
public virtual DbSet<Product> Products { set; get; }
|
public virtual DbSet<Product> Products { set; get; }
|
||||||
public virtual DbSet<ProductComponent> ProductComponents { 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.Enums;
|
||||||
using ComputerHardwareStoreDataModels.Models;
|
using ComputerHardwareStoreDataModels.Models;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
@ -18,9 +19,25 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
[Required]
|
|
||||||
public int ProductId { get; private set; }
|
private Dictionary<int, (IProductModel, int)>? _orderProducts = null;
|
||||||
public virtual Product? Product { get; set; }
|
[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)
|
public static Order? Create(ComputerHardwareStoreDBContext context, OrderBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -30,13 +47,18 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
|||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
Count = model.Count,
|
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement,
|
DateImplement = model.DateImplement,
|
||||||
ProductId = model.CannedId,
|
Products = model.OrderProducts
|
||||||
Product = context.Products.First(x => x.Id == model.ProductId)
|
.Select(op => new OrderProduct()
|
||||||
|
{
|
||||||
|
OrderId = model.Id,
|
||||||
|
ProductId = op.Key,
|
||||||
|
Count = op.Value.Item2
|
||||||
|
})
|
||||||
|
.ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(OrderBindingModel model)
|
public void Update(OrderBindingModel model)
|
||||||
@ -51,12 +73,10 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
|||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
ProductId = ProductId,
|
|
||||||
Count = Count,
|
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
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