Готова сущность Comment

This commit is contained in:
Николай 2023-04-01 15:02:51 +04:00
parent 33562b0143
commit a7cebe62b7
3 changed files with 37 additions and 5 deletions

View File

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

View File

@ -22,6 +22,8 @@ namespace HardwareShopDatabaseImplement.Models
public virtual User User { get; set; }
[ForeignKey("BuildId")]
public virtual List<Comment>? Comments { get; set; }
[ForeignKey("BuildId")]
public virtual List<BuildComponent>? Components { get; set; }

View File

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