PIbd-23_Sergunov_M.A._SUBD/BookShop/BookShopDataBaseImplement/Models/Genre.cs

52 lines
1.3 KiB
C#
Raw Normal View History

2023-05-12 12:35:01 +04:00
using BookShopContracts.BindingModels;
using BookShopContracts.ViewModels;
using BookShopDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace BookShopDataBaseImplement.Models
{
public class Genre : IGenreModel
{
public int Id { get; private set; }
[Required]
public string GenreName { get; set; } = string.Empty;
[ForeignKey("GenreId")]
public virtual List<Book> Books { get; set; } = new();
public static Genre? Create(GenreBindingModel model)
{
if (model == null)
{
return null;
}
return new Genre()
{
Id = model.Id,
GenreName = model.GenreName
};
}
public static Genre Create(GenreViewModel model)
{
return new Genre
{
Id = model.Id,
GenreName = model.GenreName
};
}
public void Update(GenreBindingModel model)
{
if (model == null)
{
return;
}
GenreName = model.GenreName;
}
public GenreViewModel GetViewModel => new()
{
Id = Id,
GenreName = GenreName
};
}
}