51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using HardwareShopContracts.BindingModels;
|
|
using HardwareShopContracts.ViewModels;
|
|
using HardwareShopDataModels.Models;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace HardwareShopDatabaseImplement.Models
|
|
{
|
|
public class Comment : ICommentModel
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
[Required]
|
|
public string Text { 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
|
|
};
|
|
}
|
|
}
|