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

60 lines
1.6 KiB
C#

using CarShowroomContracts.AbstractModels;
using CarShowroomDataModels.Views;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
namespace CarShowroomDatabaseStorage.Entities
{
[Table("service")]
[Index(nameof(Name), IsUnique = true)]
public class Service : IService
{
[Column("service_id")]
public int Id { get; private set; }
[Required]
[Column("service_name")]
[MaxLength(50)]
public string Name { get; private set; } = string.Empty;
[Required]
[Column("service_cost")]
public int Price { get; private set; }
public virtual List<SaleService> SaleServices { get; set; } = new();
private Service() { }
private Service(IService service)
{
Id = service.Id;
Name = service.Name;
Price = service.Price;
}
public static Service? Create(IService service)
{
if (service == null)
return null;
return new Service(service);
}
public void Update(IService service)
{
if (service == null)
return;
Name = service.Name;
Price = service.Price;
}
public ServiceView GetView()
{
return new ServiceView(this);
}
}
}