trakker/Models/Client.cs

108 lines
3.8 KiB
C#

using System;
using System.ComponentModel.DataAnnotations;
namespace trakker.Models
{
/// <summary>
/// Represents a client record in the application.
/// Contains contact information, address fields, and audit timestamps.
/// Validation attributes decorate properties to enforce basic constraints.
/// </summary>
public class Client
{
/// <summary>
/// Primary identifier for the client. This maps to the database <c>client_id</c>.
/// Marked with <see cref="Key"/> to indicate the primary key.
/// </summary>
[Key]
public string ClientId { get; set; } = Guid.NewGuid().ToString();
/// <summary>
/// The client's full name. This field is required and has a maximum length of 200 characters.
/// </summary>
[Required]
[MaxLength(200)]
public string Name { get; set; } = string.Empty;
/// <summary>
/// Optional company name associated with the client. Maximum length 200 characters.
/// </summary>
[MaxLength(200)]
public string? Company { get; set; } = string.Empty;
/// <summary>
/// Optional email address for the client. Validated with <see cref="EmailAddressAttribute"/> and
/// constrained to 255 characters.
/// </summary>
[EmailAddress]
[MaxLength(255)]
public string? Email { get; set; } = string.Empty;
/// <summary>
/// Optional phone number for the client. Validated with <see cref="PhoneAttribute"/> and
/// constrained to 50 characters.
/// </summary>
[Phone]
[MaxLength(50)]
public string? Phone { get; set; } = string.Empty;
/// <summary>
/// Street address for the client. Optional and limited to 100 characters.
/// </summary>
[MaxLength(100)]
public string? AddressStreet { get; set; } = string.Empty;
/// <summary>
/// City portion of the client's address. Optional and limited to 100 characters.
/// </summary>
[MaxLength(100)]
public string? AddressCity { get; set; } = string.Empty;
/// <summary>
/// State portion of the client's address. Stored as a 2-character code (e.g., US state abbreviation).
/// </summary>
[MaxLength(2)]
public string? AddressState { get; set; } = string.Empty;
/// <summary>
/// Postal code portion of the client's address. Limited to 5 characters in this model.
/// </summary>
[MaxLength(5)]
public string? AddressPostal { get; set; } = string.Empty;
/// <summary>
/// Free-form notes about the client. Optional and limited to 2000 characters.
/// </summary>
[MaxLength(2000)]
public string? Notes { get; set; } = string.Empty;
/// <summary>
/// Indicates whether the client is active. Defaults to <c>true</c>.
/// </summary>
public string IsActive { get; set; } = "y";
/// <summary>
/// UTC timestamp for when the record was created. Defaults to <see cref="DateTime.UtcNow"/>.
/// </summary>
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
/// <summary>
/// UTC timestamp for when the record was last updated. Updated by application code
/// when changes are made.
/// </summary>
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
/// <summary>
/// Updates the <see cref="UpdatedAt"/> timestamp to the current UTC time. Call this
/// before persisting changes to ensure the audit timestamp is accurate.
/// </summary>
public int ProjectCount { get; set; } = 0;
public void UpdateTimestamp()
{
UpdatedAt = DateTime.UtcNow;
}
}
}