87 lines
2.3 KiB
C#
87 lines
2.3 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace Lagerbestand.Models;
|
|
|
|
/// <summary>
|
|
/// Represents a customer who stores tires at the shop.
|
|
/// A customer can have multiple vehicles.
|
|
/// </summary>
|
|
public class Customer
|
|
{
|
|
[Key]
|
|
public Guid Id { get; set; } = Guid.NewGuid();
|
|
|
|
[MaxLength(100)]
|
|
public string? FirstName { get; set; }
|
|
|
|
[Required]
|
|
[MaxLength(100)]
|
|
public string LastName { get; set; } = string.Empty;
|
|
|
|
[MaxLength(200)]
|
|
public string? Company { get; set; }
|
|
|
|
[MaxLength(20)]
|
|
public string? Phone { get; set; }
|
|
|
|
[MaxLength(100)]
|
|
public string? Email { get; set; }
|
|
|
|
[MaxLength(500)]
|
|
public string? Notes { get; set; }
|
|
|
|
/// <summary>
|
|
/// Customer number for easy identification (e.g., K-0001)
|
|
/// </summary>
|
|
[MaxLength(20)]
|
|
public string CustomerNumber { get; set; } = string.Empty;
|
|
|
|
public bool IsActive { get; set; } = true;
|
|
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
|
|
public DateTime? UpdatedAt { get; set; }
|
|
|
|
/// <summary>
|
|
/// Navigation property for customer's vehicles
|
|
/// </summary>
|
|
public ICollection<Vehicle> Vehicles { get; set; } = new List<Vehicle>();
|
|
|
|
/// <summary>
|
|
/// Navigation property for customer's stored tire stacks
|
|
/// </summary>
|
|
public ICollection<TireStack> TireStacks { get; set; } = new List<TireStack>();
|
|
|
|
/// <summary>
|
|
/// Full name of the customer
|
|
/// </summary>
|
|
[NotMapped]
|
|
public string FullName => $"{FirstName} {LastName}".Trim();
|
|
|
|
/// <summary>
|
|
/// Display name including company if available
|
|
/// </summary>
|
|
[NotMapped]
|
|
public string DisplayName => string.IsNullOrEmpty(Company)
|
|
? FullName
|
|
: $"{FullName} ({Company})";
|
|
|
|
/// <summary>
|
|
/// Gets the primary vehicle or the first vehicle if no primary is set
|
|
/// </summary>
|
|
[NotMapped]
|
|
public Vehicle? PrimaryVehicle => Vehicles
|
|
.Where(v => v.IsActive)
|
|
.OrderByDescending(v => v.IsPrimary)
|
|
.ThenBy(v => v.CreatedAt)
|
|
.FirstOrDefault();
|
|
|
|
/// <summary>
|
|
/// Gets all active vehicles for this customer
|
|
/// </summary>
|
|
[NotMapped]
|
|
public IEnumerable<Vehicle> ActiveVehicles => Vehicles.Where(v => v.IsActive);
|
|
|
|
}
|