63 lines
1.5 KiB
C#
63 lines
1.5 KiB
C#
using ForumContracts.BindingModels;
|
|
using ForumContracts.ViewModels;
|
|
using ForumDataModels;
|
|
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,
|
|
};
|
|
}
|
|
}
|