67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
using CarShowroomContracts.AbstractModels;
|
|
using CarShowroomContracts.Views;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CarShowroomDatabaseStorage.Entities
|
|
{
|
|
[Table("car")]
|
|
public class Car : ICar
|
|
{
|
|
[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]
|
|
[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)
|
|
{
|
|
Id = car.Id;
|
|
Color = car.Color;
|
|
ReleaseDate = DateTime.Now;
|
|
ModelId = car.ModelId;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public CarView GetCarView()
|
|
{
|
|
CarView car = new CarView(this);
|
|
car.ModelPrice = Model?.Price ?? 0;
|
|
car.ModelName = Model?.Name ?? string.Empty;
|
|
car.MakeName = Model?.Make?.Name ?? string.Empty;
|
|
return car;
|
|
}
|
|
}
|
|
}
|