cyjdf c,jhrf
This commit is contained in:
parent
733c40a85a
commit
cc389d7922
@ -7,7 +7,7 @@ namespace ComputerHardwareStoreContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public int VendorId { get; set; }
|
||||
public IVendorModel Vendor { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||
public List<ICommentModel> Comments { get; set; } = new();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Стоимость")]
|
||||
public double Price { get; set; }
|
||||
public int VendorId { get; set; }
|
||||
public IVendorModel Vendor { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||
public List<ICommentModel> Comments { get; set; } = new();
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
{
|
||||
string Name { get; }
|
||||
double Price { get; }
|
||||
int VendorId { get; }
|
||||
IVendorModel Vendor { get; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; }
|
||||
public List<ICommentModel> Comments { get; }
|
||||
}
|
||||
|
@ -36,5 +36,6 @@ namespace ComputerHardwareStoreDatabaseImplement
|
||||
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
|
||||
public virtual DbSet<BuildComponent> BuildComponents { set; get; }
|
||||
public virtual DbSet<Comment> Comments { set; get; }
|
||||
public virtual DbSet<Vendor> Vendors { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -15,9 +16,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
[Required]
|
||||
public int VendorId { get; set; }
|
||||
public virtual Vendor Vendor { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents
|
||||
@ -36,10 +35,14 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
[ForeignKey("BuildId")]
|
||||
public virtual List<BuildComponent> Components { get; set; } = new();
|
||||
[ForeignKey("BuildId")]
|
||||
|
||||
public virtual List<Comment> Comments { get; set; } = new();
|
||||
[NotMapped]
|
||||
List<ICommentModel> IBuildModel.Comments => Comments.Select(c => c as ICommentModel).ToList();
|
||||
|
||||
public virtual Vendor Vendor { get; private set; } = new();
|
||||
IVendorModel IBuildModel.Vendor => Vendor as IVendorModel;
|
||||
|
||||
public static Build? Create(ComputerHardwareStoreDBContext context, BuildBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -51,7 +54,16 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price,
|
||||
VendorId = model.VendorId,
|
||||
Vendor = context.Vendors.First(v => v.Id == model.Vendor.Id),
|
||||
Components = context.Components
|
||||
.Where(c => model.BuildComponents.ContainsKey(c.Id))
|
||||
.Select(c => new BuildComponent()
|
||||
{
|
||||
BuildId = model.Id,
|
||||
ComponentId = c.Id,
|
||||
Component = c,
|
||||
Count = model.BuildComponents[c.Id].Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
@ -60,7 +72,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Price = Price,
|
||||
VendorId = VendorId,
|
||||
Vendor = Vendor,
|
||||
Comments = Comments.Select(c => c as ICommentModel).ToList(),
|
||||
BuildComponents = BuildComponents
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user