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.Runtime.ConstrainedExecution;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BlogDatabase.Models
|
|
|
|
|
{
|
|
|
|
|
public class Category : ICategoryModel
|
|
|
|
|
{
|
|
|
|
|
[Required]
|
|
|
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public int UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
[ForeignKey("TopicId")]
|
|
|
|
|
List<Topic> Topics { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
public static Category? Create(CategoryBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Category()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(CategoryBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Name = model.Name;
|
|
|
|
|
}
|
|
|
|
|
public CategoryViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Name = Name,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|