69 lines
2.1 KiB
C#
69 lines
2.1 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 Author : IAuthorModel
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public string AuthorSurname { get; set; } = string.Empty;
|
|
[Required]
|
|
public string AuthorName { get; set; } = string.Empty;
|
|
[Required]
|
|
public string AuthorPatronymic { get; set; } = string.Empty;
|
|
|
|
[ForeignKey("AuthorId")]
|
|
public virtual List<BookAuthor> BookAuthors { get; set; } = new();
|
|
public static Author? Create(AuthorBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Author()
|
|
{
|
|
Id = model.Id,
|
|
AuthorSurname = model.AuthorSurname,
|
|
AuthorName = model.AuthorName,
|
|
AuthorPatronymic = model.AuthorPatronymic
|
|
};
|
|
}
|
|
public static Author Create(AuthorViewModel model)
|
|
{
|
|
return new Author
|
|
{
|
|
Id = model.Id,
|
|
AuthorSurname = model.AuthorSurname,
|
|
AuthorName = model.AuthorName,
|
|
AuthorPatronymic = model.AuthorPatronymic
|
|
};
|
|
}
|
|
public void Update(AuthorBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
AuthorSurname = model.AuthorSurname;
|
|
AuthorName = model.AuthorName;
|
|
AuthorPatronymic = model.AuthorPatronymic;
|
|
}
|
|
public AuthorViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
AuthorSurname = AuthorSurname,
|
|
AuthorName = AuthorName,
|
|
AuthorPatronymic = AuthorPatronymic
|
|
};
|
|
}
|
|
}
|