PIbd-22-Ismailov_SUBD/BlogDataModels/BlogDatabaseImplement/Model/Comment.cs
2023-05-18 21:34:36 +04:00

55 lines
1.3 KiB
C#

using BlogContracts.BindingModel;
using BlogContracts.ViewModels;
using BlogDataModels.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlogDatabaseImplement.Model
{
public class Comment : IComment
{
[Required]
public string Text { get; set; } = string.Empty;
[Required]
public int NewsId { get; set; }
[Required]
public int Id { get; set; }
public virtual News News { get; set; }
public static Comment? Create(CommentBindingModel model)
{
if (model == null)
{
return null;
}
return new Comment()
{
Id = model.Id,
Text = model.Text,
NewsId = model.NewsId,
};
}
public void Update(CommentBindingModel model)
{
if (model == null)
{
return;
}
Text = model.Text;
NewsId = model.NewsId;
}
public CommentViewModel GetViewModel => new()
{
Id = Id,
Text = Text,
NewsId = NewsId
};
}
}