2023-09-06 22:02:39 +04:00
|
|
|
|
using BlogContracts.BindingModels;
|
|
|
|
|
using BlogContracts.ViewModels;
|
|
|
|
|
using BlogDataModels;
|
2023-09-06 21:16:28 +04:00
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|