2024-05-03 11:28:27 +04:00
|
|
|
|
using CarShowroomContracts.AbstractModels;
|
2024-05-05 22:02:53 +04:00
|
|
|
|
using CarShowroomDataModels.Views;
|
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("car")]
|
2024-05-03 11:28:27 +04:00
|
|
|
|
public class Car : ICar
|
|
|
|
|
{
|
2024-05-05 19:18:53 +04:00
|
|
|
|
[Column("car_id")]
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
[Column("car_color")]
|
|
|
|
|
[MaxLength(50)]
|
|
|
|
|
public string Color { get; private set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
[Column("car_releasedate")]
|
|
|
|
|
public DateTime ReleaseDate { get; private set; }
|
|
|
|
|
[Required]
|
2024-05-12 21:44:49 +04:00
|
|
|
|
[Column("car_issaled")]
|
|
|
|
|
public bool IsSaled { get; private set; }
|
|
|
|
|
[Required]
|
2024-05-05 19:18:53 +04:00
|
|
|
|
[Column("car_model_id")]
|
|
|
|
|
public int ModelId { get; private set; }
|
|
|
|
|
public virtual Model? Model { get; set; }
|
|
|
|
|
public virtual List<SaleCar> SaleCars { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
private Car(){}
|
|
|
|
|
|
|
|
|
|
private Car(ICar car)
|
2024-05-03 11:28:27 +04:00
|
|
|
|
{
|
|
|
|
|
Id = car.Id;
|
|
|
|
|
Color = car.Color;
|
2024-05-05 19:18:53 +04:00
|
|
|
|
ReleaseDate = DateTime.Now;
|
2024-05-03 11:28:27 +04:00
|
|
|
|
ModelId = car.ModelId;
|
2024-05-12 21:44:49 +04:00
|
|
|
|
IsSaled = car.IsSaled;
|
2024-05-03 11:28:27 +04:00
|
|
|
|
}
|
2024-05-05 19:18:53 +04:00
|
|
|
|
|
|
|
|
|
public static Car? Create(ICar car)
|
|
|
|
|
{
|
|
|
|
|
if (car == null)
|
|
|
|
|
return null;
|
|
|
|
|
return new Car(car);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(ICar car)
|
|
|
|
|
{
|
|
|
|
|
if (car == null)
|
|
|
|
|
return;
|
|
|
|
|
Color = car.Color;
|
|
|
|
|
ReleaseDate = car.ReleaseDate;
|
|
|
|
|
ModelId = car.ModelId;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 22:58:29 +04:00
|
|
|
|
public CarView GetView()
|
2024-05-05 19:18:53 +04:00
|
|
|
|
{
|
|
|
|
|
CarView car = new CarView(this);
|
2024-05-13 14:36:30 +04:00
|
|
|
|
car.Price = Model?.Price ?? 0;
|
2024-05-05 19:18:53 +04:00
|
|
|
|
car.ModelName = Model?.Name ?? string.Empty;
|
|
|
|
|
car.MakeName = Model?.Make?.Name ?? string.Empty;
|
|
|
|
|
return car;
|
|
|
|
|
}
|
2024-05-03 11:28:27 +04:00
|
|
|
|
}
|
|
|
|
|
}
|