From a7cebe62b798531e4461dd1c916dcd541e6e2623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sat, 1 Apr 2023 15:02:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=20=D1=81?= =?UTF-8?q?=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20Comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/CommentBindingModel.cs | 2 - .../Models/Build.cs | 2 + .../Models/Comment.cs | 38 +++++++++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs index 69371b1..7f6175d 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs @@ -10,8 +10,6 @@ namespace HardwareShopContracts.BindingModels public string Text { get; set; } = string.Empty; - public string BuildName { get; set; } = string.Empty; - public int BuildID { get; set; } } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Build.cs index 3132f6d..1f333b8 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Build.cs @@ -22,6 +22,8 @@ namespace HardwareShopDatabaseImplement.Models public virtual User User { get; set; } + [ForeignKey("BuildId")] + public virtual List? Comments { get; set; } [ForeignKey("BuildId")] public virtual List? Components { get; set; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Comment.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Comment.cs index 85259fd..d041dc3 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Comment.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Comment.cs @@ -1,5 +1,8 @@ -using HardwareShopDataModels.Models; +using HardwareShopContracts.BindingModels; +using HardwareShopContracts.ViewModels; +using HardwareShopDataModels.Models; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; namespace HardwareShopDatabaseImplement.Models { @@ -7,12 +10,41 @@ namespace HardwareShopDatabaseImplement.Models { public int Id { get; set; } + [Required] public string Text { get; set; } = string.Empty; - public string BuildName { get; set; } = string.Empty; - + [Required] public int BuildID { get; set; } public virtual Build Build { get; set; } + + public static Comment? Create(CommentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Comment() + { + Id = model.Id, + Text = model.Text, + BuildID = model.BuildID + }; + } + public void Update(CommentBindingModel? model) + { + if (model == null) + { + return; + } + Text = model.Text; + } + public CommentViewModel GetViewModel => new() + { + Id = Id, + Text = Text, + BuildID = BuildID, + BuildName = Build.BuildName + }; } }