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

57 lines
1.4 KiB
C#
Raw Normal View History

2023-05-12 12:35:01 +04:00
using BookShopContracts.BindingModels;
using BookShopContracts.ViewModels;
using BookShopDataModels.Models;
2023-05-13 14:30:05 +04:00
using System;
using System.Collections.Generic;
2023-05-12 12:35:01 +04:00
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
2023-05-13 14:30:05 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-05-12 12:35:01 +04:00
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
};
}
}