Compare commits

...

5 Commits

Author SHA1 Message Date
bekodeg
d49014d810 решаем конфликты 2024-04-30 17:07:55 +04:00
bekodeg
55eade5399 + 2024-04-30 17:05:42 +04:00
bekodeg
1ba401c454 Merge branch 'BACKDEV-408' of https://git.is.ulstu.ru/bekodeg/ComputerHardwareStore_YouAreProgrammer into BACKDEV-408 2024-04-29 21:02:45 +04:00
bekodeg
493886c45a фиг знает 2024-04-29 21:02:41 +04:00
bekodeg
210d90bb69 + 2024-04-29 21:02:20 +04:00
7 changed files with 51 additions and 12 deletions

View File

@ -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

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}