57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using BookShopContracts.BindingModels;
|
|
using BookShopContracts.ViewModels;
|
|
using BookShopDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
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
|
|
};
|
|
}
|
|
}
|