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