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

49 lines
1.2 KiB
C#
Raw Normal View History

2024-04-30 18:59:45 +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 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,
};
}
}