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

60 lines
1.6 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;
2024-05-05 19:18:53 +04:00
using System.Runtime.ConstrainedExecution;
2024-05-03 11:28:27 +04:00
using System.Text;
using System.Threading.Tasks;
namespace CarShowroomDatabaseStorage.Entities
{
2024-05-05 19:18:53 +04:00
[Table("service")]
[Index(nameof(Name), IsUnique = true)]
public class Service : IService
2024-05-03 11:28:27 +04:00
{
2024-05-05 19:18:53 +04:00
[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")]
2024-05-13 14:36:30 +04:00
public int Price { get; private set; }
2024-05-05 19:18:53 +04:00
public virtual List<SaleService> SaleServices { get; set; } = new();
private Service() { }
private Service(IService service)
2024-05-03 11:28:27 +04:00
{
Id = service.Id;
Name = service.Name;
2024-05-13 14:36:30 +04:00
Price = service.Price;
2024-05-03 11:28:27 +04:00
}
2024-05-05 19:18:53 +04:00
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;
2024-05-13 14:36:30 +04:00
Price = service.Price;
2024-05-05 19:18:53 +04:00
}
2024-05-05 22:58:29 +04:00
public ServiceView GetView()
2024-05-05 19:18:53 +04:00
{
return new ServiceView(this);
}
2024-05-03 11:28:27 +04:00
}
}