Сборка и комменты
This commit is contained in:
parent
4733811487
commit
7f429638b5
@ -9,5 +9,6 @@ namespace ComputerHardwareStoreContracts.BindingModels
|
||||
public double Price { get; set; }
|
||||
public int VendorId { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||
public List<ICommentModel> Comments { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,11 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название сборки")]
|
||||
public string Name { get; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Стоимость")]
|
||||
public double Price { get; }
|
||||
public int VendorId { get; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; } = new();
|
||||
public double Price { get; set; }
|
||||
public int VendorId { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||
public List<ICommentModel> Comments { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,5 @@ namespace ComputerHardwareStoreContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public int BuildId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -6,5 +6,6 @@
|
||||
double Price { get; }
|
||||
int VendorId { get; }
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; }
|
||||
public List<ICommentModel> Comments { get; }
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,5 @@
|
||||
{
|
||||
DateTime Date { get; }
|
||||
string Text { get; }
|
||||
int BuildId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,11 @@ namespace ComputerHardwareStoreDatabaseImplement
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Product> Products { set; get; }
|
||||
public virtual DbSet<ProductComponent> ProductComponents { set; get; }
|
||||
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
|
||||
|
||||
public virtual DbSet<StoreKeeper> StoreKeepers { set; get; }
|
||||
public virtual DbSet<Build> Builds { set; get; }
|
||||
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
|
||||
public virtual DbSet<BuildComponent> BuildComponents { set; get; }
|
||||
public virtual DbSet<Comment> Comments { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,68 @@
|
||||
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Build : IBuildModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
[Required]
|
||||
public int VendorId { get; private set; }
|
||||
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
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_buildComponents == null)
|
||||
{
|
||||
_buildComponents = Components
|
||||
.ToDictionary(bc => bc.ComponentId, bc =>
|
||||
(bc.Component as IComponentModel, bc.Count));
|
||||
}
|
||||
return _buildComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("BuildId")]
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents => throw new NotImplementedException();
|
||||
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 static Build? Create(ComputerHardwareStoreDBContext context, BuildBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price,
|
||||
VendorId = model.VendorId,
|
||||
};
|
||||
}
|
||||
|
||||
public BuildViewModel GetViewModel() => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Price = Price,
|
||||
VendorId = VendorId,
|
||||
Comments = Comments.Select(c => c as ICommentModel).ToList(),
|
||||
BuildComponents = BuildComponents
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class BuildComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int BuildId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Build Build { get; set; } = new();
|
||||
public virtual Component Component { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using ComputerHardwareStoreDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Comment : ICommentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public DateTime Date { get; set; }
|
||||
[Required]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int BuildId { get; set; }
|
||||
public static Comment? Create(CommentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
Date = model.Date,
|
||||
Text = model.Text,
|
||||
BuildId = model.BuildId,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CommentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Text = model.Text;
|
||||
}
|
||||
|
||||
public CommentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Date = Date,
|
||||
Text = Text,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user