PIbd-22-Ismailov_SUBD/BlogDataModels/BlogDatabaseImplement/Model/Topic.cs
2023-09-06 22:02:39 +04:00

63 lines
1.5 KiB
C#

using BlogContracts.BindingModels;
using BlogContracts.ViewModels;
using BlogDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace BlogDatabase.Models
{
public class Topic : ITopicModel
{
[Required]
public string Name { get; set; } = string.Empty;
public int Id { get; private set; }
[Required]
public int UserId { get; set; }
[Required]
public int CategoryId { get; set; }
[ForeignKey("MessageId")]
List<Message> Messages { get; set; } = new();
public virtual Category? Category { get; set; }
public static Topic? Create(TopicBindingModel model)
{
if (model == null)
{
return null;
}
return new Topic()
{
Id = model.Id,
Name = model.Name,
CategoryId = model.CategoryId,
};
}
public void Update(TopicBindingModel model)
{
if (model == null)
{
return;
}
model.Id = Id;
model.Name = Name;
}
public TopicViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
CategoryId = CategoryId,
};
}
}