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 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 }; } }