SUBD_PIbd-23_ZakharovRA/CarShowroom/CarShowroomDatabaseStorage/Entities/Make.cs

54 lines
1.3 KiB
C#
Raw Normal View History

2024-05-03 11:28:27 +04:00
using CarShowroomContracts.AbstractModels;
2024-05-05 22:02:53 +04:00
using CarShowroomDataModels.Views;
2024-05-05 19:18:53 +04:00
using Microsoft.EntityFrameworkCore;
2024-05-03 11:28:27 +04:00
using System;
using System.Collections.Generic;
2024-05-05 19:18:53 +04:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2024-05-03 11:28:27 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarShowroomDatabaseStorage.Entities
{
2024-05-05 19:18:53 +04:00
[Table("make")]
[Index(nameof(Name), IsUnique = true)]
2024-05-03 11:28:27 +04:00
public class Make : IMake
{
2024-05-05 19:18:53 +04:00
[Column("make_id")]
public int Id { get; private set; }
[Required]
[Column("make_name")]
[MaxLength(50)]
public string Name { get; private set; } = string.Empty;
public virtual List<Model> Models { get; set; } = new();
private Make() { }
private Make(IMake make)
2024-05-03 11:28:27 +04:00
{
Id = make.Id;
Name = make.Name;
}
2024-05-05 19:18:53 +04:00
public static Make? Create(IMake make)
{
if (make == null)
return null;
return new Make(make);
}
public void Update(IMake make)
{
if (make == null)
return;
Name = make.Name;
}
public MakeView GetView()
{
return new MakeView(this);
}
2024-05-03 11:28:27 +04:00
}
}