ComputerHardwareStore_YouAr.../ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Comment.cs

50 lines
1.3 KiB
C#
Raw Permalink Normal View History

2024-05-01 18:01:42 +04:00
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 virtual Build Build { get; set; } = new();
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,
};
}
}